Thread overview | |||||||||
---|---|---|---|---|---|---|---|---|---|
|
January 05, 2016 std.experimental.logger | ||||
---|---|---|---|---|
| ||||
I'm doing the following: import std.experimental.logger; int main(string[] args) { sharedLog = new FileLogger("logfile.log"); log("Test log 1"); log("Test log 2"); log("Test log 3"); } and I expected the logs to be seen in the logfile.log, but it seems like my reading of the docs on this is incorrect and the logfile.log is not populated at all (though it is created). What am I missing or using incorrectly? Basically I am trying to have the default logger log to a file instead of stderr. (I am on a Mac (OS-X 10.11.1, 64 bit) and using DMD 2.069.2) |
January 05, 2016 Re: std.experimental.logger | ||||
---|---|---|---|---|
| ||||
Posted in reply to sanjayss | On Tuesday, 5 January 2016 at 02:44:48 UTC, sanjayss wrote:
> I'm doing the following:
>
> import std.experimental.logger;
>
> int
> main(string[] args)
> {
> sharedLog = new FileLogger("logfile.log");
>
> log("Test log 1");
> log("Test log 2");
> log("Test log 3");
> }
>
>
> and I expected the logs to be seen in the logfile.log, but it seems like my reading of the docs on this is incorrect and the logfile.log is not populated at all (though it is created). What am I missing or using incorrectly?
>
> Basically I am trying to have the default logger log to a file instead of stderr.
>
> (I am on a Mac (OS-X 10.11.1, 64 bit) and using DMD 2.069.2)
You need to log with sharedLog:
sharedLog.log("Test log 1");
sharedLog.log("Test log 2");
sharedLog.log("Test log 3");
|
January 05, 2016 Re: std.experimental.logger | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mike | On Tuesday, 5 January 2016 at 02:49:01 UTC, Mike wrote: > On Tuesday, 5 January 2016 at 02:44:48 UTC, sanjayss wrote: >> I'm doing the following: >> >> import std.experimental.logger; >> >> int >> main(string[] args) >> { >> sharedLog = new FileLogger("logfile.log"); >> >> log("Test log 1"); >> log("Test log 2"); >> log("Test log 3"); >> } >> >> >> and I expected the logs to be seen in the logfile.log, but it seems like my reading of the docs on this is incorrect and the logfile.log is not populated at all (though it is created). What am I missing or using incorrectly? >> >> Basically I am trying to have the default logger log to a file instead of stderr. >> >> (I am on a Mac (OS-X 10.11.1, 64 bit) and using DMD 2.069.2) > > You need to log with sharedLog: > sharedLog.log("Test log 1"); > sharedLog.log("Test log 2"); > sharedLog.log("Test log 3"); Thanks, that works. But the docs are confusing -- it gives the impression that "sharedLog" is something associated with the default logger -- so I would expect the above to work with just the plain log() call to invoke the default logger. But it seems like I am just creating a new logger and using that by saying "sharedLog.log()". 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"); |
January 05, 2016 Re: std.experimental.logger | ||||
---|---|---|---|---|
| ||||
Posted in reply to sanjayss | On Tuesday, 5 January 2016 at 02:59:04 UTC, sanjayss wrote:
> On Tuesday, 5 January 2016 at 02:49:01 UTC, Mike wrote:
>> [...]
>
> Thanks, that works. But the docs are confusing -- it gives the impression that "sharedLog" is something associated with the default logger -- so I would expect the above to work with just the plain log() call to invoke the default logger. But it seems like I am just creating a new logger and using that by saying "sharedLog.log()".
>
> 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");
You are right, according to the docs your example should've worked just fine. Tried it myself on DMD 2.069.2 and it doesn't work either. You should raise an issue on github.
|
January 05, 2016 Re: std.experimental.logger | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mike | On Tuesday, January 05, 2016 03:01:14 Mike via Digitalmars-d-learn wrote: > You are right, according to the docs your example should've worked just fine. Tried it myself on DMD 2.069.2 and it doesn't work either. You should raise an issue on github. We don't use the issue system on github. We use bugzilla: https://issues.dlang.org Please report any issues you find there. - Jonathan M Davis |
January 05, 2016 Re: std.experimental.logger | ||||
---|---|---|---|---|
| ||||
Posted in reply to sanjayss | On Tuesday, 5 January 2016 at 02:44:48 UTC, sanjayss wrote:
> I'm doing the following:
>
> import std.experimental.logger;
>
> int
> main(string[] args)
> {
> sharedLog = new FileLogger("logfile.log");
>
> log("Test log 1");
> log("Test log 2");
> log("Test log 3");
> }
diff:
sharedLog = new FileLogger("logfile.log", LogLevel.all);
calling log uses the globalLogLevel, which is LogLevel.all by default.
The default LogLevel of a new FileLogger is LogLevel.info.
So the new FileLogger drops the log messages.
This is an inconsistency I will fix.
|
January 05, 2016 Re: std.experimental.logger | ||||
---|---|---|---|---|
| ||||
Posted in reply to Robert burner Schadek | On Tuesday, 5 January 2016 at 09:18:21 UTC, Robert burner Schadek wrote:
> On Tuesday, 5 January 2016 at 02:44:48 UTC, sanjayss wrote:
>> I'm doing the following:
>>
>> import std.experimental.logger;
>>
>> int
>> main(string[] args)
>> {
>> sharedLog = new FileLogger("logfile.log");
>>
>> log("Test log 1");
>> log("Test log 2");
>> log("Test log 3");
>> }
>
> diff:
> sharedLog = new FileLogger("logfile.log", LogLevel.all);
>
> calling log uses the globalLogLevel, which is LogLevel.all by default.
> The default LogLevel of a new FileLogger is LogLevel.info.
> So the new FileLogger drops the log messages.
>
> This is an inconsistency I will fix.
Thanks -- seems like you found my bugzilla issue and fixed the problem. I'll try using your diff above and see if that helps me.
|
Copyright © 1999-2021 by the D Language Foundation