On Thursday, 11 September 2014 at 16:55:32 UTC, Marco Leise wrote:

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.

This is a tricky situation.  Log files generally have a specific
format for a given application, and I often don't want APIs I
call writing lines to whatever log I have open.  What I tend to
like the best is for APIs that log data to log to an internal
circular buffer, and provide me the option to request that log
data.  Then if I get an error while using that API and I want
additional context, I can pull the internal logs and examine them
or dump them in my own application's log file.

Reply via email to