Implementing std.log

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Mon May 9 12:08:32 PDT 2011


On 5/9/11 1:30 PM, Robert Clipsham wrote:
> On 09/05/2011 07:52, Andrei Alexandrescu wrote:
>> On 5/7/11 3:43 PM, Jose Armando Garcia wrote:
>>> Hey folks,
>>>
>>> For the past couple of days I took the liberty of partially
>>> implementing a logging module for D.
>> [snip]
>>
>> Nice work. Also thanks for contacting me offline.
>>
>> As I mentioned I'd already decided I'll take a stab at implementing a
>> logging module inspired in design from glog. I was tired of the endless
>> discussions on what a logging API should look like. This ironically is
>> leading now to an embarrassment of riches - we now have two proposals on
>> the table. I subjectively prefer mine for the simple reason that it
>> includes exactly what I wanted from a logging subsystem with a light
>> syntax.
>>
>> The documentation is at
>> http://d-programming-language.org/phobos-prerelease/std_log.html.
>>
>> The source code is at http://erdani.com/log.d, with informative title
>> only; to compile the code you'd need some changes in std.format as well
>> (I extended the positional parameter syntax to allow ranges of
>> positions). Todos include slight refactoring to avoid bloat in generated
>> code per call, OS portability (I only tested on OSX), and getting
>> threading right by fixing the shared-related compiler bugs.
>>
>> Looking forward to more discussion of the matter.
>>
>>
>> Andrei
>
> The example looks great, exactly what I'd hope for in the way of a
> logging library. A few questions:
>
> * How do you disable logging at compile time? (and is it zero overhead?)

Passing -version=strip_log_error during compilation strips all error, 
warning, and info messages; passing -version=strip_log_warning strips 
all warning and info messages; and passing -version=strip_log_info 
strips all info messages. The critical and fatal logs cannot be stripped 
out.

With -O -release -inline, log.info(arguments) leaves no trace in the 
generated object file. However, log.info.when(condition)(arguments) does 
leave a few calls behind. This is an issue in the inliner that will need 
to be fixed before releasing std.log.

> * How do you define your own logging backend?

Currently the backend API is not exposed. The focus now is to get good 
client-level functionality in shape, after which we can work on a more 
refined API. We'll also need to tune the code to not generate undue 
bloating.

> * Is it possible to change logging options after initialisation?

Not for the time being. I agree that that's a good thing to have. 
Everything is ready for exposure, so writing a couple of extra APIs 
should be easy.

> There are a couple of features missing, but you seem to have mentioned
> planning to implement these elsewhere in the thread. Once they're in
> place I'd be happy to vote yes to its inclusion into phobos.

Sounds great!


Andrei


More information about the Digitalmars-d mailing list