digitalmars.D.learn - std.logger sharedLog usage
- lobo (17/17) Mar 28 2015 Hi,
- lobo (17/34) Mar 28 2015 Hmm, I should read code before posting. logf() etc. are using
- Robert burner Schadek (5/22) Mar 29 2015 just add the line stdThreadLocalLog.logLevel = LogLevel.info
- lobo (3/33) Mar 29 2015 Thank you, lobo.
- Robert burner Schadek (3/4) Mar 30 2015 next version will have equal default LogLevel for all Logger.
Hi, I'm trying to use std.experimental.logger and I'd like the logf(), tracef() style functions to log to a file and stdout. (note: I can use sharedLog.logf(), sharedLog.tracef(), but I prefer just logf()) So I did this: shared static this() { auto ml = new MultiLogger(); ml.insertLogger("stdout", new FileLogger(std.stdio.stdout)); ml.insertLogger("applog", new FileLogger("applog.txt")); sharedLog = ml; logf("This is a test"); // Doesn't work } Which doesn't work, so I'm wondering if it's possible to do what I want. thanks, lobo
Mar 28 2015
On Sunday, 29 March 2015 at 01:36:24 UTC, lobo wrote:Hi, I'm trying to use std.experimental.logger and I'd like the logf(), tracef() style functions to log to a file and stdout. (note: I can use sharedLog.logf(), sharedLog.tracef(), but I prefer just logf()) So I did this: shared static this() { auto ml = new MultiLogger(); ml.insertLogger("stdout", new FileLogger(std.stdio.stdout)); ml.insertLogger("applog", new FileLogger("applog.txt")); sharedLog = ml; logf("This is a test"); // Doesn't work } Which doesn't work, so I'm wondering if it's possible to do what I want. thanks, loboHmm, I should read code before posting. logf() etc. are using stdThreadLocalLog so this does what I want: shared static this() { auto ml = new MultiLogger(); ml.insertLogger("stdout", new FileLogger(std.stdio.stdout)); ml.insertLogger("applog", new FileLogger("applog.txt")); stdThreadLocalLog = ml; logf("This is a test"); // works :) } Minor nitpick: This isn't clear in the docs of std.logger. Throughout sharedLog is referred to as the "default" logger, not stdThreadLocalLog. Other than that I'm finding std.logger is really easy to use, nice work Phobosians! bye, lobo
Mar 28 2015
On Sunday, 29 March 2015 at 01:36:24 UTC, lobo wrote:Hi, I'm trying to use std.experimental.logger and I'd like the logf(), tracef() style functions to log to a file and stdout. (note: I can use sharedLog.logf(), sharedLog.tracef(), but I prefer just logf()) So I did this: shared static this() { auto ml = new MultiLogger(); ml.insertLogger("stdout", new FileLogger(std.stdio.stdout)); ml.insertLogger("applog", new FileLogger("applog.txt")); sharedLog = ml; logf("This is a test"); // Doesn't work } Which doesn't work, so I'm wondering if it's possible to do what I want. thanks, lobojust add the line stdThreadLocalLog.logLevel = LogLevel.info before logf and it should work. The default LogLevel of the MultiLogger and FileLogger is high than the default LogLevel of stdThreadLocalLog. (I will fix that)
Mar 29 2015
On Sunday, 29 March 2015 at 12:37:23 UTC, Robert burner Schadek wrote:On Sunday, 29 March 2015 at 01:36:24 UTC, lobo wrote:Thank you, lobo.Hi, I'm trying to use std.experimental.logger and I'd like the logf(), tracef() style functions to log to a file and stdout. (note: I can use sharedLog.logf(), sharedLog.tracef(), but I prefer just logf()) So I did this: shared static this() { auto ml = new MultiLogger(); ml.insertLogger("stdout", new FileLogger(std.stdio.stdout)); ml.insertLogger("applog", new FileLogger("applog.txt")); sharedLog = ml; logf("This is a test"); // Doesn't work } Which doesn't work, so I'm wondering if it's possible to do what I want. thanks, lobojust add the line stdThreadLocalLog.logLevel = LogLevel.info before logf and it should work. The default LogLevel of the MultiLogger and FileLogger is high than the default LogLevel of stdThreadLocalLog. (I will fix that)
Mar 29 2015
On Monday, 30 March 2015 at 04:05:12 UTC, lobo wrote:Thank you, lobo.next version will have equal default LogLevel for all Logger. https://github.com/D-Programming-Language/phobos/pull/3124
Mar 30 2015