Log4j2.xml configuration in web.xml. IllegalArgumentException - uri is not absolute

Before adding the parameter context and Log4jConfigListener for Log4j2me, I had all the logs listed in the catalina.out file .

So now I am trying to configure log4jfor my web application.

In I added the necessary configuration. web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 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_2_5.xsd">
    <display-name>etl-service</display-name>

    <!-- Support for Spring -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath*:applicationContext.xml</param-value>
    </context-param>

    <context-param>
        <param-name>spring.profiles.active</param-name>
        <param-value>myprofile</param-value>
    </context-param>

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

    <listener>
        <listener-class>
            org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>

    <listener>
        <listener-class>
            org.springframework.web.util.Log4jConfigListener
        </listener-class>
    </listener>


</web-app>

log4j2.xml

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="trace" strict="true" name="XMLConfigTest"
               packages="">         

    <Appenders>
        <Console name="Console" target="SYSTEM_OUT">
            <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
        </Console>

        <RollingRandomAccessFile name="RollingRandomAccessFileDebug" fileName="/local/deploy/logs/debug.log"
                                 filePattern="logs/$${date:yyyy-MM}/etl-%d{MM-dd-yyyy}-%i.log.gz"
                                 immediateFlush="false"
                                 append="false">
            <PatternLayout>
                <Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
            </PatternLayout>
            <Policies>
                <TimeBasedTriggeringPolicy/>
                <SizeBasedTriggeringPolicy size="250 MB"/>
            </Policies>
        </RollingRandomAccessFile>
        <RollingRandomAccessFile name="RollingRandomAccessFile" fileName="/local/deploy/logs/info.log"
                                 filePattern="logs/$${date:yyyy-MM}/etl-%d{MM-dd-yyyy}-%i.log.gz"
                                 immediateFlush="false"
                                 append="false">
            <PatternLayout>
                <Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
            </PatternLayout>
            <Policies>
                <TimeBasedTriggeringPolicy/>
                <SizeBasedTriggeringPolicy size="250 MB"/>
            </Policies>
        </RollingRandomAccessFile>
        <!--<Async name="AsyncConsole">-->
        <!--<AppenderRef ref="Console"/>-->
        <!--</Async>-->
    </Appenders>
    <Loggers>
        <Root  level="TRACE">
            <AppenderRef ref="RollingRandomAccessFileDebug" level="DEBUG"/>
            <AppenderRef ref="RollingRandomAccessFile" level="INFO"/>
            <AppenderRef ref="Console"  level="TRACE"/>
        </Root>
    </Loggers>
</Configuration>

But at the moment I have the following error:

ERROR Unable to access WEB-INF/classes/log4j2.xml java.lang.IllegalArgumentException: URI is not absolute

Perhaps someone has already encountered such a problem. Also I tried instead of adding /WEB-INF/classes/log4j.xmluseclasspath*:log4j.xml

And had a mistake java.net.URISyntaxException: Illegal character in schema name at 9 index: classpath*:log4j.xml

UPDATE: We only need to add the descriptor file name, and it works.

<context-param>
            <param-name>log4jConfiguration</param-name>
            <param-value>log4j2.xml</param-value>
        </context-param>

, catalina.out. log4j.

+4
3

Spring Servler.

Spring 4.2.1 Log4jConfigListener .

, Spring 4.2.1 (+), Servlet 3.0 (+) Log4j2. , , :

  • log4j-web,
  • a) log4j2.xml WEB-INF b) log4j2 log4jConfiguration context web.xml .

, - .

​​ Log4j2, .

+6

, log4j - log4j 2.xml, log4j.xml . , , 2.5, log4j .

, log4j. -Dlog4j.configurationFile, log4j2.xml. debug -Dorg.apache.logging.log4j.simplelog.StatusLogger.level=debug

tomcat, ${catalina.home}/bin/setenv.sh( .bat, ) JAVA_OPTS.

log4j , :

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

:

<listener>
    <listener-class>
        org.springframework.web.util.Log4jConfigListener
    </listener-class>
</listener>

Spring log4j 1.x, ( maven):

        <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>${log4j.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-api</artifactId>
        <version>${log4j.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-web</artifactId>
        <version>${log4j.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-1.2-api</artifactId>
        <version>${log4j.version}</version>
    </dependency>

log4j-1.2-api - api, log4j-web - -.

0

. org.springframework.web.util.Log4jConfigListener. "log4jConfigLocation". , classpath, classpath:/logs/log4j2.xml. , ://Users/logs/log4j2.xml. , web.xml. :

<context-param>
        <param-name>log4jConfigLocation</param-name>
        <param-value>file://Users/logs/log4j2.xml</param-value>
 </context-param>

, spring Log4jConfigListener log4j 1.x.

0

Source: https://habr.com/ru/post/1528101/


All Articles