I am trying to configure chronicle logger to work with diffusion and the logs do not work. Instead it just gives the following error:
2016-08-26 15:56:26,316 main ERROR appenders contains an invalid element or attribute "appender"
2016-08-26 15:56:26,329 main ERROR Unable to locate appender "STDOUT" for logger config “root"
This is the configuration that causes this error:
<?xml version="1.0" encoding="UTF-8"?>
<configuration packages="net.openhft.chronicle.logger,net.openhft.chronicle.logger.log4j2">
<appenders>
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n" />
</layout>
</appender>
</appenders>
<loggers>
<root level="all">
<appender-ref ref="STDOUT"/>
</root>
<logger name="net.openhft" level="warn"/>
</loggers>
</configuration>
I copied this config from a separate project where it works so it should work. What am I doing wrong?
Thanks in advance.
You have copied the appender
element from a project that uses log4j
but diffusion uses log4j2
which does not support this element.
For it to work you can replace your config with something like this:
<?xml version="1.0" encoding="UTF-8"?>
<configuration packages="net.openhft.chronicle.logger,net.openhft.chronicle.logger.log4j2">
<Properties>
<Property name="diffusion.log.dir">../logs</Property>
<Property name="log.dir">${sd:diffusion.log.dir}</Property>
<Property name="pattern">%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
</Property>
</Properties>
<appenders>
<Console name="console">
<PatternLayout pattern="$%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n" />
</Console>
</appenders>
<loggers>
<AsyncRoot level="warn" includeLocation="false">
<AppenderRef ref="console" />
</AsyncRoot>
</loggers>
</configuration>
It is worth noting that you have only configured console logging and nothing will be written to a log file which means that if something happens to your server it would be very easy to lose your log history. For this reason I recommend that you also log to a file.
The default log4j2.xml supplied with Diffusion uses the RollingRandomAccessFile
appender to write to a file and refers to that appenender in the AsyncRoot
element.