std.experimental.logger: practical observations

Robert burner Schadek via Digitalmars-d digitalmars-d at puremagic.com
Sat Sep 13 07:34:16 PDT 2014


On Friday, 12 September 2014 at 16:08:42 UTC, Marco Leise wrote:
>
> Remember that the stdlog is __gshared? Imagine we set the
> LogLevel to off and while executing writeLogMsg ...
>
> * a different thread wants to log a warning to stdlog
> * a different thread wants to inspect/set the log level
>
> It is your design to have loggers shared between threads.
> You should go all the way to make them thread safe.
>
> * catch recursive calls from within the same thread,
>   while not affecting other threads' logging
> * make Logger a shared class and work with atomicLoad/Store,
>   a synchronized class or use the built-in monitor field
>   through synchronized(this) blocks.

hm, I don't know of any magic pill for that. I guess this would 
require some dataflow analysis.
>
>> > 3. Exceptions and loggin don't mix.
>> > How do you log errors that also throw exceptions ?
>> 
>> please elaborate. I think I misunderstand
>
> I know when to throw an exception, but I never used logging
> much. If some function throws, would I also log the same
> message with error() one line before the throw statement?
> Or would I log at the place where I catch the exception?
> What to do about the stack trace when I only have one line per
> log entry?
> You see, I am a total newbie when it comes to logging and from
> the question that arose in my head I figured exceptions and
> logging don't really mix. Maybe only info() and debug() should
> be used and actual problems left to exception handling alone.

that is depended on what your program requires. You can write 
more than one line, just indent it by a tab or two. again no 
magic pill as far as I know


More information about the Digitalmars-d mailing list