Early review of std.logger

Robert Schadek realburner at gmx.de
Mon Oct 14 06:43:29 PDT 2013


On 10/14/2013 03:31 PM, Martin Drasar wrote:
> On 14.10.2013 15:18, Robert Schadek wrote:
>> On 10/14/2013 02:32 PM, Martin Drasar wrote:
>>> 1) MultiLogger class that takes references to other loggers and just
>>> forwards the call to the log function.
>> will be done, see the reply to Sönke's post.
> Cool
>
Cool
>>> 2) Optional string parameter that describes the desired log output (i.e.
>>> format and position of timestamp, line, file, message, ...) for
>>> different needs, e.g. machine vs. human read log.
>> I thought about that, but I'm not sure if that won't the logger to
>> complex.  IMO it is better to have some reasonable hard-coded default
>> than a log format parser. If the user needs something else, subclassing
>> a logger and changing the format is a 7 liner. And this is the design
>> Idea behind the logger.
> True, it would definitely make the logger more complex. Default
> implementation would just help developers that want this feature avoid
> the pitfalls of string formatting (e.g. buffers vs. allocation as was
> discussed in previous thread on std.logger).
Yes, but you have to lookup the formatting parameter, which adds some
complexity. It would also a time complexity for each logging call,
because you would have to parse the format. IMO KISS.
>>> 2.1) Allow more than one string to be logged. For example I want to add
>>> component name, task identifier, etc., but I want to let correct
>>> formatting on the logger.
>> logf("name %s, taskId %s", name, taskId); already works
> This was tightly coupled with the previous request, i.e. not using
> string format and logging one string, but passing several strings and
> let the target logger assemble them as it see fit.
This plays in my hands exactly, you have properly some idea of "see fit"
and I can't anticipate this and properly can't create such a flexible
configuration that makes it all see fit. So write you're own logger and
handle all strings our own. Just ignore the printf style formatted
string at the beginning or just call logf("", string1, string2, ...) and
mix string1 and friend as you see fit ;-)
>
>> Thanks, keep it coming
> How about being able to log only certain log level(s) and not only
> greater or equal?
>
> Martin
Well, Bitmasked come to mind, but I really don't want to go C-Style and
I think that defeats the purpose of having levels.


More information about the Digitalmars-d mailing list