Early review of std.logger
Robert Schadek
realburner at gmx.de
Tue Oct 15 06:07:43 PDT 2013
On 10/15/2013 02:54 PM, Sönke Ludwig wrote:
> What I meant is just that in Druntime there is something like this:
>
> struct LogManager {
> static void somefunc();
> }
>
> instead of
>
> class LogManager {
> static void someFunc();
> }
>
> In any case, such a struct/class should also have a member "@disable
> this();" so that it cannot be uselessly instantiated.
I see what you mean, good point.
>
> The log messages are supposed to go to the same destination, just
> filtered by log level. A totally artificial example:
>
> ---
> void main(string[] args)
> {
> logDiagnostic("Application called as %s", args[0]);
> ubyte[] contents;
> try {
> logTrace("Going to read file");
> contents = read("somefile.dat");
> logTrace("Done reading file");
> } catch (Exception e) {
> logError("Failed to read input file.");
> logDiagnostic("Reported error: %s", e.msg);
> logDebug("Full exception: %s", e.toString());
> return 1;
> }
> logInfo("Input file is %d bytes", contents.length);
> logTrace("Computing sum");
> auto sum = sum(contents);
> logTrace("Removing file");
> remove("somefile.dat");
> }
>
> ulong sum(ubyte[] arr)
> {
> ulong ret = 0;
> foreach (b; arr) {
> logDebugV("Adding %d", b);
> ret += b;
> }
> logDebugV("Sum result: %d", b);
> return ret;
> }
> ---
Ok, you can achieve this by assigning a LogLevel to the defaultLogger.
Than all message with a LogLevel >= to the assigned LogLevel will be
logged. Or do you want to, for example, filter all message with critical
and debug LogLevel, but don't display the messages with LogLevels in
between?
>
> BTW you stated that there is a "debug" level in your implementation,
> but neither the docs, nor the pull request have it.
You're right I was reading Debug and thought Info, my bad!
More information about the Digitalmars-d
mailing list