Logging best practices

mw mingwu at gmail.com
Sun May 31 20:04:11 UTC 2020


On Sunday, 31 May 2020 at 07:49:01 UTC, Luis wrote:
> On Saturday, 30 May 2020 at 18:17:21 UTC, mw wrote:
>>
>> A related question: how to log to multiple destinations? e.g. 
>> both console & log file? any examples?
>>
>> Thanks.
>
> ```D
> auto multiLogger = new MultiLogger();
> multiLogger.insertLogger("console", new FileLogger(stdout, 
> LogLevel.all));
> multiLogger.insertLogger("file", new FileLogger(outputFile, 
> LogLevel.all));
>
> sharedLog = multiLogger;
> ```
> If you are missing color output for log level , you can use 
> this ConsoleLogger

Thanks.

For the colored console logger, I'm using this one:

https://code.dlang.org/packages/colored-logger

so far so good. (I prefer to use library, instead of reinvent my 
own wheels :-).




More information about the Digitalmars-d-learn mailing list