On Fri, Apr 10, 2009 at 09:20:46AM -0700, Andrei Alexandrescu wrote:
> If anyone has ideas and/or code to contribute, that would be great.

I never understood why they should be complicated. Couldn't you just do
something like (pseudocodeish):

======

enum LogLevel { Verbose, Warning, Error }

FILE* logStream;
LogLevel currentLevel

// We need to open the log file ahead of time; this might be from command
// line args in a real program.
static this() {
        logStream = stderr; // or fopen("log", "wt"); or whatever
        currentLevel = LogLevel.Verbose;
}

static ~this() {
        fclose(logStream);
}

void log(LogLevel message, formatted message...) {
        if( currentLevel >= message) {
                logStream.writef("%s: ", currentTime() );
                logStream.writefln(formatted message....);
        }
}

void fun() {
        log(LogLevel.Verbose, "Entering function %s", __FUNCTION__);
        if ( crap )
                log(LogLevel.Error, "Crap happened!"
}

=======


Does it really need to be much more complex than that?


> 
> Andrei

-- 
Adam D. Ruppe
http://arsdnet.net

Reply via email to