std.experimental.logger default log level is everything

Mathias LANG geod24 at gmail.com
Mon May 31 00:42:50 UTC 2021


On Friday, 28 May 2021 at 17:29:48 UTC, Steven Schveighoffer 
wrote:
> [...]
>
> IMO, the default level should be either `off` (no logging) or 
> `fatal`. I shouldn't see trace messages without opting in to 
> logging.

Expectations vary depending on the developer. I, for one, would 
expect `Info` to be the default level, but would be surprised if 
I wrote code and it did nothing by default.

> It makes std.experimental.logger unusable inside a public 
> library, or else I have to stick it behind a special dub 
> configuration to enable it.
>
> Thoughts?
>
> -Steve

I think what makes `std.experimental.logger` unusable inside a 
public library is the lack of hierarchy. Tango had loggers that 
were object and hierarchical.
Ocean has them too: 
https://github.com/sociomantic-tsunami/ocean/blob/v6.x.x/src/ocean/util/log/Logger.d

We use them a lot in our app, e.g. having `this.log = 
Log.lookup(__MODULE__);` in the class' ctor. They can be 
configured to output to stdout, file(s), or any other output 
(e.g. Ocean has syslog support). In our unit tests, we save all 
log output to a circular buffer, which we print if an assert is 
triggered, this way we don't clutter the output of the run, but 
still provide detailed informations on (possibly spurious) 
failure.

They can also be configured: 
https://github.com/bosagora/agora/blob/2809791954133da4c352d612d7347ee667e65312/doc/config.example.yaml#L172-L222
In our server app, we even have a control interface (bound to 
localhost) which allow us to dynamically reconfigure them. E.g. 
there was a bug recently, I just SSH into the machine and run 
`curl -X POST 
'127.0.0.1:3000/admin/logger?name=root&level=Trace&console=true'` 
(https://github.com/bosagora/agora/blob/2809791954133da4c352d612d7347ee667e65312/source/agora/api/Admin.d#L36-L42) and voila, everything is being logged out.

Oh, and you can set a buffer that is to be used, so they don't 
keep on allocating.


More information about the Digitalmars-d mailing list