Implementing std.log

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Mon May 9 10:27:57 PDT 2011


On 5/9/11 12:10 PM, Jacob Carlborg wrote:
> On 2011-05-09 17:49, Andrei Alexandrescu wrote:
>> On 5/9/11 10:37 AM, Jacob Carlborg wrote:
>>> Isn't the name of the log file a little too verbose? Don't know if I'm
>>> missing something but this doesn't seem so useful for long running
>>> application that use logging. As far as I know you usually have one log
>>> file per application and outputs the message along with the level and
>>> date and time.
>>
>> I did what glog does. Going forward, there is a private static string
>> for formatting file names using positional parameters. In the future I'm
>> considering providing an API for changing that format string, which
>> means the log file format will be user-definable. (Same about the format
>> of individual messages - see the string constants fileNameFormat and
>> format toward the top of log.d.) Positional parameters look a bit odd
>> but they are quite flexible.
>>
>> Andrei
>
> Excuse me for asking again but to me it seems that the log functions
> will output a new file for every log event (since the time is included
> in the filename). Is that the case?

No, log files are created and opened only once, and the time in the 
filename reflects the creation time. Logging messages also contain the 
time (with added precision) and go to the respective files. A maximum of 
five files are created. (No support for rotating logs for the time being.)

There's one difference from glog by the way - glog defines four levels 
and consequently four files: info, warning, error, and fatal. I defined 
critical in between error and fatal. Logging to the critical log throws 
an exception right after logging. I think this is very useful for 
figuring out what happens in exceptional code.


Andrei



More information about the Digitalmars-d mailing list