std.logger

Robert Schadek realburner at gmx.de
Fri Aug 23 05:16:10 PDT 2013


On 08/23/2013 01:10 PM, Piotr Szturmaj wrote:
> so if I have a LogLevel variable I want to use:
>
> LogLevel myLogLevel;
>
> I need to write this:
>
> # alternative 1 (possibly wrapped in a function)
> switch (myLogLevel)
> {
>     case LogLevel.Info: log.Info("..."); break;
>     case LogLevel.Warning: log.Warning("..."); break;
>     case LogLevel.Error: log.Error("..."); break;
>     case LogLevel.Critical: log.Critical("..."); break;
>     case LogLevel.Fatal: log.Fatal("..."); break;
> }
>
> #alternative 2
> log.logLevel = myLogLevel; // not thread-safe (shared state)
> log("...");
the default logger is not shared. so no thread problems.
>
> I mean sure, it is possible to specify LogLevel for each message, but
> only at compile time (by the use of function names .Info, .Error, etc.).
>
> This is not what I meant in my previous post. I rather meant the
> ability to specify LogLevel using a runtime variable.

auto myLogger = new MyLogger(myLogLevel);
mylogger("my log msg");

>
>>>
>>> Then, each _compile-time_ specifiers like .Warning() or .Error()
>>> should be just a syntactic sugar over log().
>>
>
> Just thought that the ability to add user defined log levels may be
> useful too.
You can implement the abstract logger class and create new log
functions, but the design is intended to simple and user defined log
level makes it complex.



More information about the Digitalmars-d mailing list