phobos icon indicating copy to clipboard operation
phobos copied to clipboard

log(str) is not work

Open dlangBugzillaToGithub opened this issue 2 years ago • 2 comments

1499874170 reported this on 2023-04-15T15:55:55Z

Transfered from https://issues.dlang.org/show_bug.cgi?id=23840

Description

For std/logger/package.d
The comments tell me:

The easiest way to create a log message is to write:
-------------
import std.logger;

void main() {
    log("Hello World");
}
-------------

But I created a test project:
(test.d)
import std.logger;
void main(string[] args)
{
    log("test");
}

It is not any output.

But if I change it:
(test.d)
import std.logger;
void main(string[] args)
{
    log(LogLevel.info, "test");
}

It is working.

dlangBugzillaToGithub avatar Apr 15 '23 15:04 dlangBugzillaToGithub

While the top example in the docs now recommends using info("test") instead of log("test") since #10582, this is still at the very least documented badly, if not implemented incorrectly.

The docs mention several times that without providing a loglevel, that it will use the default log level of the logger

log("Logging to the sharedLog with its default LogLevel");

what is the the default log level of the logger? It should be the value of logger.logLevel, right? But then calling log without providing a LogLevel should by definition always use the minimum acceptable loglevel.

Should the bug be made a feature and documented or should the behaviour be fixed in a "breaking" change? I'd consider the current useability bad enough and the severity of additional log entries mild enough to say it should just be made that log("test") should dispatch a message per default

Inkrementator avatar Feb 19 '25 19:02 Inkrementator

what is the the default log level of the logger? It should be the value of logger.logLevel, right?

That part is actually documented:
https://github.com/dlang/phobos/blob/b3aee4d3b4bc23e0d7639d61162b82dddd5223a5/std/logger/package.d#L61-L62

But then calling log without providing a LogLevel should by definition always use the minimum acceptable loglevel.

I like this idea, but I’m not sure whether the crowd agrees.

See also: https://issues.dlang.org/show_bug.cgi?id=22532

0xEAB avatar Feb 28 '25 02:02 0xEAB