digitalmars.D.learn - Logging best practices
- Vladimirs Nordholm (5/5) Apr 25 2019 Hello.
- dangbinghoo (7/12) Apr 25 2019 for the latest alpha version of D release, all std.experimental
- Bastiaan Veelo (9/21) Apr 26 2019 Are you sure about that?
- dangbinghoo (3/12) Apr 26 2019 yes, you're right, I just made a misunderstanding.
- Bastiaan Veelo (7/12) Apr 26 2019 Apart from an open issue I have,
- Andre Pany (9/14) Apr 27 2019 I also use it for all of my applications. But I really miss a
- Arun Chandrasekaran (27/42) Apr 29 2019 std.experimenetal.logger is very limited with the feature set it
- mw (3/6) May 30 2020 Also is any file logger thread safe?
- mw (5/10) May 30 2020 A related question: how to log to multiple destinations? e.g.
- Andre Pany (5/18) May 30 2020 Please have a look at the unittest in line 108 here
- Luis (87/90) May 31 2020 ```D
Hello. Is there a current "Best Practices" for logging in D? For the actual logging, I know of `std.experimental.logger`. However, the `experimental` has kept me away from it. Is it good, or are there any better alternatives?
Apr 25 2019
On Thursday, 25 April 2019 at 10:33:00 UTC, Vladimirs Nordholm wrote:Hello. Is there a current "Best Practices" for logging in D? For the actual logging, I know of `std.experimental.logger`. However, the `experimental` has kept me away from it. Is it good, or are there any better alternatives?for the latest alpha version of D release, all std.experimental has been already moved to std. so, just don't be afraid! ~_^ ----- binghoo dang
Apr 25 2019
On Thursday, 25 April 2019 at 15:51:43 UTC, dangbinghoo wrote:On Thursday, 25 April 2019 at 10:33:00 UTC, Vladimirs Nordholm wrote:Are you sure about that? https://github.com/dlang/phobos/tree/master/std I think you are confusing the package std.experimental.all that moved to std. It means you can now import all of Phobos by doing `import std;` instead of `import std.experimental.all;`. It does not mean that everything below std.experimental moved to std and thereby lost its experimental status. Bastiaan.Hello. Is there a current "Best Practices" for logging in D? For the actual logging, I know of `std.experimental.logger`. However, the `experimental` has kept me away from it. Is it good, or are there any better alternatives?for the latest alpha version of D release, all std.experimental has been already moved to std.
Apr 26 2019
On Friday, 26 April 2019 at 08:10:33 UTC, Bastiaan Veelo wrote:yes, you're right, I just made a misunderstanding. Thanks!std.experimental has been already moved to std.Are you sure about that? https://github.com/dlang/phobos/tree/master/std I think you are confusing the package std.experimental.all that moved to std. It means you can now import all of Phobos by doing `import std;` instead of `import std.experimental.all;`. It does not mean that everything below std.experimental moved to std and thereby lost its experimental status. Bastiaan.
Apr 26 2019
On Thursday, 25 April 2019 at 10:33:00 UTC, Vladimirs Nordholm wrote:Hello. Is there a current "Best Practices" for logging in D? For the actual logging, I know of `std.experimental.logger`. However, the `experimental` has kept me away from it. Is it good, or are there any better alternatives?Apart from an open issue I have, https://issues.dlang.org/show_bug.cgi?id=15536, I have used std.experimental.logger successfully here: https://github.com/PhilippeSigaud/Pegged/wiki/Grammar-Debugging Bastiaan.
Apr 26 2019
On Thursday, 25 April 2019 at 10:33:00 UTC, Vladimirs Nordholm wrote:Hello. Is there a current "Best Practices" for logging in D? For the actual logging, I know of `std.experimental.logger`. However, the `experimental` has kept me away from it. Is it good, or are there any better alternatives?I also use it for all of my applications. But I really miss a RotatedTimeFileLogger. One big log file which will grow and grow is not that usuable in cloud environment. Also I haven't found out wheter it is safe / how to write from different threads to the same log file. Kind regards Andre
Apr 27 2019
On Sat, Apr 27, 2019 at 2:55 AM Andre Pany via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> wrote:On Thursday, 25 April 2019 at 10:33:00 UTC, Vladimirs Nordholm wrote:std.experimenetal.logger is very limited with the feature set it offers. You can't set custom log patterns, etc. If you use AWS (docker), you could log to stdout and let the cloudwatch do all the magic. Based on a config parameter, you can enable/disable logging to a file. module my.logger; import std.experimental.logger; __gshared MultiLogger log; private __gshared FileLogger fileLog; private __gshared FileLogger onScreen; shared static this() { import std.file; import std.stdio : stdout, File; auto file = File("LMS.log", "a"); fileLog = new FileLogger(file); onScreen = new FileLogger(stdout); log = new MultiLogger(); if (cfg.logToFile) log.insertLogger("file", fileLog); log.insertLogger("stdout", onScreen); }Hello. Is there a current "Best Practices" for logging in D? For the actual logging, I know of `std.experimental.logger`. However, the `experimental` has kept me away from it. Is it good, or are there any better alternatives?I also use it for all of my applications. But I really miss a RotatedTimeFileLogger. One big log file which will grow and grow is not that usuable in cloud environment.Also I haven't found out wheter it is safe / how to write from different threads to the same log file.std.experimental.logger is perfectly thread safe. However printing the logging thread ID is still pending with this PR https://github.com/dlang/phobos/pull/6978
Apr 29 2019
On Monday, 29 April 2019 at 16:02:25 UTC, Arun Chandrasekaran wrote:std.experimental.logger is perfectly thread safe. However printing the logging thread ID is still pending with this PR https://github.com/dlang/phobos/pull/6978Also is any file logger thread safe?
May 30 2020
On Thursday, 25 April 2019 at 10:33:00 UTC, Vladimirs Nordholm wrote:Hello. Is there a current "Best Practices" for logging in D? For the actual logging, I know of `std.experimental.logger`. However, the `experimental` has kept me away from it. Is it good, or are there any better alternatives?A related question: how to log to multiple destinations? e.g. both console & log file? any examples? Thanks.
May 30 2020
On Saturday, 30 May 2020 at 18:17:21 UTC, mw wrote:On Thursday, 25 April 2019 at 10:33:00 UTC, Vladimirs Nordholm wrote:Please have a look at the unittest in line 108 here https://www.github.com/dlang/phobos/tree/384d0427936fc8846b633ac08e212e5107c37d16/std%2Fexperimental%2Flogger%2Fmultilogger.d Kind regards AndreHello. Is there a current "Best Practices" for logging in D? For the actual logging, I know of `std.experimental.logger`. However, the `experimental` has kept me away from it. Is it good, or are there any better alternatives?A related question: how to log to multiple destinations? e.g. both console & log file? any examples? Thanks.
May 30 2020
On Saturday, 30 May 2020 at 18:17:21 UTC, mw wrote:A related question: how to log to multiple destinations? e.g. both console & log file? any examples? Thanks.```D auto multiLogger = new MultiLogger(); multiLogger.insertLogger("console", new FileLogger(stdout, LogLevel.all)); multiLogger.insertLogger("file", new FileLogger(outputFile, LogLevel.all)); sharedLog = multiLogger; ``` If you are missing color output for log level , you can use this ConsoleLogger ```D import std.experimental.logger; /// Extends FileLogger to log only to stdout and colorize log level class ConsoleLogger : FileLogger { import std.concurrency : Tid; import std.datetime.systime : SysTime; import std.format : formattedWrite; this(const LogLevel lv = LogLevel.all) { import std.stdio : stdout; super(stdout, lv); } /* This method overrides the base class method in order to log to a file without requiring heap allocated memory. Additionally, the `FileLogger` local mutex is logged to serialize the log calls. */ override protected void beginLogMsg(string file, int line, string funcName, string prettyFuncName, string moduleName, LogLevel logLevel, Tid threadId, SysTime timestamp, Logger logger) safe { import std.string : lastIndexOf; ptrdiff_t fnIdx = file.lastIndexOf('/') + 1; ptrdiff_t funIdx = funcName.lastIndexOf('.') + 1; auto lt = this.file_.lockingTextWriter(); systimeToISOString(lt, timestamp); colorizeLogLevel(lt, logLevel); formattedWrite(lt, " %s:%u:%s ", file[fnIdx .. $], line, funcName[funIdx .. $]); } private void colorizeLogLevel(Writer)(auto ref Writer lt, LogLevel logLevel) safe { import std.conv : to; auto logLevelStr = logLevel.to!string; switch (logLevel) { case LogLevel.all: formattedWrite(lt, " [\033[1;37;40m%s\033[0m] ", logLevelStr); break; case LogLevel.trace: formattedWrite(lt, " [\033[1;37;40m%s\033[0m] ", logLevelStr); break; case LogLevel.info: formattedWrite(lt, " [\033[1;32;40m%s\033[0m] ", logLevelStr); break; case LogLevel.warning: formattedWrite(lt, " [\033[1;33;40m%s\033[0m] ", logLevelStr); break; case LogLevel.error: formattedWrite(lt, " [\033[1;31;40m%s\033[0m] ", logLevelStr); break; case LogLevel.critical: formattedWrite(lt, " [\033[1;37;41m%s\033[0m]", logLevelStr); break; case LogLevel.fatal: formattedWrite(lt, " [\033[1;25;37;41m%s\033[0m] ", logLevelStr); break; default: formattedWrite(lt, " [\033[1;37;40m%s\033[0m] ", logLevelStr); } } } ```
May 31 2020
On Sunday, 31 May 2020 at 07:49:01 UTC, Luis wrote:On Saturday, 30 May 2020 at 18:17:21 UTC, mw wrote:Thanks. For the colored console logger, I'm using this one: https://code.dlang.org/packages/colored-logger so far so good. (I prefer to use library, instead of reinvent my own wheels :-).A related question: how to log to multiple destinations? e.g. both console & log file? any examples? Thanks.```D auto multiLogger = new MultiLogger(); multiLogger.insertLogger("console", new FileLogger(stdout, LogLevel.all)); multiLogger.insertLogger("file", new FileLogger(outputFile, LogLevel.all)); sharedLog = multiLogger; ``` If you are missing color output for log level , you can use this ConsoleLogger
May 31 2020
On Sunday, 31 May 2020 at 20:04:11 UTC, mw wrote:Thanks. For the colored console logger, I'm using this one: https://code.dlang.org/packages/colored-logger so far so good. (I prefer to use library, instead of reinvent my own wheels :-).I dind't know that exists. 👍
May 31 2020