java - main ERROR Unable to locate appender "test" for logger config "test" -
this log4j2 json config
{ "configuration": { "appenders": { "console": { "patternlayout": { "pattern": "%d{yyyy-mmm-dd hh:mm:ss a} [%t] %-5level %logger{36} - %msg%n" }, "name": "console", "target": "system_out" }, "rollingfile": { "name": "general", "filename": "c:/logs/simulator-log.log", "filepattern": "c:/logs/simulator-log-%d{yyyy-mm-dd hh-mm-ss}.log", "patternlayout": { "pattern": "%msg%n" }, "policies": { "onstartuptriggeringpolicy": { } } }, "file": { "patternlayout": { "pattern":"%msg%n" }, "name": "test", "filename": "c:/logs/requests_received.log" }, "file": { "patternlayout": { "pattern":"%msg%n" }, "name": "test1", "filename": "c:/logs/response_sent.log" } }, "loggers": { "root": { "appenderref": [ { "ref": "console" } ], "level": "trace" }, "logger": [ { "name": "test", "level": "trace", "additivity":"false", "appenderref": { "ref": "test" } }, { "name": "test1", "level": "trace", "additivity":"false", "appenderref": { "ref": "test1" } }, { "name": "general", "level": "trace", "additivity":"false", "appenderref": { "ref": "general" } } ] } }
}
when use 1 file appenders works fine. when use 2 file appenders getting error mention in title.cant add more 1 file appenders. dont want use rolling file appender.
please ignore "it looks post code; please add more details. more details want? think have conveyed everything. else want me add. let people @ issue."
java code creating logger variables
private static final logger requestsreceived = logmanager.getlogger("test"); private static final logger responsesent = logmanager.getlogger("test1"); private static final logger logger = logmanager.getlogger("general");
try define appenders using type
attribute below -
{ "type": "file", "patternlayout": { "pattern": "%msg%n" }, "name": "test", "filename": "c:/logs/requests_received.log" }, { "type": "file", "patternlayout": { "pattern": "%msg%n" }, "name": "test1", "filename": "c:/logs/response_sent.log" }
for this, have modify appender configuration using type
attribute. complete configuration file change below -
{ "configuration": { "appenders": { "appender": [ { "type": "console", "patternlayout": { "pattern": "%d{yyyy-mmm-dd hh:mm:ss a} [%t] %-5level %logger{36} - %msg%n" }, "name": "console", "target": "system_out" }, { "type": "rollingfile", "name": "general", "filename": "c:/logs/simulator-log.log", "filepattern": "c:/logs/simulator-log-%d{yyyy-mm-dd hh-mm-ss}.log", "patternlayout": { "pattern": "%msg%n" }, "policies": { "onstartuptriggeringpolicy": { } } }, { "type": "file", "patternlayout": { "pattern": "%msg%n" }, "name": "test", "filename": "c:/logs/requests_received.log" }, { "type": "file", "patternlayout": { "pattern": "%msg%n" }, "name": "test1", "filename": "c:/logs/response_sent.log" } ] }, "loggers": { "root": { "appenderref": [ { "ref": "console" } ], "level": "trace" }, "logger": [ { "name": "test", "level": "trace", "additivity": "false", "appenderref": { "ref": "test" } }, { "name": "test1", "level": "trace", "additivity": "false", "appenderref": { "ref": "test1" } }, { "name": "general", "level": "trace", "additivity": "false", "appenderref": { "ref": "general" } } ] } } }
Comments
Post a Comment