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.
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
Du musst angemeldet sein, um einen Kommentar abzugeben.
Schritte zu machen, Tomcat Arbeit mit log4j
Wir laden Sie zwei Dateien aus extras auf tomcat-download-Bereich
tomcat-juli.jar tomcat-juli-adapters.jar
$CATALINA_HOME\lib
Danach starten Sie tomcat neu.
$CATALINA_HOME\libs und $CATALINA_HOME\lib verwendet werden. Ist es ein Tippfehler? libs vs lib?
Bitte auch klären, was gemeint ist mit "Download log4j version größer als 1,2 und kopieren nach $CATALINA_HOME\lib" Die Datei? ls -1 apache-log4j-2.0.2-bin/ log4j-1.2-api-2.0.2.jar log4j-api-2.0.2.jar log4j-core-2.0.2.jar log4j-core-2.0.2-tests.jar log4j-flume-ng-2.0.2.jar log4j-jcl-2.0.2.jar log4j-jmx-gui-2.0.2.jar log4j-nosql-2.0.2.jar log4j-slf4j-impl-2.0.2.jar log4j-taglib-2.0.2.jar log4j-to-slf4j-2.0.2.jar log4j-web-2.0.2.jar
Ich meine download-version log4j-1.2.17.jar. Wenn ich schrieb diesen guide log4j 2 noch in der beta
InformationsquelleAutor phamthaithinh
versuchen, fügen Sie diese zu Ihrem tomcat launcher in eclipse als JVM-Parameter
Es löst das problem nicht
InformationsquelleAutor Abderrazak BOUADMA
@Julia Haben Sie überprüfen Sie Ihre $CATALINA_BASE/conf/logging.Eigenschaften-Datei? Möglicherweise müssen Sie löschen Sie es aus dem TOMCAT-Ordner.
Follow-up für meine Antwort:
Ich denke, dass Ihr log4j.Eigenschaften-Konfiguration korrekt ist. Der nächste Schritt wäre die überprüfung, in welchem der aktuelle Pfad der log-Konfiguration, die geladen wird. Hinzufügen
-Dlog4j.debug
zu IhremJAVA_OPTS
imTOMCAT
. Auf diese Weise können Sie überprüfen, wie die log4j ist instanziiert und es wird sich zeigen, was log4j-Eigenschaften geladen wurde. Dann versuchen Sie, überprüfen Sie Informationen aus dem tomcat-log-Dateiencatalina.out
odercatalina.2013-11-06.log
Hab ich bereits gemacht. Bitte Lesen Sie sich meine Frage gezielt.
InformationsquelleAutor archetype