Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-625

Serialization error with SocketAppender and Asynch Logger

    XMLWordPrintableJSON

Details

    • Question
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0-rc1
    • 2.0-rc2
    • Appenders
    • None
    • Ubuntu 12.04, Java 7

    Description

      I'm testing a simple SocketAppender, which works fine until I switch to asynchronous loggers. Once I turn on async logging, I get:

      2014-04-29 21:17:26,029 ERROR Serialization of LogEvent failed. java.io.NotSerializableException: org.apache.logging.log4j.core.Logger$PrivateConfig
      at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1183)
      at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1547)
      at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1508)
      at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1431)
      at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1177)
      at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1547)
      at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1508)
      at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1431)
      at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1177)
      at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:347)
      at org.apache.logging.log4j.core.layout.SerializedLayout.toByteArray(SerializedLayout.java:64)
      at org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender.append(AbstractOutputStreamAppender.java:118)
      at org.apache.logging.log4j.core.config.AppenderControl.callAppender(AppenderControl.java:97)
      at org.apache.logging.log4j.core.config.LoggerConfig.callAppenders(LoggerConfig.java:425)
      at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:406)
      at org.apache.logging.log4j.core.Logger$PrivateConfig.logEvent(Logger.java:275)
      at org.apache.logging.log4j.core.async.AsyncLogger.actualAsyncLog(AsyncLogger.java:289)
      at org.apache.logging.log4j.core.async.RingBufferLogEvent.execute(RingBufferLogEvent.java:99)
      at org.apache.logging.log4j.core.async.RingBufferLogEventHandler.onEvent(RingBufferLogEventHandler.java:43)
      at org.apache.logging.log4j.core.async.RingBufferLogEventHandler.onEvent(RingBufferLogEventHandler.java:28)
      at com.lmax.disruptor.BatchEventProcessor.run(BatchEventProcessor.java:128)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      at java.lang.Thread.run(Thread.java:744)

      My client is configured with:

      <?xml version="1.0" encoding="UTF-8"?>
      <Configuration status="INFO">
      <Appenders>
      <Console name="MyConsole" target="SYSTEM_OUT">
      <PatternLayout pattern="%d

      {HH:mm:ss.SSS} {EST} %5level %msg%n"/>
      </Console>
      <Socket name="MySocket" host="localhost" port="8888">
      <SerializedLayout />
      </Socket>
      </Appenders>
      <Loggers>
      <Root level="INFO">
      <AppenderRef ref="MyConsole"/>
      <AppenderRef ref="MySocket"/>
      </Root>
      </Loggers>
      </Configuration>

      My server is configured with:

      <?xml version="1.0" encoding="UTF-8"?>
      <Configuration status="INFO">
      <Appenders>
      <Console name="MyConsole" target="SYSTEM_OUT">
      <PatternLayout pattern="%d{HH:mm:ss.SSS}{EST}

      %5level %msg%n"/>
      </Console>
      </Appenders>
      <Loggers>
      <Root level="INFO">
      <AppenderRef ref="MyConsole"/>
      </Root>
      </Loggers>
      </Configuration>

      The client just does a LogManager.getLogger().info("{}", "hello").

      The server just creates a SocketServer:
      SocketServer server = new SocketServer(8888);
      server.run();

      All works fine until I add this into the client:
      System.setProperty("Log4jContextSelector", "org.apache.logging.log4j.core.async.AsyncLoggerContextSelector");

      Am I missing something? Please advise.

      Thanks

      Attachments

        Activity

          People

            rpopma Remko Popma
            bhsueh Bryan Hsueh
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: