Log4j2 json配置不写入文件

时间:2015-11-24 06:43:54

标签: java json logging log4j2

我在资源目录

下有这个log4j2.json文件
{
    "configuration": {
        "status": "TRACE",
        "name": "App",
        "monitorInterval": "300",
        "appenders": {
            "appender": [
                {
                    "type": "Console",
                    "name": "STDOUT",
                    "PatternLayout": {
                        "pattern": "%m%n"
                    }
                },
                {
                    "type": "RollingFile",
                    "name": "RollingFile",
                    "PatternLayout": {
                        "pattern": "%m%n"
                    },
                    "filename": "console.log",
                    "filePattern": "$${date:yyyy-MM}/console-%d{MM-dd-yyyy}-%i.log",
                    "TimeBasedTriggeringPolicy": {
                        "interval": 24,
                        "modulate": true
                    }
                },
                {
                    "type": "RollingFile",
                    "name": "text-roll",
                    "PatternLayout": {
                        "pattern": "%d %p %c{1.} [%t] %m %ex%n"
                    },
                    "filename": "info.log",
                    "filePattern": "$${date:yyyy-MM}/info-%d{MM-dd-yyyy}-%i.log",
                    "TimeBasedTriggeringPolicy": {
                        "interval": 24,
                        "modulate": true
                    }
                },
                {
                    "type": "RollingFile",
                    "name": "json-roll",
                    "JsonLayout": {
                        "complete": true,
                        "compact": true,
                        "eventEol": true
                    },
                    "filename": "json.log",
                    "filePattern": "$${date:yyyy-MM}/json-%d{MM-dd-yyyy}-%i.log",
                    "TimeBasedTriggeringPolicy": {
                        "interval": 24,
                        "modulate": true
                    }
                }
            ]
        },
        "loggers": {
            "logger": [
                {
                    "name":"Console Root",
                    "level": "debug",
                    "AppenderRef": {
                        "ref": "STDOUT"
                    }
                },
                {
                    "name":"Console Output",
                    "level": "trace",
                    "AppenderRef": {
                        "ref": "RollingFile"
                    }
                },
                {
                    "name":"Info",
                    "level": "info",
                    "AppenderRef": {
                        "ref": "text-roll"
                    }
                },
                {
                    "name":"Json",
                    "level": "error",
                    "AppenderRef": {
                        "ref": "json-roll"
                    }
                }
            ],
            "root": {
                "AppenderRef": {
                    "ref": "STDOUT"
                }
            }
        }
    }
}

虽然它确实创建了这些文件但从未写入任何内容。 在console.log中,info.log为空。但是json.log有这样的内容:

[

]

]

]

]

]

]

这是启动log4j初始化服务器后的控制台: Gist of the console output

1 个答案:

答案 0 :(得分:0)

我不确定,但是根据没有调试的唯一日志行,

Log4j appears to be running in a Servlet environment, but there's no log4j-web module available. If you want better web container support, please add the log4j-web JAR to your web archive or server lib directory.

那罐子在吗?