Example code in std.logger.core doesn't even work

Christian Köstlin christian.koestlin at gmail.com
Thu Jul 13 21:44:18 UTC 2023


Thanks for all the explanations in the thread.

Reading again through
https://dlang.org/phobos/std_logger.html I think the chapter Basic 
Logging explains nicely how to work with sharedLog (but leaves out the 
shared detail).

Logging is something very dear to me and I think it's important to have 
that done right.

imho there are only two main usecases for logging:
1. logging to debug stuff (sometimes logging is easier than unittesting)
2. logging in production
those two usecases have quite different requirements (e.g. 1. needs to 
print as much out as it can before the program eventually crashes, 
whereas 2. needs to be as fast as possible, to not drain resources from 
the real program).

I think the current std.logger might be a good candidate as is for use 
case 1. It really tries hard to get the data out. I do not understand 
why FileLogger internally takes some more locks on the file (several 
calls to lockingTextWriter for one logmessage) (as my understanding is, 
that the locking is already done earlier on). Perhaps Robert can explain 
us why that is needed?

Also interesting is, that the sharedLog is not directly used, but with a 
thread local StdForwardLogger. For me the real thread safe locking 
happens here.

For usecase 2 I do not see how the existing loggers are a very good fit, 
as for my taste too much locking is going on. Still I think the API is 
powerfull enough to e.g. just forward the logmessages (that are not 
filtered out) from StdForwardLogger to a logger thread, that 
asynchronously outputs the log messages.

It would probably be great to also have a rotating filelogger, as this 
is something most people are used to.


Kind regards,
Christian


More information about the Digitalmars-d mailing list