14
14
#![ feature( formatting_options) ]
15
15
16
16
// TODO:ehedeman Remove or replace with better config once telemetry perf issues are solved
17
- /// Environment variable to disable the glog logging layer.
18
- /// Set to "1" to disable glog logging output.
19
- pub const DISABLE_GLOG_TRACING : & str = "DISABLE_GLOG_TRACING" ;
20
-
21
17
/// Environment variable to disable the OpenTelemetry logging layer.
22
18
/// Set to "1" to disable OpenTelemetry tracing.
23
19
pub const DISABLE_OTEL_TRACING : & str = "DISABLE_OTEL_TRACING" ;
@@ -83,23 +79,18 @@ impl TelemetryClock for DefaultTelemetryClock {
83
79
84
80
// Need to keep this around so that the tracing subscriber doesn't drop the writer.
85
81
lazy_static ! {
86
- static ref WRITER_GUARD : Arc <( NonBlocking , WorkerGuard ) > = {
87
- let writer: Box <dyn Write + Send > = match env:: Env :: current( ) {
88
- env:: Env :: Local | env:: Env :: Test | env:: Env :: MastEmulator => {
82
+ static ref FILE_WRITER_GUARD : Arc <( NonBlocking , WorkerGuard ) > = {
83
+ let writer: Box <dyn Write + Send > = match RollingFileAppender :: builder( )
84
+ . rotation( Rotation :: DAILY )
85
+ . filename_prefix( "dedicated_log_monarch" )
86
+ . filename_suffix( "log" )
87
+ . build( "/logs/" )
88
+ {
89
+ Ok ( file) => Box :: new( file) ,
90
+ Err ( e) => {
91
+ tracing:: warn!( "unable to create custom log file: {}" , e) ;
89
92
Box :: new( std:: io:: stderr( ) )
90
93
}
91
- env:: Env :: Mast => match RollingFileAppender :: builder( )
92
- . rotation( Rotation :: DAILY )
93
- . filename_prefix( "dedicated_log_monarch" )
94
- . filename_suffix( "log" )
95
- . build( "/logs/" )
96
- {
97
- Ok ( file) => Box :: new( file) ,
98
- Err ( e) => {
99
- tracing:: warn!( "unable to create custom log file: {}" , e) ;
100
- Box :: new( std:: io:: stderr( ) )
101
- }
102
- } ,
103
94
} ;
104
95
return Arc :: new(
105
96
tracing_appender:: non_blocking:: NonBlockingBuilder :: default ( )
@@ -425,24 +416,46 @@ macro_rules! declare_static_histogram {
425
416
/// to get this behavior.
426
417
pub fn initialize_logging ( clock : impl TelemetryClock + Send + ' static ) {
427
418
swap_telemetry_clock ( clock) ;
428
- let glog_level = match env:: Env :: current ( ) {
419
+ let file_log_level = match env:: Env :: current ( ) {
429
420
env:: Env :: Local => "info" ,
430
421
env:: Env :: MastEmulator => "info" ,
431
422
env:: Env :: Mast => "info" ,
432
423
env:: Env :: Test => "debug" ,
433
424
} ;
425
+ let file_writer: & NonBlocking = & FILE_WRITER_GUARD . 0 ;
426
+ let file_layer = fmt:: Layer :: default ( )
427
+ . with_writer ( file_writer. clone ( ) )
428
+ . event_format ( Glog :: default ( ) . with_timer ( LocalTime :: default ( ) ) )
429
+ . fmt_fields ( GlogFields :: default ( ) . compact ( ) )
430
+ . with_ansi ( false )
431
+ . with_filter (
432
+ Targets :: new ( )
433
+ . with_default ( LevelFilter :: from_level (
434
+ tracing:: Level :: from_str (
435
+ & std:: env:: var ( "MONARCH_FILE_LOG" ) . unwrap_or ( file_log_level. to_string ( ) ) ,
436
+ )
437
+ . expect ( "Invalid log level" ) ,
438
+ ) )
439
+ . with_target ( "opentelemetry" , LevelFilter :: OFF ) , // otel has some log span under debug that we don't care about
440
+ ) ;
434
441
435
- let writer: & NonBlocking = & WRITER_GUARD . 0 ;
436
- let glog = fmt:: Layer :: default ( )
437
- . with_writer ( writer. clone ( ) )
442
+ let stderr_log_level = match env:: Env :: current ( ) {
443
+ env:: Env :: Local => "error" ,
444
+ env:: Env :: MastEmulator => "info" ,
445
+ env:: Env :: Mast => "error" ,
446
+ env:: Env :: Test => "debug" ,
447
+ } ;
448
+ let stderr_layer = fmt:: Layer :: default ( )
449
+ . with_writer ( std:: io:: stderr)
438
450
. event_format ( Glog :: default ( ) . with_timer ( LocalTime :: default ( ) ) )
439
451
. fmt_fields ( GlogFields :: default ( ) . compact ( ) )
440
452
. with_ansi ( std:: io:: stderr ( ) . is_terminal ( ) )
441
453
. with_filter (
442
454
Targets :: new ( )
443
455
. with_default ( LevelFilter :: from_level (
444
456
tracing:: Level :: from_str (
445
- & std:: env:: var ( "RUST_LOG" ) . unwrap_or ( glog_level. to_string ( ) ) ,
457
+ & std:: env:: var ( "MONARCH_STDERR_LOG" )
458
+ . unwrap_or ( stderr_log_level. to_string ( ) ) ,
446
459
)
447
460
. expect ( "Invalid log level" ) ,
448
461
) )
@@ -465,16 +478,13 @@ pub fn initialize_logging(clock: impl TelemetryClock + Send + 'static) {
465
478
} else {
466
479
None
467
480
} )
468
- . with ( if is_layer_enabled ( DISABLE_GLOG_TRACING ) {
469
- Some ( glog)
470
- } else {
471
- None
472
- } )
473
481
. with ( if is_layer_enabled ( DISABLE_RECORDER_TRACING ) {
474
482
Some ( recorder ( ) . layer ( ) )
475
483
} else {
476
484
None
477
485
} )
486
+ . with ( file_layer)
487
+ . with ( stderr_layer)
478
488
. try_init ( )
479
489
{
480
490
tracing:: debug!( "logging already initialized for this process: {}" , err) ;
@@ -502,13 +512,8 @@ pub fn initialize_logging(clock: impl TelemetryClock + Send + 'static) {
502
512
#[ cfg( not( fbcode_build) ) ]
503
513
{
504
514
if let Err ( err) = Registry :: default ( )
505
- . with (
506
- if std:: env:: var ( DISABLE_GLOG_TRACING ) . unwrap_or_default ( ) != "1" {
507
- Some ( glog)
508
- } else {
509
- None
510
- } ,
511
- )
515
+ . with ( file_layer)
516
+ . with ( stderr_layer)
512
517
. with (
513
518
if std:: env:: var ( DISABLE_RECORDER_TRACING ) . unwrap_or_default ( ) != "1" {
514
519
Some ( recorder ( ) . layer ( ) )
0 commit comments