Review of Jose Armando Garcia Sancio's std.log

Jonathan M Davis jmdavisProg at gmx.com
Tue Mar 6 20:21:19 PST 2012


On Tuesday, March 06, 2012 20:10:58 Andrei Alexandrescu wrote:
> On 3/6/12 7:43 PM, Jonathan M Davis wrote:
> > Because the level that you log something at and what you want to do in
> > terms of exceptions aren't necessarily related at all. It could easily be
> > that you want to log something and then do some series of operations
> > before throwing - even if the log level is the most severe level, and you
> > intend to throw an Error to kill the program. And as others have pointed
> > out, you might want to log a series of messages. Having std.log throw on
> > the first one makes it so that you can't log any others.
> 
> Then I guess you'd be well advised to use the function that "logs to the
> error log", not the one that "logs to the error log and then throws".
> No? I mean you're explaining how a screwdriver is not appropriate for
> pounding nails.

Sure, but std.log appears to have built in whether an exception is thrown or 
not into the log level itself. The log level and whether an exception is 
thrown are not necessarily related. Having one log function which throws and 
another which doesn't is fine. It's the fact that this proposal ties the 
exceptions to the log levels which is the problem.

> >>> std.log shouldn't be declaring _any_
> >>> exception types unless they're related to setting up the logging (_none_
> >>> which relate to functions which log).
> >> 
> >> Why?
> > 
> > Because as others have asserted, logging should not affect program flow.
> > It's
> > printing out messages to a log, which doesn't necessarily have _anything_
> > to do with throwing exceptions.
> 
> It does, because, as I mentioned, frequently one is interested in
> logging erroneous events that are followed by a breakage of flow.

Sure, you _may_ want to throw when you log, and having a way to do that in one 
command is fine. The problem is that you don't _always_ want to throw or not at 
a particular log level, and this std.log proposal ties to the two together.

> > And when you _do_ throw an exception, why on earth would anyone want a
> > LoggingException (or whatever std.log would call its exception type)? You
> > want an exception which relates to what went wrong, not what threw it.
> > The fact that you logged a message before throwing is incidental. Nothing
> > that catches the exception is going to care.
> 
> That I do agree with.

And the current proposal declares a CriticalException type which is thrown 
when logging at the critical level. So, while we may agree on this, the 
current proposal does not.

- Jonathan M Davis


More information about the Digitalmars-d mailing list