Bug 23323 – std.logger (previously experimental) needs better documentation

Status
NEW
Severity
enhancement
Priority
P4
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-09-04T14:10:25Z
Last change time
2024-12-01T16:40:21Z
Assigned to
No Owner
Creator
Andrej Mitrovic
Moved to GitHub: phobos#10499 →

Comments

Comment #0 by andrej.mitrovich — 2022-09-04T14:10:25Z
It took me quite a bit of time to realize why by default `log(string)` will do nothing at all. In fact I think the default is very counter-intuitive. Here's an example: ----- import std.experimental.logger; void main (){ log("Hello?"); logf(LogLevel.info, "%s", "test 1"); logf(LogLevel.error, "%s", "test 2"); log(LogLevel.info, "test 3"); } ----- The first line will not be emitted to stdout or stderr, or anywhere for that matter. The user is supposed to explicitly set the logging level. But it's not even obvious for which logger they're supposed to do that. The actual solution is: ----- import std.experimental.logger; void main (){ stdThreadLocalLog().logLevel = LogLevel.info; log("Now this works"); } ----- I lost a fair bit of time digging through phobos sources to understand what's going on. I think we should at least document that you have to do this to get any kind of output to stdout/stderr when calling 'log()'.
Comment #1 by robert.schadek — 2024-12-01T16:40:21Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/10499 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB