digitalmars.D.learn - std.logger issue
- o3o (22/22) Jan 26 2023 ```
- Krzysztof =?UTF-8?B?SmFqZcWbbmljYQ==?= (10/11) Jan 26 2023 Set `sharedLog.logLevel` instead of `globalLogLevel`.
- =?UTF-8?Q?Ali_=c3=87ehreli?= (22/27) Jan 26 2023 Good catch. I had tried the following without success:
- o3o (3/14) Jan 26 2023 Thank you very much Krzysztof, it works.
``` // rdmd --main -unitest app.d import std.stdio; import std.logger; unittest { globalLogLevel = LogLevel.all; infof("g: %s", globalLogLevel); trace("trace"); // NO output! info("info"); warning("warn"); error("error"); } ``` output is: ``` 2023-01-26T18:16:13.546 [info] log.d:6:main g: all 2023-01-26T18:16:13.546 [info] log.d:8:main info 2023-01-26T18:16:13.546 [warning] log.d:9:main warn 2023-01-26T18:16:13.546 [error] log.d:10:main error ``` how can I enable `trace` level? Thank
Jan 26 2023
On Thursday, 26 January 2023 at 17:17:28 UTC, o3o wrote:how can I enable `trace` level?Set `sharedLog.logLevel` instead of `globalLogLevel`. ```d // Note: the cast is needed because sharedLog is shared (cast()sharedLog).logLevel = LogLevel.all; ``` Explanation: logging functions (`trace`, `log`, etc.) called without a logger perform the logging using a global logger called `sharedLog`. `sharedLog` uses `LogLevel.info` by default, which is why your trace messages were not showing.
Jan 26 2023
On 1/26/23 12:08, Krzysztof Jajeśnica wrote:On Thursday, 26 January 2023 at 17:17:28 UTC, o3o wrote:Good catch. I had tried the following without success: stdThreadLocalLog.logLevel = LogLevel.all;how can I enable `trace` level?Set `sharedLog.logLevel` instead of `globalLogLevel`.// Note: the cast is needed because sharedLog is shared (cast()sharedLog).logLevel = LogLevel.all;I did not think casting that way would be the right thing to do. Although I've never used std.logger, and without remembering who implemented it (sincere aplogies), given how simple the use cases of logging are, I found its implementation very complicated. For example, the following function is one I stumbled upon while debugging the OP's issue: bool isLoggingEnabled()(LogLevel ll, LogLevel loggerLL, LogLevel globalLL, lazy bool condition = true) safe { return ll >= globalLL && ll >= loggerLL && ll != LogLevel.off && globalLL != LogLevel.off && loggerLL != LogLevel.off && condition; } I don't think it is possible to entagle usage issues with functions with that semantic complexity. Ali
Jan 26 2023
On Thursday, 26 January 2023 at 20:08:51 UTC, Krzysztof Jajeśnica wrote:On Thursday, 26 January 2023 at 17:17:28 UTC, o3o wrote:Thank you very much Krzysztof, it works.how can I enable `trace` level?Set `sharedLog.logLevel` instead of `globalLogLevel`. ```d // Note: the cast is needed because sharedLog is shared (cast()sharedLog).logLevel = LogLevel.all; ``` Explanation: logging functions (`trace`, `log`, etc.) called without a logger perform the logging using a global logger called `sharedLog`. `sharedLog` uses `LogLevel.info` by default, which is why your trace messages were not showing.
Jan 26 2023