Hi,

I want to write log entries to stdout in JSON format. Therefore I created a customer logger. Unfortunatelly there are 2 errors with following implementation:

module logger;

import std.experimental.logger;
import std.stdio: stdout;

class MyCustomLogger : Logger
{
    private FileLogger _stdOutLogger;

    this(LogLevel lv = LogLevel.all) @safe
    {
        super(lv);
        _stdOutLogger = new FileLogger(stdout);
    }

    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);
                }
    }
}

static this()
{
        stdThreadLocalLog = new MyCustomLogger();
}

source\logger.d(13,34): Error: safe function 'this' cannot access __gshared data 'stdout'

source\logger.d(20,22): Error: safe function 'logger.MyCustomLogger.writeLogMsg' cannot call system function 'std.experimental.logger.core.Logger.logf!(20, "source\\logger.d", "logger.MyCustomLogger.writeLogMsg", "void logger.MyCustomLogger...


Also the example for creating an user defined logger is wrong:
http://dlang.org/phobos-prerelease/std_experimental_logger.html
There is a compilation error regarding variable newName in super.
newName seems not to be expected here.

Kind regards
André


Reply via email to