experimental.logger: safe function and stdou

Andre via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Nov 18 23:15:18 PST 2015


On Thursday, 19 November 2015 at 06:27:58 UTC, Andre wrote:
>
>     override void writeLogMsg(ref LogEntry payload)
>     {
> 		with (payload)
> 		{
> 			_stdOutLogger.logf(logLevel, `{
> 				"file":"%s", "line":%s, "funcName":"%s", 
> "prettyFuncName":"%s",
> 				"moduleName":"%s", "logLevel":%s, "threadId":%s, 
> "timestamp":"%s", "msg":"%s"}`,
> 				file, line, funcName, prettyFuncName, moduleName, logLevel, 
> threadId, timestamp);
> 		}
>     }

I changed the implementation of writeLogMsg and attached the 
trusted attribute.
Is this a valid solution?

     override void writeLogMsg(ref LogEntry payload) @trusted
     {
		with (payload)
		{
			 writefln(`{"file":"%s", "line":%s, "funcName":"%s", 
"prettyFuncName":"%s",`~
					` "moduleName":"%s", "logLevel":%s, "threadId":%s, 
"timestamp":"%s", "msg":"%s"}`,
				file, line, funcName, prettyFuncName, moduleName, logLevel, 
threadId, timestamp, msg);
			stdout.flush();
		}
     }


More information about the Digitalmars-d-learn mailing list