On 08/01/2014 05:56 AM, Martin Nowak wrote:
On 07/30/2014 01:09 AM, Robert burner Schadek wrote:

I'm not sure how you except log(LogLevel.xxxx, "Hello world") to be
disabled at compile time if LogLevel.xxxx is a runtime value? Or do I
misunderstood you?

you can choose to disable name based logging like trace("Hello trace")
at CT with the current release

Here is a proof of concept to achieve this.
http://dpaste.dzfl.pl/95fb6a4e086d
It works by creating a different type for each loglevel.

Just checked tested this.

    static struct TestLogger
    {
        enum minLogLevel = LogLevel.error;
        void write(in LogEntry e) { _entries ~= e; }

        const(LogEntry)[] _entries;
    }

    void main()
    {
        TestLogger logger;
        logger.log(LogLevel.debug_, "foobar");
    }


The call logger.log(LogLevel.debug_) can be completely removed by the compiler. The delegates for the lazy parameters are still generated though. Either fixing [`--gc-sections`](https://issues.dlang.org/show_bug.cgi?id=879) or adding [LTO](https://github.com/ldc-developers/ldc/issues/693) would help. Also dmd (but not LDC) has a [bug](https://issues.dlang.org/show_bug.cgi?id=8615) where it still adds a few instructions to pass the delegate (even though the function is never called).

So I think it's an appropriate solution to the problem.
http://dpaste.dzfl.pl/95fb6a4e086d

Reply via email to