Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    #16
    I am trying to upgrade to 5.1 and when calling:
    Code:
    public static org.apache.log4j.Logger getLogger(Class c) {
            return ((Logger) com.isomorphic.util.DataTools.getLoggerRepository()).getLogger(c.getName());
        }
    As you suggested I get:
    Code:
    Caused by: java.lang.ClassCastException: org.apache.log4j.Hierarchy cannot be cast to org.apache.log4j.Logger
        at de.mks_infofabrik.kids.server.Utils.getLogger(Utils.java:249)
        at de.mks_infofabrik.kids.server.Utils.<clinit>(Utils.java:60)
        ... 20 more
    What am I doing wrong? How to get the logger with 5.1 ?

    Comment


      #17
      Originally posted by Isomorphic View Post
      Just FYI.

      Since 10.0 we added documented API to get log4j LoggerRepository (Hierarchy class is deprecated) configured from log4j.isc.config.xml file. Code below demonstrates how it should be used taking your class as an example:
      Code:
      private static final org.apache.log4j.Logger LOG = com.isomorphic.util.DataTools.getLoggerRepository().getLogger(SessionDMIHandler.class.getName());
      This will be available in nightly builds from tomorrow (2014-10-07).
      This is not working. I tried with:
      Code:
      public static org.apache.log4j.Logger getLogger(Class c) {
              return ((org.apache.log4j.Logger) com.isomorphic.util.DataTools.getLoggerRepository()).getLogger(c.getName());
          }
      And the same. So what is the correct way to get the logger with 5.1 ?

      Comment


        #18
        Ok, the correct way is:

        Code:
        public static org.apache.log4j.Logger getLogger(Class c) {
                return ((org.apache.log4j.Hierarchy) com.isomorphic.util.DataTools.getLoggerRepository()).getLogger(c.getName());
            }

        Comment


          #19
          Correct, although considering that Hierarchy is deprecated, the proper cast would be to LoggerRepository as described in the latest server docs:
          Code:
          public static org.apache.log4j.Logger getLogger(Class c) {
              return ([b](org.apache.log4j.spi.LoggerRepository)[/b] com.isomorphic.util.DataTools.getLoggerRepository()).getLogger(c.getName());
          }
          Note that sample code without casting was correct for the time it was posted (late 2014) and in fact is still correct for version 5.0.

          Comment

          Working...
          X