std.experimental.logger formal review round 3
Martin Nowak via Digitalmars-d
digitalmars-d at puremagic.com
Wed Dec 3 14:09:13 PST 2014
On 10/30/2014 12:11 AM, Robert burner Schadek wrote:
> That can actually be added to the current state of std.logger without
> breaking any api. The string mixin, version string matching isn't really
> pretty, but it gets the job done. Anyway IMO your approach presented
> here and my approach can go hand in hang. Yours should be propagated as
> the idiomatic way and if you really need the crowbar, which you need
> sometimes, use StdLoggerDisableXXXXX.
I just found a very compelling solution to the LogLevel disabling problem.
Basically we can declare a logLevel for each module or package and let
the logger do a reverse look up.
```d
module mymod;
import logger;
// can be anything that converts to a LogLevel
// calls with lower log level can be optimized away if this is a compile
time constant
// runtime values also work nicely but incur a small overhead
// if this declaration is not present, logLevel from the package is used
or a default LogLevel.
enum logLevel = LogLevel.critical;
void foo()
{
info("information from foo"); // optimized out
fatal("error"); // works
}
```
https://gist.github.com/MartinNowak/443f11aa017d14007c35
There is a tiny gotcha, this works because the logger module imports the
callee module. So we'd need to avoid module constructors in the logger
module or use a workaround.
More information about the Digitalmars-d
mailing list