Log4j 2
  1. Log4j 2
  2. LOG4J2-410

java.io.NotSerializableException: org.slf4j.impl.SLF4JLogger

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0-beta8
    • Fix Version/s: 2.0-rc2
    • Component/s: None
    • Labels:
      None

      Description

      When i use a the logger object in a model,and the model will set to some cache like memcached,this exception happens.Maybe this class and some other related class need implements Serializable interface?

        Activity

        Hide
        Gary Gregory added a comment -

        org.slf4j.impl.SLF4JLogger is not a Log4j class, it's a SLF4J class.

        What is your stack trace?

        Show
        Gary Gregory added a comment - org.slf4j.impl.SLF4JLogger is not a Log4j class, it's a SLF4J class. What is your stack trace?
        Hide
        lvlin zeng added a comment - - edited

        jdk version:1.7
        memcached client:spymemcached 2.6

        i use the Log4j2 with slf4j interface,which depends on the log4j-slf4j-impl-2.0-beta8.jar,and i put the logger into the EmpBaseInfo model,here is a snippet of this code:

        import org.slf4j.Logger;
        import org.slf4j.LoggerFactory;
        ..........................
        public class EmpBaseInfo implements Serializable

        { private final long serialVersionUID = -5413579595663647712L; private final Logger logger = LoggerFactory.getLogger(EmpBaseInfo.class); private Integer id; ................. }

        Stack trace:
        Caused by: java.io.NotSerializableException: org.slf4j.impl.SLF4JLogger
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1180) ~[?:1.7.0_17]
        at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1528) ~[?:1.7.0_17]
        at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1493) ~[?:1.7.0_17]
        at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416) ~[?:1.7.0_17]
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174) ~[?:1.7.0_17]
        at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:346) ~[?:1.7.0_17]
        at java.util.concurrent.ConcurrentHashMap.writeObject(ConcurrentHashMap.java:1519) ~[?:1.7.0_17]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_17]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[?:1.7.0_17]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.7.0_17]
        at java.lang.reflect.Method.invoke(Method.java:601) ~[?:1.7.0_17]
        at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:975) ~[?:1.7.0_17]
        at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1480) ~[?:1.7.0_17]
        at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416) ~[?:1.7.0_17]
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174) ~[?:1.7.0_17]
        at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1528) ~[?:1.7.0_17]
        at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1493) ~[?:1.7.0_17]
        at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416) ~[?:1.7.0_17]
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174) ~[?:1.7.0_17]
        at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1528) ~[?:1.7.0_17]
        at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1493) ~[?:1.7.0_17]
        at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416) ~[?:1.7.0_17]
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174) ~[?:1.7.0_17]
        at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1528) ~[?:1.7.0_17]
        at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1493) ~[?:1.7.0_17]
        at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416) ~[?:1.7.0_17]
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174) ~[?:1.7.0_17]
        at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1528) ~[?:1.7.0_17]
        at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1493) ~[?:1.7.0_17]
        at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416) ~[?:1.7.0_17]
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174) ~[?:1.7.0_17]
        at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1528) ~[?:1.7.0_17]
        at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1493) ~[?:1.7.0_17]
        at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416) ~[?:1.7.0_17]
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174) ~[?:1.7.0_17]
        at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1528) ~[?:1.7.0_17]
        at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1493) ~[?:1.7.0_17]
        at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416) ~[?:1.7.0_17]
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174) ~[?:1.7.0_17]
        at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1528) ~[?:1.7.0_17]
        at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1493) ~[?:1.7.0_17]
        at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416) ~[?:1.7.0_17]
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174) ~[?:1.7.0_17]
        at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:346) ~[?:1.7.0_17]
        at net.spy.memcached.transcoders.BaseSerializingTranscoder.serialize(BaseSerializingTranscoder.java:81) ~[spymemcached-2.6.jar:]
        ... 96 more

        Show
        lvlin zeng added a comment - - edited jdk version:1.7 memcached client:spymemcached 2.6 i use the Log4j2 with slf4j interface,which depends on the log4j-slf4j-impl-2.0-beta8.jar,and i put the logger into the EmpBaseInfo model,here is a snippet of this code: import org.slf4j.Logger; import org.slf4j.LoggerFactory; .......................... public class EmpBaseInfo implements Serializable { private final long serialVersionUID = -5413579595663647712L; private final Logger logger = LoggerFactory.getLogger(EmpBaseInfo.class); private Integer id; ................. } Stack trace: Caused by: java.io.NotSerializableException: org.slf4j.impl.SLF4JLogger at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1180) ~ [?:1.7.0_17] at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1528) ~ [?:1.7.0_17] at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1493) ~ [?:1.7.0_17] at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416) ~ [?:1.7.0_17] at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174) ~ [?:1.7.0_17] at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:346) ~ [?:1.7.0_17] at java.util.concurrent.ConcurrentHashMap.writeObject(ConcurrentHashMap.java:1519) ~ [?:1.7.0_17] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~ [?:1.7.0_17] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~ [?:1.7.0_17] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~ [?:1.7.0_17] at java.lang.reflect.Method.invoke(Method.java:601) ~ [?:1.7.0_17] at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:975) ~ [?:1.7.0_17] at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1480) ~ [?:1.7.0_17] at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416) ~ [?:1.7.0_17] at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174) ~ [?:1.7.0_17] at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1528) ~ [?:1.7.0_17] at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1493) ~ [?:1.7.0_17] at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416) ~ [?:1.7.0_17] at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174) ~ [?:1.7.0_17] at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1528) ~ [?:1.7.0_17] at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1493) ~ [?:1.7.0_17] at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416) ~ [?:1.7.0_17] at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174) ~ [?:1.7.0_17] at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1528) ~ [?:1.7.0_17] at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1493) ~ [?:1.7.0_17] at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416) ~ [?:1.7.0_17] at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174) ~ [?:1.7.0_17] at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1528) ~ [?:1.7.0_17] at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1493) ~ [?:1.7.0_17] at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416) ~ [?:1.7.0_17] at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174) ~ [?:1.7.0_17] at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1528) ~ [?:1.7.0_17] at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1493) ~ [?:1.7.0_17] at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416) ~ [?:1.7.0_17] at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174) ~ [?:1.7.0_17] at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1528) ~ [?:1.7.0_17] at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1493) ~ [?:1.7.0_17] at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416) ~ [?:1.7.0_17] at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174) ~ [?:1.7.0_17] at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1528) ~ [?:1.7.0_17] at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1493) ~ [?:1.7.0_17] at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416) ~ [?:1.7.0_17] at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174) ~ [?:1.7.0_17] at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:346) ~ [?:1.7.0_17] at net.spy.memcached.transcoders.BaseSerializingTranscoder.serialize(BaseSerializingTranscoder.java:81) ~ [spymemcached-2.6.jar:] ... 96 more
        Hide
        Ralph Goers added a comment -

        I recommend you declare the Logger as transient. Loggers are not Serialable.

        Show
        Ralph Goers added a comment - I recommend you declare the Logger as transient. Loggers are not Serialable.
        Hide
        Ralph Goers added a comment -

        Actually, looking at Logback I see that Logger is Serializable there so this should be as well.

        Show
        Ralph Goers added a comment - Actually, looking at Logback I see that Logger is Serializable there so this should be as well.
        Hide
        lvlin zeng added a comment -

        so i think the Logger and some other related classes should be serializable,when i use log4j1.x,no exception happens,if some people migrate the log4j from 1.x to 2.x ,they need to change some codes^_^

        Show
        lvlin zeng added a comment - so i think the Logger and some other related classes should be serializable,when i use log4j1.x,no exception happens,if some people migrate the log4j from 1.x to 2.x ,they need to change some codes^_^
        Hide
        lvlin zeng added a comment -

        i made some changes in org.slf4j.impl.SLF4JLogger,declare transient to the members,and no exception happens:

        private static final String FQCN = SLF4JLogger.class.getName();
        private static final transient Marker EVENT_MARKER = MarkerFactory.getMarker("EVENT");
        private final boolean eventLogger;
        private final transient AbstractLoggerWrapper logger;
        private final String name;
        private final transient EventDataConverter converter;

        Show
        lvlin zeng added a comment - i made some changes in org.slf4j.impl.SLF4JLogger,declare transient to the members,and no exception happens: private static final String FQCN = SLF4JLogger.class.getName(); private static final transient Marker EVENT_MARKER = MarkerFactory.getMarker("EVENT"); private final boolean eventLogger; private final transient AbstractLoggerWrapper logger; private final String name; private final transient EventDataConverter converter;
        Hide
        Nick Williams added a comment -

        Should we take some action on this before RC1?

        Show
        Nick Williams added a comment - Should we take some action on this before RC1?
        Hide
        Ralph Goers added a comment -

        I don't consider it a blocker but it should be a high priority.

        Show
        Ralph Goers added a comment - I don't consider it a blocker but it should be a high priority.
        Hide
        Ralph Goers added a comment -

        Fixed in revision 1572998. Please verify and close.

        Show
        Ralph Goers added a comment - Fixed in revision 1572998. Please verify and close.

          People

          • Assignee:
            Ralph Goers
            Reporter:
            lvlin zeng
          • Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development