Log4J2 Konfiguration in servlet 3.0

Ich versuchte die Einrichtung LOG4J-Dokumentation nach (und Verwandte Fragen), aber es nicht schaffen, soll die Datei, aber es ist so log in WildFly:

No Log4j context configuration provided. This is very unusual

web.xml

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
       version="3.0">

<context-param>
      <param-name>log4jConfigLocation</param-name>
     <param-value>/WEB-INF/classes/log4j2.xml</param-value>
</context-param>

app.war/WEB-INF/classes/log4j2.xml

<?xml version="1.0" encoding="UTF-8"?>
<Configuration monitorInterval="30">
    <!-- http://logging.apache.org/log4j/2.x/manual/configuration.html -->
    <Properties>
        <Property name="filename">c:/oauth.log</Property>
    </Properties>

    <Filter type="ThresholdFilter" level="trace"/>

    <Appenders>
        <Appender type="File" name="File" fileName="${filename}">
            <Layout type="PatternLayout">
                <Pattern>%d %p %C{1.} [%t] %m%n</Pattern>
            </Layout>
        </Appender>
        <File name="MyFile" fileName="c:/oauth2.log" immediateFlush="true">
            <PatternLayout pattern="%d{yyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
        </File>
    </Appenders>

    <Loggers>
        <Logger name="cz.literak.demo" level="debug" additivity="true">
            <AppenderRef ref="File"/>
        </Logger>
        <Root level="error">
            <AppenderRef ref="MyFile"/>
        </Root>
    </Loggers>

</Configuration>

app.war/WEB-INF/lib

commons-logging-1.1.3.jar
json-smart-1.1.1.jar
log4j-api-2.0-rc1.jar
log4j-core-2.0-rc1.jar
log4j-jcl-2.0-rc1.jar

Könnten Sie mir sagen, was falsch ist? Ich habe versucht, Kommentar context-param in web.xml und verlassen Sie sich auf Autokonfiguration, aber es gibt keine änderung.

BEARBEITEN

wenn ich folgenden code Hinzugefügt

<context-param>
    <param-name>log4jContextName</param-name>
    <param-value>oauthDemo</param-value>
</context-param>

scheiterte es anders (ich habe nicht Zeit, zu untersuchen, jetzt)

07:41:29,269 INFO  [io.undertow.servlet] (MSC service thread 1-12) Log4jServletContainerInitializer starting up Log4j in Servlet 3.0+ environment.
07:41:29,644 INFO  [stdout] (MSC service thread 1-12) 2014-02-20 07:41:29,643 ERROR FileManager (c:/oauth2.log) java.io.FileNotFoundException: c:\oauth2.log (Přístup byl odepřen)
07:41:29,646 INFO  [stdout] (MSC service thread 1-12) 2014-02-20 07:41:29,645 ERROR Unable to invoke method createAppender in class org.apache.logging.log4j.core.appender.FileAppender for element File 07:41:29,647 INFO    [stdout] (MSC service thread 1-12)    at org.apache.logging.log4j.core.config.BaseConfiguration.createPluginObject(BaseConfiguration.java:913)
  • Verwenden Sie die richtige context-param. Es sollte log4jConfiguration statt log4jConfigLocation. Siehe logging.apache.org/log4j/2.x/manual/webapp.html#Servlet-3.0.
  • log4jConfiguration: Unable to access /WEB-INF/classes/log4j2.xml java.lang.IllegalArgumentException: URI ist nicht absolut. log4jConfigLocation in der Lage ist zu Lesen, config von innerhalb Krieg. Wenn ich geänderte Protokoll Standort, es konnte nicht mit einige syntax-Fehler.
  • Ich versuchte, völlig verlassen sich auf automatische Konfiguration, damit ich auskommentiert LOG4J Sachen in web.xml. Die Konfiguration funktioniert, aber die Warnung immer noch angezeigt "Keine Log4j Kontext-Konfiguration zur Verfügung gestellt. Das ist sehr ungewöhnlich" 🙁
InformationsquelleAutor Leos Literak | 2014-02-20
Schreibe einen Kommentar