Log4j-Konfiguration funktioniert nicht auf Tomcat

Ich habe ein problem mit log4j-Konfiguration.

Bevor Maven-Pakete, die meine Anwendung im Krieg-Datei, es führt tests. Und die log4j-Konfiguration geladen und verwendet werden, - log-Datei wird erstellt, und die Nachrichten werden geschrieben und in der Konsole.

Es ist log4j-debug-Ausgabe in der Konsole:

log4j: Trying to find [log4j.xml] using context classloader sun.misc.Launcher$AppClassLoader@422ede.
log4j: Trying to find [log4j.xml] using sun.misc.Launcher$AppClassLoader@422ede class loader.
log4j: Trying to find [log4j.xml] using ClassLoader.getSystemResource().
log4j: Trying to find [log4j.properties] using context classloader sun.misc.Launcher$AppClassLoader@422ede.
log4j: Using URL [file:/C:/dev/workspace/paymentsystemsstub/target/classes/log4j.properties] for automatic log4j configuration.
log4j: Reading configuration from URL file:/C:/dev/workspace/paymentsystemsstub/target/classes/log4j.properties
log4j: Parsing for [root] with value=[WARN, file, stdout].
log4j: Level token is [WARN].
log4j: Category root set to WARN
log4j: Parsing appender named "file".
log4j: Parsing layout options for "file".
log4j: Setting property [conversionPattern] to [%d{dd MMM yyyy HH:mm:ss,SSS} [%c] [%-5p] %n%m%n].
log4j: End of parsing for "file".
log4j: Setting property [file] to [C:\tomcat\log/paymentSystemsStub.log].
log4j: Setting property [maxBackupIndex] to [1].
log4j: Setting property [maxFileSize] to [1MB].
log4j: setFile called: C:\tomcat\log/paymentSystemsStub.log, true
log4j: setFile ended
log4j: Parsed "file" options.
log4j: Parsing appender named "stdout".
log4j: Parsing layout options for "stdout".
log4j: Setting property [conversionPattern] to [%d{HH:mm:ss,SSS} [%c] [%-5p] %n%m%n].
log4j: End of parsing for "stdout".
log4j: Parsed "stdout" options.
log4j: Parsing for [com.panbet.paymentstub] with value=[DEBUG].
log4j: Level token is [DEBUG].
log4j: Category com.panbet.paymentstub set to DEBUG
log4j: Handling log4j.additivity.com.panbet.paymentstub=[null]
log4j: Finished configuring.

Aber wenn ich bereitstellen generierte war-Datei im Tomcat, sehe ich, dass die log4j-Konfiguration geladen und die log-Datei erstellt wird, aber Nachrichten werden nicht geschrieben oder in der Konsole:

Es ist log4j-debug-Ausgabe:

log4j: Trying to find [log4j.xml] using context classloader WebappClassLoader
  context: /paymentstub
  delegate: false
  repositories:
    /WEB-INF/classes/
----------> Parent Classloader:
org.apache.catalina.loader.StandardClassLoader@d1ad08
.
log4j: Trying to find [log4j.xml] using WebappClassLoader
  context: /paymentstub
  delegate: false
  repositories:
    /WEB-INF/classes/
----------> Parent Classloader:
org.apache.catalina.loader.StandardClassLoader@d1ad08
 class loader.
log4j: Trying to find [log4j.xml] using ClassLoader.getSystemResource().
log4j: Trying to find [log4j.properties] using context classloader WebappClassLoader
  context: /paymentstub
  delegate: false
  repositories:
    /WEB-INF/classes/
----------> Parent Classloader:
org.apache.catalina.loader.StandardClassLoader@d1ad08
.
log4j: Using URL [file:/C:/tomcat/webapps/paymentstub/WEB-INF/classes/log4j.properties] for automatic log4j configuration.
log4j: Reading configuration from URL file:/C:/tomcat/webapps/paymentstub/WEB-INF/classes/log4j.properties
log4j: Parsing for [root] with value=[WARN, file, stdout].
log4j: Level token is [WARN].
log4j: Category root set to WARN
log4j: Parsing appender named "file".
log4j: Parsing layout options for "file".
log4j: Setting property [conversionPattern] to [%d{dd MMM yyyy HH:mm:ss,SSS} [%c] [%-5p] %n%m%n].
log4j: End of parsing for "file".
log4j: Setting property [file] to [C:\tomcat\log/paymentSystemsStub.log].
log4j: Setting property [maxBackupIndex] to [1].
log4j: Setting property [maxFileSize] to [1MB].
log4j: setFile called: C:\tomcat\log/paymentSystemsStub.log, true
log4j: setFile ended
log4j: Parsed "file" options.
log4j: Parsing appender named "stdout".
log4j: Parsing layout options for "stdout".
log4j: Setting property [conversionPattern] to [%d{HH:mm:ss,SSS} [%c] [%-5p] %n%m%n].
log4j: End of parsing for "stdout".
log4j: Parsed "stdout" options.
log4j: Parsing for [com.panbet.paymentstub] with value=[DEBUG].
log4j: Level token is [DEBUG].
log4j: Category com.panbet.paymentstub set to DEBUG
log4j: Handling log4j.additivity.com.panbet.paymentstub=[null]
log4j: Finished configuring.

Dateien log4j.properties im Ordner WEB-INF\classes und log4j-1.2.17.jar im Ordner WEB-INF\lib (aus hier und hier Sie es sein sollte).

Gebe ich einen absoluten Pfad, wo um die Protokolldatei zu erstellen, wie eine JVM-Eigenschaft.

Es ist mein log4j.properties Datei:

# Set root logger level to WARN and its appenders to file and stdout
log4j.rootLogger=WARN, file, stdout

# stdout is set to be a ConsoleAppender
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
# stdout uses PatternLayout
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{HH:mm:ss,SSS} [%c] [%-5p] %n%m%n

# file is set to be a RollingFileAppender
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=${stubLog}/paymentSystemsStub.log
log4j.appender.file.MaxFileSize=1MB
# Keep one backup file
log4j.appender.file.MaxBackupIndex=1
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{dd MMM yyyy HH:mm:ss,SSS} [%c] [%-5p] %n%m%n

# Print only messages of level DEBUG or above in the package com.panbet.paymentstub
log4j.logger.com.panbet.paymentstub=DEBUG

Ich bin mit Windows 7, Eclipse, Tomcat 7, Maven und Log4j 1.2.

Verbringe ich den ganzen Tag versucht, herauszufinden, was falsch ist und noch keine Ahnung haben.

Update

Ich bin so verwirrt! Herausstellen, dass die Methoden, die ich aufgerufen, nicht melden, nichts! Ich war so sicher, dass Sie tun... Sorry für die Mühe.

Das ist etwas offtopic, aber warum log4j? Verwenden logback statt!
Denn es ist eine Voraussetzung. Ich muss verwenden es.
Haben Sie irgendwelche Ausnahmen in <TOMCAT_HOME>\logs\catalina.out?
Nein, ich glaube nicht
Dann sollte das funktionieren. Nur jede Möglichkeit ausschließen, wenn Sie sagen, dass keine Nachrichten aufgezeichnet wurden, müssen Sie auf die tatsächlich zugegriffen wird Ihre app so, dass zumindest ein paar Methoden, die log etwas bekommen wird aufgerufen, richtig?

InformationsquelleAutor Julia | 2013-11-14

Schreibe einen Kommentar