@@ -40,6 +40,7 @@ pub struct Builder {
4040 writer : writer:: Builder ,
4141 format : fmt:: ConfigurableFormat ,
4242 built : bool ,
43+ is_syslog : bool ,
4344}
4445
4546impl Builder {
@@ -160,6 +161,10 @@ impl Builder {
160161 self . parse_write_style ( & s) ;
161162 }
162163
164+ if env. is_daemon ( ) {
165+ self . is_syslog = true ;
166+ }
167+
163168 self
164169 }
165170
@@ -291,6 +296,13 @@ impl Builder {
291296 self
292297 }
293298
299+ /// If set to true, format log messages in a Syslog-adapted format.
300+ /// Overrides the auto-detected value.
301+ pub fn format_syslog ( & mut self , syslog : bool ) -> & mut Self {
302+ self . is_syslog = syslog;
303+ self
304+ }
305+
294306 /// Set the format for structured key/value pairs in the log record
295307 ///
296308 /// With the default format, this function is called for each record and should format
@@ -480,7 +492,11 @@ impl Builder {
480492 Logger {
481493 writer : self . writer . build ( ) ,
482494 filter : self . filter . build ( ) ,
483- format : Box :: new ( std:: mem:: take ( & mut self . format ) ) ,
495+ format : if self . is_syslog {
496+ fmt:: SyslogFormatter . build ( )
497+ } else {
498+ self . format . build ( )
499+ } ,
484500 }
485501 }
486502
@@ -822,6 +838,11 @@ impl<'a> Env<'a> {
822838 fn get_write_style ( & self ) -> Option < String > {
823839 self . write_style . get ( )
824840 }
841+
842+ fn is_daemon ( & self ) -> bool {
843+ //TODO: support more logging systems
844+ Var :: new ( "JOURNAL_STREAM" ) . get ( ) . is_some ( )
845+ }
825846}
826847
827848impl < ' a , T > From < T > for Env < ' a >
0 commit comments