File tree Expand file tree Collapse file tree 2 files changed +36
-1
lines changed
Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -218,6 +218,7 @@ pub(crate) type FormatFn = Box<dyn RecordFormat + Sync + Send>;
218218#[ derive( Default ) ]
219219pub ( crate ) struct Builder {
220220 pub ( crate ) format : ConfigurableFormat ,
221+ pub ( crate ) format_syslog : bool ,
221222 built : bool ,
222223}
223224
@@ -238,7 +239,25 @@ impl Builder {
238239 } ,
239240 ) ;
240241
241- Box :: new ( built. format )
242+ if !built. format_syslog {
243+ Box :: new ( built. format )
244+ } else {
245+ Box :: new ( |buf, record| {
246+ writeln ! (
247+ buf,
248+ "<{}>{}: {}" ,
249+ match record. level( ) {
250+ Level :: Error => 3 ,
251+ Level :: Warn => 4 ,
252+ Level :: Info => 6 ,
253+ Level :: Debug => 7 ,
254+ Level :: Trace => 7 ,
255+ } ,
256+ record. target( ) ,
257+ record. args( )
258+ )
259+ } )
260+ }
242261 }
243262}
244263
Original file line number Diff line number Diff line change @@ -160,6 +160,10 @@ impl Builder {
160160 self . parse_write_style ( & s) ;
161161 }
162162
163+ if env. is_daemon ( ) {
164+ self . format . format_syslog = true ;
165+ }
166+
163167 self
164168 }
165169
@@ -299,6 +303,13 @@ impl Builder {
299303 self
300304 }
301305
306+ /// If set to true, format log messages in a Syslog-adapted format.
307+ /// Overrides the auto-detected value.
308+ pub fn format_syslog ( & mut self , syslog : bool ) -> & mut Self {
309+ self . format . format_syslog = syslog;
310+ self
311+ }
312+
302313 /// Set the format for structured key/value pairs in the log record
303314 ///
304315 /// With the default format, this function is called for each record and should format
@@ -817,6 +828,11 @@ impl<'a> Env<'a> {
817828 fn get_write_style ( & self ) -> Option < String > {
818829 self . write_style . get ( )
819830 }
831+
832+ fn is_daemon ( & self ) -> bool {
833+ //TODO: support more logging systems
834+ Var :: new ( "JOURNAL_STREAM" ) . get ( ) . is_some ( )
835+ }
820836}
821837
822838impl < ' a , T > From < T > for Env < ' a >
You can’t perform that action at this time.
0 commit comments