Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Reason for no lazy log parameters?

Moderators: kris

Posted: 01/05/09 18:10:57

According to the API docs:

"The above will be handled implicitly by the logging system when macros are added to the language (used to be handled implicitly via lazy delegates, but usage of those turned out to be awkward)."

Why is this the case? I'm probably missing something obvious so I wanted to post here before filing a ticket, but this works just fine for me with both the latest GDC 1.x and DMD 1.037:

module lazy_log;

import tango.io.Stdout,
       tango.util.log.Log,
       tango.util.log.AppendConsole;

static Logger log;

void trace(R ...)(char[] a, lazy R r) {
    if (log.enabled(Logger.Level.Info))
        log.trace(a, r);
}

void main() {
    log = Log.root;
    log.add(new AppendConsole);
    log.level = Logger.Level.Warn;

    // No "blah"
    trace("{} {} {}", Stdout("blah").newline, 1, 2);

    log.level = Logger.Level.Trace;

    // Yes "blah"
    trace("{} {} {}", Stdout("blah").newline, 1, 2);
}

There are no responses to display.