1+ use serde:: Deserialize ;
12use {
23 crate :: lazer_publisher:: LazerPublisher ,
34 anyhow:: Context ,
@@ -14,38 +15,61 @@ mod publisher_handle;
1415mod relayer_session;
1516mod websocket_utils;
1617
17- #[ derive( Parser ) ]
18+ #[ derive( Parser , Deserialize ) ]
1819#[ command( version) ]
1920struct Cli {
2021 #[ clap( short, long, default_value = "config/config.toml" ) ]
2122 config : String ,
23+ #[ clap( short, long, default_value = "json" ) ]
24+ log_format : LogFormat ,
25+ }
26+
27+ #[ derive( clap:: ValueEnum , Clone , Deserialize , Default ) ]
28+ enum LogFormat {
29+ #[ default]
30+ Json ,
31+ Compact ,
32+ Pretty ,
2233}
2334
2435#[ tokio:: main]
2536async fn main ( ) -> anyhow:: Result < ( ) > {
37+ let args = Cli :: parse ( ) ;
38+ init_tracing_subscriber ( args. log_format ) ;
39+
40+ let config =
41+ config:: load_config ( args. config . to_string ( ) ) . context ( "Failed to read config file" ) ?;
42+ info ! ( ?config, "starting lazer-agent" ) ;
43+
44+ let lazer_publisher = LazerPublisher :: new ( & config) . await ;
45+ http_server:: run ( config, lazer_publisher) . await ?;
46+
47+ Ok ( ( ) )
48+ }
49+
50+ fn init_tracing_subscriber ( log_format : LogFormat ) {
2651 #[ allow(
2752 clippy:: expect_used,
2853 reason = "application can fail on invalid RUST_LOG"
2954 ) ]
30- tracing_subscriber:: fmt ( )
55+ let subscriber = tracing_subscriber:: fmt ( )
3156 . with_env_filter (
3257 EnvFilter :: builder ( )
3358 . with_default_directive ( LevelFilter :: INFO . into ( ) )
3459 . from_env ( )
3560 . expect ( "invalid RUST_LOG env var" ) ,
3661 )
37- . with_span_events ( FmtSpan :: NONE )
38- . json ( )
39- . with_span_list ( false )
40- . init ( ) ;
62+ . with_span_events ( FmtSpan :: NONE ) ;
4163
42- let args = Cli :: parse ( ) ;
43- let config =
44- config:: load_config ( args. config . to_string ( ) ) . context ( "Failed to read config file" ) ?;
45- info ! ( ?config, "starting lazer-agent" ) ;
46-
47- let lazer_publisher = LazerPublisher :: new ( & config) . await ;
48- http_server:: run ( config, lazer_publisher) . await ?;
49-
50- Ok ( ( ) )
64+ match log_format {
65+ LogFormat :: Json => {
66+ subscriber. json ( ) . with_span_list ( false ) . init ( ) ;
67+ }
68+ LogFormat :: Compact => {
69+ subscriber. compact ( ) . init ( ) ;
70+ }
71+ LogFormat :: Pretty => {
72+ subscriber. pretty ( ) . init ( ) ;
73+ }
74+ }
5175}
0 commit comments