Creating a logging library and have questions
sybrandy
sybrandy at gmail.com
Sat Feb 6 16:08:34 PST 2010
>
> I second Rainer. A logging system should commit (at least) error messages immediately, particularly if the application has multiple threads. Otherwise it is going to make debugging a crashing system a nightmare. When I do it I just stick 'synchronized' in front of the statement that does the write.
>
>
Yes, I fully understand that and in the current single-threaded version
I have, that's exactly what happens: all error and fatal messages cause
the buffer to flush.
What I'm looking for is the best way to handle having a daemon writer.
My biggest concern here is multi-threaded applications. Granted, it
would be nice to not have the writing in the same thread as the rest of
the code to try to keep file I/O from affecting performance, but that's
secondary.
Here's what I know: a variable of type OutputStream cannot be shared. I
did not try using __gshared, but regardless while this would work and I
could easily synchronize the writes, I can see a lot of contention if
multiple threads trying to write a lot of data to a log file. (E.g.
trace statements that capture variable states to enhance debugging)
Granted, this shouldn't be the case in production code, but if I can
find a better way to do this, I'd love to. This is why I thought that
the new threading model with message passing would be good, but I again
have concerns if there are a lot of messages trying to be written. I
know in Erlang you can fill up the message buffer if you're not careful.
Casey
More information about the Digitalmars-d-learn
mailing list