1

I just started using log4j2. I am using it for multiple JVMs that use RMI. I have two problems.

  1. I start up the rmiregistry as it's own executable using the same CLASSPATH as the application. It starts without any errors, but once an RMI client talks to it, rmiregistry outputs this error: ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath... But the log4j-core jar file is already in the CLASSPATH and if there was a problem, then why does the application not output this error as well?

  2. I am using the RollingFile appender with OnStartupTriggeringPolicy and SizeBasedTriggeringPolicy. In theory at startup I should get logs like:

foo.log - active log
foo.log.1 - old log rolled if I already started it before
foo.log.2 - older log rolled if I already started it more than once

But instead when I start it the first time, it rolls a bunch of times, even though the size limit has not been reached and the active log is one that should have been rolled. In other words, I get this:

foo.log
foo.log.1
foo.log.2
foo.log.3 - active log
foo.log.4

Config file (log4j2.xml) contents:

    <?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
    <!-- ********** APPENDERS *********** -->

    <Appenders>
        <Console name="CONSOLE" target="SYSTEM_OUT">
            <PatternLayout pattern="%d (%-4r) [%t] %-5p %c %x - %m%n"/>
        </Console>
        <RollingFile
            name="FOO_OUT"
            fileName="/foo/log/foo.log"
            filePattern="/foo/log/foo.log.%i"
            append="true">

            <PatternLayout>
                <Pattern>%d (%-4r) [%t] %-5p %c %x - %m%n</Pattern>
            </PatternLayout>

            <DefaultRolloverStrategy max="24" fileIndex="min"/>
                <Policies>
                    <OnStartupTriggeringPolicy />
                    <SizeBasedTriggeringPolicy size="10 MB"/>
                </Policies>
        </RollingFile>
    </Appenders>
    <Loggers>
        <asyncLogger name="au.com" level="DEBUG">
            <AppenderRef ref="FOO_OUT"/>
        </asyncLogger>

        <asyncRoot level="debug">
            <AppenderRef ref="FOO_OUT"/>
        </asyncRoot>
    </Loggers>
</Configuration>

The CLASSPATH includes a lot of jars, but main ones related to lo4j2 are:

/foo/lib/slf4j/slf4j-api-1.7.21.jar
/foo/lib/slf4j/jcl-over-slf4j-1.7.21.jar
/foo/lib/slf4j/log4j-slf4j-impl-2.5.jar
/foo/lib/log4j2/log4j-core-2.5.jar
/foo/lib/log4j2/log4j-api-2.5.jar
/foo/lib/log4j2/disruptor-3.3.4.jar
  • Are all your JVMs using the same configuration? Are they all logging to /foo/log/foo.log and trying to roll to /foo/log/ScoreQueueReader.log.%i? Can you change status="warn" to status="debug" so it is obvious when rollover is occurring? – rgoers May 13 '16 at 05:46
  • Yes, the same classpath is used. Sorry, I made mistake in my sample config file; I meant /foo/log/foo.log and rolling to /foo/log/foo.log.%i . And I will attach output from rmiregistry when it's status="trace". I am thinking at this point, that log4j2 was not designed to work for rmiregistry and hence there are strange errors. – Mr. Mundkowsky May 16 '16 at 21:23
  • too hard to figure out how to get Stackoverflow to take a log. Anyways, only notable things from status="trace" for rmiregistry are: "DEBUG Stopped LoggerContext[name=70dea4e, org.apache.logging.log4j.core.LoggerContext@145f66e3]...: arithmetic syntax error", but this is after "DEBUG Stopped XmlConfiguration[location=/foo/config/log4j2.xml] OK". – Mr. Mundkowsky May 16 '16 at 21:40
  • I would suggest you create a Jira issue with log4j so you can attach your configuration and logs – rgoers May 19 '16 at 13:29

0 Answers0