Early review of std.logger

Martin Drasar drasar at ics.muni.cz
Mon Oct 14 05:32:47 PDT 2013


Having skimmed through the docs I noticed that there are three features
missing that I use and would like to see in standard logger. First is
the ability to write to several loggers at once, the second is optional
formatting of log output and the third is an option to tell logger to
log only one concrete log level.

All these can be accomplished by writing my own logger that would do
this, but it would be nice to have some batteries included, e.g.:

1) MultiLogger class that takes references to other loggers and just
forwards the call to the log function.

2) Optional string parameter that describes the desired log output (i.e.
format and position of timestamp, line, file, message, ...) for
different needs, e.g. machine vs. human read log.

2.1) Allow more than one string to be logged. For example I want to add
component name, task identifier, etc., but I want to let correct
formatting on the logger.

***
Example:

auto machineLogger = new FileLogger(format = "%ts;%f;%l;{1};{2};{3};");
auto humanLogger = new FileLogger(format = "[%ts] :: %f:%l\nComponent:
{1}\nTask:{2}\n{3});

machineLogger.log("Some component", "Some task", "Everything is well");

output =>
2013-10-14 14:28:05;file.d;54;Some component;Some task;Everything is well;

humanLogger.log("Some component", "Some task", "Everything is well");

output =>
[2013-10-14 14:28:05] :: file.d:54
Component: Some component
Task: Some task
Everything is well
***

Regards,
Martin


More information about the Digitalmars-d mailing list