@@ -22,7 +22,7 @@ use once_cell::sync::Lazy;
2222use regex:: Regex ;
2323use serde:: { Deserialize , Deserializer } ;
2424use serde_json:: { Map , Value } ;
25- use tracing:: { error, warn } ;
25+ use tracing:: error;
2626
2727/// Predefined JSON with known textual logging formats
2828const FORMATS_JSON : & str = include_str ! ( "../../../resources/formats.json" ) ;
@@ -32,8 +32,12 @@ pub static KNOWN_SCHEMA_LIST: Lazy<EventProcessor> =
3232 Lazy :: new ( || EventProcessor :: new ( FORMATS_JSON ) ) ;
3333
3434#[ derive( Debug , thiserror:: Error ) ]
35- #[ error( "Event is not in the expected text/JSON format for {0}" ) ]
36- pub struct Unacceptable ( String ) ;
35+ pub enum Error {
36+ #[ error( "Event is not in the expected text/JSON format for {0}" ) ]
37+ Unacceptable ( String ) ,
38+ #[ error( "Unknown log format: {0}" ) ]
39+ Unknown ( String ) ,
40+ }
3741
3842/// Deserializes a string pattern into a compiled Regex
3943/// NOTE: we only warn if the pattern doesn't compile
@@ -178,10 +182,9 @@ impl EventProcessor {
178182 json : & mut Value ,
179183 log_source : & str ,
180184 extract_log : Option < & str > ,
181- ) -> Result < HashSet < String > , Unacceptable > {
185+ ) -> Result < HashSet < String > , Error > {
182186 let Some ( schema) = self . schema_definitions . get ( log_source) else {
183- warn ! ( "Unknown log format: {log_source}" ) ;
184- return Ok ( HashSet :: new ( ) ) ;
187+ return Err ( Error :: Unknown ( log_source. to_owned ( ) ) ) ;
185188 } ;
186189
187190 let mut fields = HashSet :: new ( ) ;
@@ -194,15 +197,15 @@ impl EventProcessor {
194197 if let Some ( known_fields) = schema. check_or_extract ( event, extract_log) {
195198 fields. extend ( known_fields) ;
196199 } else {
197- return Err ( Unacceptable ( log_source. to_owned ( ) ) ) ;
200+ return Err ( Error :: Unacceptable ( log_source. to_owned ( ) ) ) ;
198201 }
199202 }
200203 }
201204 Value :: Object ( event) => {
202205 if let Some ( known_fields) = schema. check_or_extract ( event, extract_log) {
203206 return Ok ( known_fields) ;
204207 } else {
205- return Err ( Unacceptable ( log_source. to_owned ( ) ) ) ;
208+ return Err ( Error :: Unacceptable ( log_source. to_owned ( ) ) ) ;
206209 }
207210 }
208211 _ => unreachable ! ( "We don't accept events of the form: {json}" ) ,
0 commit comments