File tree Expand file tree Collapse file tree 1 file changed +10
-26
lines changed Expand file tree Collapse file tree 1 file changed +10
-26
lines changed Original file line number Diff line number Diff line change 1- use std:: io:: Write ;
2-
3- use env_logger:: fmt:: Formatter ;
4- use log:: Record ;
5-
61fn main ( ) {
7- match std:: env:: var ( "RUST_LOG_STYLE" ) {
8- Ok ( s) if s == "SYSTEMD" => env_logger:: Logger :: from_default_env ( )
9- . with_format ( Box :: new ( |buf : & mut Formatter , record : & Record < ' _ > | {
10- writeln ! (
11- buf,
12- "<{}>{}: {}" ,
13- match record. level( ) {
14- log:: Level :: Error => 3 ,
15- log:: Level :: Warn => 4 ,
16- log:: Level :: Info => 6 ,
17- log:: Level :: Debug => 7 ,
18- log:: Level :: Trace => 7 ,
19- } ,
20- record. target( ) ,
21- record. args( )
22- )
23- } ) )
24- . try_init ( )
25- . unwrap ( ) ,
26- _ => env_logger:: init ( ) ,
27- } ;
2+ env_logger:: builder ( )
3+ . parse_default_env ( )
4+ // While journald-logging is auto-detected, but you can manually override it.
5+ // Especially useful if you are using a different logging system.
6+ . format_syslog ( true )
7+ . init ( ) ;
8+
9+ // Prints in a human readable way if run interactively,
10+ // and in a syslog-compatible way if run as a systemd service.
11+ log:: info!( "we are logging" ) ;
2812}
You can’t perform that action at this time.
0 commit comments