Implementing std.log

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Mon May 9 10:45:23 PDT 2011


On 5/9/11 12:24 PM, Jacob Carlborg wrote:
> I assume the "initLogging" function needs the application command line
> because you want to have the name of the application? If that's the
> case, I don't like that is handled via the application command line. I
> have a function that gets the path of the current process:
>
> http://dsource.org/projects/tango/attachment/ticket/1536/process.d
>
> This links to a file attached to a Tango ticket but don't worry, I've
> written the whole file myself and I intend to change the license to the
> Boost License. It's written with D1 (obviously) but it's very easy to
> port to D2, the only dependencies are C functions.
>
> Feel free to port it to D2 and use it in you're logging library if you
> want to.

Thanks! In fact, the command-line arguments are needed for considerably 
more than just the application name. std.log is configurable via 
application's command line (e.g. --logtostderr --log_dir=/tmp/ etc., see 
documentation) and extracts these flags using getopt. The rest of the 
flags are left alone for the application to process.

In case the application would want to change a flag's name, e.g. use 
"--log_to_stderr" instead of "--logtostderr", it's easy to define an API 
that does that; currently all parameter names are hoisted in private 
strings in std.log.


Andrei


More information about the Digitalmars-d mailing list