Bug 15517 – std.experimental.logger: using 'sharedLog' to change to file logging for default logger does not work
Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P4
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Mac OS X
Creation time
2016-01-05T03:36:20Z
Last change time
2018-01-05T13:29:02Z
Assigned to
No Owner
Creator
varaccts
Comments
Comment #0 by varaccts — 2016-01-05T03:36:20Z
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");