Skip to content

Streamformatter

greggwon edited this page May 31, 2013 · 13 revisions

The NetLog.Logging.StreamFormatter class is a NetLog.Logging.Handler subclass. It has the following set of properties which can be set to control some aspects of its formatting to create abbreviated output.

  • NetLog.Logging.StreamFormatter.Brief=true/false - Changes date formatting to just time
  • NetLog.Logging.StreamFormatter.WithTime=true/false - Remove date/time altogether
  • NetLog.Logging.StreamFormatter.TruncatedPackageName=true/false - 'this.package.Name' becomes 'Name'
  • NetLog.Logging.StreamFormatter.WithClass=true/false - turn off inclusion of any class name included in LogRecord
  • NetLog.Logging.StreamFormatter.WithMethod=true/false - turn off includes of any method name included in LogRecord

As an example, the following code, if run with the default configuration of the package, will generate the output formatted as shown below this code listing.

log = Logger.GetLogger( "NetLog.test.LogText" );
StreamFormatter f = (StreamFormatter)Logger.GetLogger("").GetHandlers()[0].Formatter;
Logger.GetLogger("").GetHandlers()[0].Level = Level.ALL;
log.info("normal message");
f.TruncatedPackageName = true;
log.info("truncated package name");
f.Brief = true;
log.info("brief output");
f.WithTime = false;
log.info("no time");
log.Level = Level.ALL;
f.WithTime = true;
f.Brief = false;
f.TruncatedPackageName = false;
log.entering( GetType().FullName, "MyMethod" );
f.WithClass = false;
log.exiting( GetType( ).FullName, "MyMethod" );
f.WithMethod = false;
log.entering( GetType( ).FullName, "AnotherMethod" );

This is the generated/logged output from the above code.

2013/05/31 17:47:10.322 [NetLog.test.LogText#1] INFO # normal message
2013/05/31 17:47:10.337 [LogText#2] INFO # truncated package name
17:47:10 INFO # brief output
INFO # no time
2013/05/31 17:47:10.338 [NetLog.test.LogText#5] FINER # : from=LogTesting.LogTesting.MyMethod( ) ENTRY
2013/05/31 17:47:19.753 [NetLog.test.LogText#6] FINER # : from=MyMethod( ) EXIT
2013/05/31 17:47:19.754 [NetLog.test.LogText#7] FINER # ENTRY

Clone this wiki locally