Voting: std.logger

Kevin Lamonte via Digitalmars-d digitalmars-d at puremagic.com
Tue Sep 2 20:05:41 PDT 2014


On Tuesday, 2 September 2014 at 14:53:17 UTC, Dicebot wrote:
> This is exactly what I call theoretical speculations. Please 
> provide specific list like this:
>
> 1) some method signature needs to be changed

I propose the following API changes (+ changes on default 
implementation):

     protected LogEntry beginLogMsg(string file, int line, string 
funcName,
         string prettyFuncName, string moduleName, LogLevel 
logLevel,
         Tid threadId, SysTime timestamp, Logger logger)
         @trusted
     {
         static if (isLoggingActive())
         {
             return LogEntry(file, line, funcName, prettyFuncName,
                 moduleName, logLevel, threadId, timestamp, null, 
logger);
         }
     }

     /** Logs a part of the log message. */
     protected void logMsgPart(MsgRange msgAppender, const(char)[] 
msg)
     {
         static if (isLoggingActive())
         {
             msgAppender.put(msg);
         }
     }

     /** Signals that the message has been written and no more 
calls to
     $(D logMsgPart) follow. */
     protected void finishLogMsg(ref LogEntry entry, MsgRange 
msgAppender)
     {
         static if (isLoggingActive())
         {
             entry.msg = msgAppender.data;
             this.writeLogMsg(entry);
         }
     }

...with the corresponding changes to logImpl/logImplf to create 
msgAppender as a local function variable, and the elimination of 
header and msgAppender as Logger class variables.

The benefit to this change is that Logger (including stdlog) 
becomes thread-safe, as well as any subclass of Logger that only 
implements writeLogMsg().


More information about the Digitalmars-d mailing list