In a recently project, I needed a good log system, as usual I looking for any one, no found one, well, no that adjust to my needs, so I wrote LoggerFactory my own logger.
Should fit this (and others) needs:
- Easy to use
- Asynchronous by default using threads
- Various outputs by TypeLevel
- Custom format outputs
Based on very good loggers as java.util.logging or MacOS Logging, I made LoggerFactory the result was very thin with no more 900+ lines of code, with the features I want for my project and for any other projects what need it.
Levels: ALL, DEBUG, ERROR, FATAL, INFO, TRACE, WARN
By default console and system.DebugLog are set, you can configure adding a Adder with LoggerFactory.Adders.Append example:
In the previous snippet, set one “Addler” for console and other for file, here I explain “Adders”, Adders is for “add” outputs (messages) for each level, or to a file, properties or file. The default Adders are:
- ConsoleAdder: Outputs for console (only for console proyects)
- SystemDebugLogAdder: The normal System.DebugLog
- SystemLogAdder: The System.Log
- FileLogAdder: Outputs to file
One intetesting thing is we can, for example, set DEBUG outputs to SystemDebugLogAdder, plus ERROR outputs to a file, change the output format also you made you own Adders, You can sub-classing LoggerFactory.Adder and overwrite “Log” method; You can create outputs to, for example, to a database or web service; only setting Adders, no other code change.
Another interesting feature of Adders is setting the output format, like:
“SEP” is a property of adder, TAB [Chr(9) en ASCII] is default and you can also set.
The FileLogAdder can be set “roll over”, with the FileLogAdder.FileType property and could be: same file, yearly, monthly, daily, hourly or by size.
Last, I talk about “Formatter”, you can use Str() o Format() for format outputs or code as:
%d: Signed integers
%u: Unsigned integers
%f: Signed doubles/singles