[Issue 15517] New: std.experimental.logger: using 'sharedLog' to change to file logging for default logger does not work

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Mon Jan 4 19:36:20 PST 2016


https://issues.dlang.org/show_bug.cgi?id=15517

          Issue ID: 15517
           Summary: std.experimental.logger: using 'sharedLog' to change
                    to file logging for default logger does not work
           Product: D
           Version: D2
          Hardware: x86
                OS: Mac OS X
            Status: NEW
          Severity: minor
          Priority: P1
         Component: phobos
          Assignee: nobody at puremagic.com
          Reporter: varaccts at yahoo.com

import std.experimental.logger;

void
main(string[] args)
{
    sharedLog = new FileLogger("logfile.log");

    log("Test log 1");
    log("Test log 2");
    log("Test log 3");
}

$ ls -l logfile.log
-rw-r--r--  1 randomuser  staff  0 Jan  4 19:19 logfile.log

The above creates the 'logfile.log' file, but does not seem to redirect the
default logs to the file -- at program exit, the 'logfile.log' is empty. From
the documentation, this should've changed the default logger to logging to the
file from logging to stderr.


Referring to the 'sharedLog' works though -- it seems like this just creates a
new logger and doesn't affect the default logger property??

import std.experimental.logger;

void
main(string[] args)
{
    sharedLog = new FileLogger("logfile.log");

    sharedLog.log("Test log 1");
    sharedLog.log("Test log 2");
    sharedLog.log("Test log 3");
}

$ ls -l logfile.log
-rw-r--r--  1 randomuser  staff  142 Jan  4 19:34 logfile.log

As per the doc:

>From the doc:

The default Logger will by default log to stderr and has a default LogLevel of
LogLevel.all. The default Logger can be accessed by using the property called
sharedLog. This property a reference to the current default Logger. This
reference can be used to assign a new default Logger.

 sharedLog = new FileLogger("New_Default_Log_File.log");

--


More information about the Digitalmars-d-bugs mailing list