This example shows you how easy it is to add your custom formatter /destination classes.
This usage:
- You have one logger
- You have one filter, which can be turned on or off
- You want to format the message before it's written
- The logger has several log destinations
- The output goes to console, debug output window, and a file called out.txt - as XML
- Formatting - prefix each message by its start time, its index, and append newline
Custom classes:
- secs_since_start - custom formatter
- as_xml - custom destination
Optimizations:
- use a cache string (from optimize namespace), in order to make formatting the message faster
The output will look similar to this one:
The console and the debug window will be the same:
+6s [1] this is so cool 1
+6s [2] this is so cool again 2
+7s [3] hello, world
+7s [4] good to be back ;) 3
The out.txt file will look like this:
<msg>+6s [1] this is so cool 1
</msg>
<msg>+6s [2] this is so cool again 2
</msg>
<msg>+7s [3] hello, world
</msg>
<msg>+7s [4] good to be back ;) 3
</msg>
Copyright John Torjo © 2007
Have a question/ suggestion/ comment? Send me feedback