Implementing std.log

Denis Koroskin 2korden at gmail.com
Thu Apr 21 07:16:15 PDT 2011


On Thu, 21 Apr 2011 16:58:17 +0400, Jens Mueller <jens.k.mueller at gmx.de>  
wrote:

> Denis Koroskin wrote:
>> On Thu, 21 Apr 2011 01:34:29 +0400, so <so at so.com> wrote:
>>
>> >>For me, Logger needs to be simple but feature complete. Here is
>> >>my ideal syntax:
>> >>
>> >>Logger log = new Logger();
>> >>log.warn("bewarned");
>> >>log.error("error code: %d", 42);
>> >>log.fatal("Derp");
>> >
>> >Fine if you remove the first line, switching the output is
>> >something we rarely do, so we shouldn't mandate this for each use.
>> >
>> >note("just a note :", 5);
>> >note!warn("bewarned");
>> >note!error(c, ", ", d);
>>
>> Having different loggers for different parts of programs (e.g.
>> separate logger for my rendering, separate one for audio, separate
>> for physics, and so on) is a must for me.
>> Because when you debug your code by analyzing log output, you want
>> to be able to filter out non-relevant stuff. If you only have ONE
>> logger, you will start adding stupid prefixes like this:
>>
>> error("GAME/GAMEMODE_CHALLENGE/OBJECTIVE_CHECKER: match data frame
>> is not valid");
>>
>> instead of
>>
>> log.error("match data frame is not valid");
>
> This can be solved by taking the compilation unit into account. I.e.
> each logging statement is associated with a file, namely the file it was
> used in, i.e. __FILE__. Then one only needs the ability to
> disable/enable logging per compilation unit. See e.g. glog's
> VLOG/--vmodule on  
> http://google-glog.googlecode.com/svn/trunk/doc/glog.html
>
> Jens

That could work, I guess. Either way, one line of code is that much of a  
difference, I believe.


More information about the Digitalmars-d mailing list