Review: std.logger

Robert burner Schadek via Digitalmars-d digitalmars-d at puremagic.com
Tue Jul 22 16:43:58 PDT 2014


On Tuesday, 22 July 2014 at 21:52:09 UTC, linkrope wrote:
> Sorry, but at the first contact with the implementation (the 
> one with 'genDocComment' and 'buildLogFunction' from months 
> ago) I was scared away. (It's better now.)

There was no need, even read that, for implementing a 
FileRotateLogger

>
> I feared that if I criticize the 'mixin' sequences you would 
> ask something like "suggestions?" ;-)
> So, I made this experiment to provide an answer. Now, I can 
> suggest: try something like this:
>
>     alias trace = log!(LogLevel.trace);
>     alias info = log!(LogLevel.info);
>     alias warn = log!(LogLevel.warn);
>     alias error = log!(LogLevel.error);
>     alias fatal = log!(LogLevel.fatal);
>
> (see https://github.com/linkrope/log/blob/master/src/log.d)

I did and I had to mod it quite a bit to make it work with 
default logging instance logging and an more elaborate api

>
> Controversial conditional logging
> ----------------------------
> The only advantage of
>     tracec(condition, "passed");
> over
>     if (condition) trace("passed");
> would be, that a costly evaluation of the condition is omitted 
> when there is no trace logger.
> That's why the std.log proposal had 'when(lazy bool now)'.
>
> First, I was puzzled about your argument that LOG_FIRST_N or 
> LOG_EVERY_N would be no problem with the '...c' functions. But 
> a look at the implementation confirmed that the std.logger has 
> no lazy evaluation of the condition; discarding the only 
> advantage.

passing a bool as a delegate that is the first thing that gets 
evaluated does not sound right.

>
> Sets of log levels
> --------------
> No!
> Of course, I can log (trace | info) to stdout, warn.orHigher to 
> stderr, and for instance info.orHigher to some file.
>
> Simplicity
> --------
> "The simplest way to achieve simplicity is through thoughtful 
> reduction."
>
> We started with tango.util.log (best described as log4j for D). 
> We are happier now with a lot less functionality, but on the 
> other hand with the simplest API that works.

In your last post you said that you wrote it on a weekend, which 
is it?

That api may work for your requirements, but this should go into 
phobos and allow anybody to get satisfied.


More information about the Digitalmars-d mailing list