Implementing std.log

Jonathan M Davis jmdavisProg at gmx.com
Sat May 14 14:31:30 PDT 2011


On 2011-05-14 12:36, Andrei Alexandrescu wrote:
> On 05/14/2011 01:29 PM, dsimcha wrote:
> > On 5/14/2011 1:04 PM, Andrei Alexandrescu wrote:
> >> On 5/9/11 1:52 AM, Andrei Alexandrescu wrote:
> >> [snip]
> >> 
> >> I updated my std.log draft. Added a lot of features including formatted
> >> writing, delayed logging, and a variety of configuration options.
> >> Replaced the redundant log.xyz with logXyz. The implementation is
> >> getting close to reviewable form.
> >> 
> >> Documentation:
> >> 
> >> http://d-programming-language.org/phobos-prerelease/std_log.html
> >> 
> >> Source:
> >> 
> >> https://github.com/andralex/phobos
> >> 
> >> Feedback welcome.
> >> 
> >> 
> >> Thanks,
> >> 
> >> Andrei
> > 
> > Overall, I like this library a lot. One comment, though, is that the
> > docs should be more explicit about threading issues. I assume it's going
> > to be made thread-safe before inclusion in Phobos. Also, is there any
> > way to get thread-specific logs instead of having them intermingled?
> 
> Logs will be thread-shared. I haven't seen a need for thread-local logs.

I've dealt with code before where it was critical to know which log messages 
came from which thread if you had any hope of debugging what was going on. 
However, what I did was have the ID of each thread put at the beginning of 
every logged line, and it actually would have been a problem for them to be in 
separate logs, because it would have lost the timing. Of course, part of what 
I was doing there was tracking down problems with mutexes and race conditions 
and the like (and the code was _really_ bad about how it handled threads - 
every thread could be _anywhere_; no segregation at all), and that sort of 
problem isn't likely to crop up in D code. Still, knowing which thread is 
logging a particular message can be very useful. However, I question the 
usefulness of separating the log into thread-specific logs. It might be useful 
if std.log had an option to print the Thread's name at the beginning of every 
log line, but if not, someone who wanted that could always just include that 
at the beginning of their log messages.

So, I do think that knowing which thread is logging what could be very 
important for some programs, but I don't think that separating the log files 
is necessarily a good idea. If you did, you'd lose timing information (unless 
the time is at the beginning of every log line (which could also be useful), 
but then you'd have to read the times and compare them to see what happened 
before what). So, I'd be all for some options and extra information which 
could be added to each log line which would help debugging, but I don't think 
that thread-local logs is a great idea.

- Jonathan M Davis


More information about the Digitalmars-d mailing list