Wednesday, October 1, 2014

Oh my LOG!!!!

This is exactly my reaction owing to recent encounters with log4j2. I have had the privilege of facing multiple issues which I would like to share so that others can seek help from my experiences.

Scenario: Our application migrated from log4j2-beta9 jars to log4j2 GA version. Also SLF4J version changed from 1.7.5 to 1.7.7.

Issue#1: Log files not getting created in windows-weblogic environment
Root Cause: Windows does not recognize "\" in the path. It should either be escaped by using \\ (double back slash) or use a single forward slash. 
Solution: So after migration, we created a new JAVA OPTION where we changed the log directory by replacing all the back slashes with a forward slash, something like this:
                                 set LOG4J2_DIR_HOME=%MY_APP_PATH:\=/%

Issue#2: In case of a cluster setup, if the admin server and one of the nodes are pointing to the same installation, log files do not rotate in windows-weblogic environment
Root Cause: Log4J has a policy that if the log file size reaches a specified limit, then it is moved to another location and  the current file is emptied. But in case of a cluster set up, this was not happening. This is because, the admin server, which is one JVM and the node, which is another JVM, both of them point to the same log file. Though the admin server may or may not have anything to write to the log file, but it will still hold a lock on the file.
Solution: In our case, since Admin server did not have anything to write to log file, the file was never created. Only in case of a node, a log file was created.

Issue#3: ERROR StatusLogger Error parsing \config\properties\log4j2.xml javax.xml.parsers.ParserConfigurationException: Feature 'http://apache.org/xml/features/xincl
ude' is not recognized.ERROR StatusLogger Error parsing \config\properties\log4j2.xml javax.xml.parsers.ParserConfigurationException: Feature 'http://apache.org/xml/features/xincl
ude' is not recognized. error occurs on load.
Root Cause: Jar conflict, 2 jars of the same name, but different versions was present in the classpath
Solution: Removed the duplicate jars from the classpath. Usual conflicting jars would be; xmlApis.jar, xerces.jar, xercesImpl.jar

No comments: