std.experimental.logger: practical observations
Robert burner Schadek via Digitalmars-d
digitalmars-d at puremagic.com
Thu Sep 11 14:32:44 PDT 2014
On Thursday, 11 September 2014 at 16:55:32 UTC, Marco Leise wrote:
> So I've implemented my first logger based on the abstract
> logger class, (colorize stderr, convert strings to system
> locale for POSIX terminals and wstring on Windows consoles).
>
> 1. Yes, logging is slower than stderr.writeln("Hello, world!");
> It is a logging framework with timestamps, runtime
> reconfiguration, formatting etc. One has to accept that. :p
what he said
>
> 2. I noticed that as my logger implementation grew more complex
> and used functionality from other modules I wrote, that if
> these used logging as well I'd easily end up in a recursive
> logging situation.
>
> Can recursion checks be added somewhere
> before .writeLogMsg()?
I think I don't follow. Just to clear
foo() {
log(); bar();
}
bar() {
log(); foo();
}
?
>
> 3. Exceptions and loggin don't mix.
> Logging functions expect the file and line to be the one
> where the logging function is placed. When I work with C
> functions I tend to call them through a template that will
> check the error return code. See:
> http://dlang.org/phobos/std_exception.html#.errnoEnforce
> Such templates pick up file and line numbers from where
> they are instantiated and pass them on to the exception
> ctor as runtime values.
> Now when I use error(), I see no way to pass it runtime
> file and line variables to make the log file reflect the
> actual file and line where the error occured, instead of
> some line in the template or where ever I caught the
> exception.
> Not all errors/exceptions are fatal and we might just want
> to log an exception and continue with execution.
hm, I think adding template function as requested by dicebot
would solve that problem, as it would take line and friends as
function parameters
More information about the Digitalmars-d
mailing list