Log4J does not write anything

I just put together an existing web application at work that should log my activity with Log4J. I set up my workspace exactly as I was told, and everything else (db connection, authentication, etc.) works fine, except that nothing is written to the log file. Other similar applications do not have logging problems.

I looked at the WebSphere console when starting the application and there are no errors that can indicate why Log4J is not logging.

I mentioned this to another developer (who once worked on this application, but not for some time and is more outdated than I did on it), who noticed that this was a very strange behavior, but had no idea why he may not log or report any errors.

I looked at the configuration file and the properties file, and everything looks fine. I suspect Log4J does not even read log4j.xml, but I am not sure about that. It's been a while since I worked with Log4J - does anyone have any good tips to fix this problem?

PS: There are instances of this application that are deployed on different test / QA / prod servers, and these instances are all logged in order. It is only on local workstations that journaling seems to fail.


Update: . So it looks like the problem is with how the application is being deployed. I changed the classloader mode to "Parent Last" and I see that the Log4J file is at least now being read. And the first action that I am trying starts ClassNotFoundExceptionis saying that org.apache.commons.logging.impl.Log4jFactoryit cannot be found.


: - ... WAR - - , - -. , , . - - , ClassNotFoundException. commons-logging.jar, JavaEE, ( "" ).

, ( JAR), , , , .

( org.apache.commons.logging.LogFactory META-INF/services , : "org.apache.commons.logging.impl.Log4jFactory" ) : Websphere SystemOut.log, , , .

+5
5

, , , , , "PARENT_FIRST" WAR classloader "". "PARENT_FIRST" / "Module". "PARENT_LAST" / "" , , , , , . , "PARENT_FIRST" / "", .


UPDATE:

, . , "PARENT_FIRST" / "" org.apache.commons.logging.LogFactory META-INF/ , : "org.apache.commons.logging.impl.Log4jFactory", ( , Log4J ).

+2

: log4j?

-Dlog4j.debug

+7

, , log4j, ( , ) Commons Logging. , /.

0

, logback.xml spring webservice websphere... log4j.properties, . log4j slf4j.. logback.xml file

<file>C:/abc/myLogFile.log</file>
<append>true</append>
<encoder>
  <pattern>%d [%thread] %-5level %logger{35} - %msg%n</pattern>
</encoder></appender>

     `

:

<dependency>
    <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
      <version>${slf4j.version}</version>
    </dependency>
    <dependency>
      <groupId>ch.qos.logback</groupId>
      <artifactId>logback-classic</artifactId>
      <version>${logback.version}</version>
    </dependency>
    <dependency>
      <groupId>ch.qos.logback</groupId>
      <artifactId>logback-core</artifactId>
      <version>${logback.version}</version>
    </dependency>
0

I had a problem when log4j didn't show anything in one of my projects. It turned out that I added the starting space to the class name in the log4j2.xml file. Log4j searches for a dictionary by class name. Thus, any start or end space in the class name will invalidate this particular entry.

0
source

All Articles