Review of Jose Armando Garcia Sancio's std.log
Jonathan M Davis
jmdavisProg at gmx.com
Tue Mar 6 17:07:57 PST 2012
On Tuesday, March 06, 2012 16:59:09 Andrei Alexandrescu wrote:
> I don't see why the agitation around this particular matter. It's a
> matter of convenience, much like writeln (as opposed to just write).
> Let's admit that it often happens that you want to log some troublesome
> stuff just before throwing an exception with essentially the same
> message, so the thing is shown on the screen and also persisted in the
> log. Without a critical level, the pattern would be:
>
> string message = stuff() + ": " + moreStuff();
> log.error(message);
> throw new Exception(message);
>
> It's nice to encapsulate this frequent pattern, hence:
>
> log.critical(stuff() + ": " + moreStuff());
>
> If you want to log but not throw, use log.error. I don't think the
> response "dont use those libraries either" is meaningful.
I think that it would be far more meaningful to have a logging function which
you pass the exception to throw. That way, you can throw whatever is
appropriate for your program, not have std.log throw a logging exception of
some kind. Such a function would be a convenience function where the
programmer is explicitly saying that they want to log and then throw rather
than having logging functions throw as a matter of course if the logging level
is critical enough. What if you want to log such a message _without_ throwing?
As it stands, std.log is conflating two separate concepts - logging and and
error handling. Providing a convenience function to make that easier is fine,
but making it so that the normal logging functions deal with error handling is
not.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list