0

尝试在我的 Jersey3 应用程序(在 tomcat 中运行)中使用 log4j2。我想通过我的 web.xml 加载配置,如下所示:

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
         version="4.0">

    <!-- ServletContextListeners -->
    <listener>
        <listener-class>com.something.AppContextListener</listener-class>
    </listener>
    
    <!-- Servlets -->
    <servlet>
       ...
    </servlet>

    <!-- Log4J -->
    <context-param>
        <param-name>log4jConfiguration</param-name>
        <param-value>classpath:config/log4j-dev.properties</param-value>
    </context-param>

    <!-- URL-Mapping -->
    <servlet-mapping>
        ...
    </servlet-mapping>

    <!-- Security Roles -->
    <security-role>
      ...
    </security-role>

    <!-- Login Config -->
    <login-config>
        ...
    </login-config>

    <!-- Security Constraints-->
    <security-constraint>
       ...
    </security-constraint>
</web-app>

配置文件本身,位于以下结构中:

src/main/resources/config/

在我的属性中,我定义了一个文件记录器:

log4j-dev.properties

status = warn
name= properties_configuration

property.basePath = ${sys:catalina.home}/logs/ogd_mdd/

# RollingFileAppender will print logs in file which can be rotated based on time or size
appender.rolling.type = RollingFile
appender.rolling.name = fileLogger
appender.rolling.fileName= ${basePath}app.log
appender.rolling.filePattern= ${basePath}app_%d{yyyyMMdd}.log.gz
appender.rolling.layout.type = PatternLayout
appender.rolling.layout.pattern = %d{yyyy-MM-dd HH:mm:ss.SSS} %level [%M] [%l] - %msg%n

# Configure root logger for logging error logs in classes which are in package other than above specified package
rootLogger.level = info
rootLogger.appenderRef.rolling.ref = fileLogger

pom.xml

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

我得到的只是错误级别的控制台日志(似乎加载了默认配置而不是我的)。我确定,我正确定义了配置,尽管在 web.xml 中犯了一个错误...我需要如何定义路径才能正确加载属性?

log4j 的调试日志

DEBUG StatusLogger Using ShutdownCallbackRegistry class org.apache.logging.log4j.core.util.DefaultShutdownCallbackRegistry
DEBUG StatusLogger Not in a ServletContext environment, thus not loading WebLookup plugin.
DEBUG StatusLogger AsyncLogger.ThreadNameStrategy=UNCACHED (user specified null, default is UNCACHED)
TRACE StatusLogger Using default SystemClock for timestamps.
DEBUG StatusLogger org.apache.logging.log4j.core.util.SystemClock supports precise timestamps.
DEBUG StatusLogger Not in a ServletContext environment, thus not loading WebLookup plugin.
DEBUG StatusLogger Took 0.163821 seconds to load 218 plugins from ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64

DEBUG StatusLogger PluginManager 'Converter' found 44 plugins
DEBUG StatusLogger Starting OutputStreamManager SYSTEM_OUT.false.false-1
DEBUG StatusLogger Starting LoggerContext[name=1fb9201c, org.apache.logging.log4j.core.LoggerContext@65b40e79]...
DEBUG StatusLogger Reconfiguration started for context[name=1fb9201c] at URI null (org.apache.logging.log4j.core.LoggerContext@65b40e79) with optional ClassLoader: null
DEBUG StatusLogger Not in a ServletContext environment, thus not loading WebLookup plugin.
DEBUG StatusLogger PluginManager 'ConfigurationFactory' found 4 plugins
DEBUG StatusLogger Not in a ServletContext environment, thus not loading WebLookup plugin.
DEBUG StatusLogger Not in a ServletContext environment, thus not loading WebLookup plugin.
DEBUG StatusLogger Missing dependencies for Yaml support, ConfigurationFactory org.apache.logging.log4j.core.config.yaml.YamlConfigurationFactory is inactive
DEBUG StatusLogger Not in a ServletContext environment, thus not loading WebLookup plugin.
DEBUG StatusLogger Not in a ServletContext environment, thus not loading WebLookup plugin.
DEBUG StatusLogger Using configurationFactory org.apache.logging.log4j.core.config.ConfigurationFactory$Factory@5d745e72
TRACE StatusLogger Trying to find [log4j2-test1fb9201c.properties] using context class loader ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
.
TRACE StatusLogger Trying to find [log4j2-test1fb9201c.properties] using ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
 class loader.
TRACE StatusLogger Trying to find [log4j2-test1fb9201c.properties] using ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
 class loader.
TRACE StatusLogger Trying to find [log4j2-test1fb9201c.properties] using ClassLoader.getSystemResource().
TRACE StatusLogger Trying to find [log4j2-test1fb9201c.yml] using context class loader ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
.
TRACE StatusLogger Trying to find [log4j2-test1fb9201c.yml] using ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
 class loader.
TRACE StatusLogger Trying to find [log4j2-test1fb9201c.yml] using ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
 class loader.
TRACE StatusLogger Trying to find [log4j2-test1fb9201c.yml] using ClassLoader.getSystemResource().
TRACE StatusLogger Trying to find [log4j2-test1fb9201c.yaml] using context class loader ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
.
TRACE StatusLogger Trying to find [log4j2-test1fb9201c.yaml] using ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
 class loader.
TRACE StatusLogger Trying to find [log4j2-test1fb9201c.yaml] using ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
 class loader.
TRACE StatusLogger Trying to find [log4j2-test1fb9201c.yaml] using ClassLoader.getSystemResource().
TRACE StatusLogger Trying to find [log4j2-test1fb9201c.json] using context class loader ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
.
TRACE StatusLogger Trying to find [log4j2-test1fb9201c.json] using ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
 class loader.
TRACE StatusLogger Trying to find [log4j2-test1fb9201c.json] using ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
 class loader.
TRACE StatusLogger Trying to find [log4j2-test1fb9201c.json] using ClassLoader.getSystemResource().
TRACE StatusLogger Trying to find [log4j2-test1fb9201c.jsn] using context class loader ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
.
TRACE StatusLogger Trying to find [log4j2-test1fb9201c.jsn] using ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
 class loader.
TRACE StatusLogger Trying to find [log4j2-test1fb9201c.jsn] using ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
 class loader.
TRACE StatusLogger Trying to find [log4j2-test1fb9201c.jsn] using ClassLoader.getSystemResource().
TRACE StatusLogger Trying to find [log4j2-test1fb9201c.xml] using context class loader ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
.
TRACE StatusLogger Trying to find [log4j2-test1fb9201c.xml] using ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
 class loader.
TRACE StatusLogger Trying to find [log4j2-test1fb9201c.xml] using ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
 class loader.
TRACE StatusLogger Trying to find [log4j2-test1fb9201c.xml] using ClassLoader.getSystemResource().
TRACE StatusLogger Trying to find [log4j2-test.properties] using context class loader ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
.
TRACE StatusLogger Trying to find [log4j2-test.properties] using ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
 class loader.
TRACE StatusLogger Trying to find [log4j2-test.properties] using ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
 class loader.
TRACE StatusLogger Trying to find [log4j2-test.properties] using ClassLoader.getSystemResource().
TRACE StatusLogger Trying to find [log4j2-test.yml] using context class loader ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
.
TRACE StatusLogger Trying to find [log4j2-test.yml] using ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
 class loader.
TRACE StatusLogger Trying to find [log4j2-test.yml] using ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
 class loader.
TRACE StatusLogger Trying to find [log4j2-test.yml] using ClassLoader.getSystemResource().
TRACE StatusLogger Trying to find [log4j2-test.yaml] using context class loader ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
.
TRACE StatusLogger Trying to find [log4j2-test.yaml] using ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
 class loader.
TRACE StatusLogger Trying to find [log4j2-test.yaml] using ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
 class loader.
TRACE StatusLogger Trying to find [log4j2-test.yaml] using ClassLoader.getSystemResource().
TRACE StatusLogger Trying to find [log4j2-test.json] using context class loader ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
.
TRACE StatusLogger Trying to find [log4j2-test.json] using ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
 class loader.
TRACE StatusLogger Trying to find [log4j2-test.json] using ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
 class loader.
TRACE StatusLogger Trying to find [log4j2-test.json] using ClassLoader.getSystemResource().
TRACE StatusLogger Trying to find [log4j2-test.jsn] using context class loader ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
.
TRACE StatusLogger Trying to find [log4j2-test.jsn] using ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
 class loader.
TRACE StatusLogger Trying to find [log4j2-test.jsn] using ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
 class loader.
TRACE StatusLogger Trying to find [log4j2-test.jsn] using ClassLoader.getSystemResource().
TRACE StatusLogger Trying to find [log4j2-test.xml] using context class loader ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
.
TRACE StatusLogger Trying to find [log4j2-test.xml] using ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
 class loader.
TRACE StatusLogger Trying to find [log4j2-test.xml] using ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
 class loader.
TRACE StatusLogger Trying to find [log4j2-test.xml] using ClassLoader.getSystemResource().
TRACE StatusLogger Trying to find [log4j21fb9201c.properties] using context class loader ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
.
TRACE StatusLogger Trying to find [log4j21fb9201c.properties] using ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
 class loader.
TRACE StatusLogger Trying to find [log4j21fb9201c.properties] using ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
 class loader.
TRACE StatusLogger Trying to find [log4j21fb9201c.properties] using ClassLoader.getSystemResource().
TRACE StatusLogger Trying to find [log4j21fb9201c.yml] using context class loader ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
.
TRACE StatusLogger Trying to find [log4j21fb9201c.yml] using ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
 class loader.
TRACE StatusLogger Trying to find [log4j21fb9201c.yml] using ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
 class loader.
TRACE StatusLogger Trying to find [log4j21fb9201c.yml] using ClassLoader.getSystemResource().
TRACE StatusLogger Trying to find [log4j21fb9201c.yaml] using context class loader ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
.
TRACE StatusLogger Trying to find [log4j21fb9201c.yaml] using ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
 class loader.
TRACE StatusLogger Trying to find [log4j21fb9201c.yaml] using ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
 class loader.
TRACE StatusLogger Trying to find [log4j21fb9201c.yaml] using ClassLoader.getSystemResource().
TRACE StatusLogger Trying to find [log4j21fb9201c.json] using context class loader ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
.
TRACE StatusLogger Trying to find [log4j21fb9201c.json] using ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
 class loader.
TRACE StatusLogger Trying to find [log4j21fb9201c.json] using ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
 class loader.
TRACE StatusLogger Trying to find [log4j21fb9201c.json] using ClassLoader.getSystemResource().
TRACE StatusLogger Trying to find [log4j21fb9201c.jsn] using context class loader ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
.
TRACE StatusLogger Trying to find [log4j21fb9201c.jsn] using ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
 class loader.
TRACE StatusLogger Trying to find [log4j21fb9201c.jsn] using ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
 class loader.
TRACE StatusLogger Trying to find [log4j21fb9201c.jsn] using ClassLoader.getSystemResource().
TRACE StatusLogger Trying to find [log4j21fb9201c.xml] using context class loader ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
.
TRACE StatusLogger Trying to find [log4j21fb9201c.xml] using ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
 class loader.
TRACE StatusLogger Trying to find [log4j21fb9201c.xml] using ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
 class loader.
TRACE StatusLogger Trying to find [log4j21fb9201c.xml] using ClassLoader.getSystemResource().
TRACE StatusLogger Trying to find [log4j2.properties] using context class loader ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
.
TRACE StatusLogger Trying to find [log4j2.properties] using ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
 class loader.
TRACE StatusLogger Trying to find [log4j2.properties] using ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
 class loader.
TRACE StatusLogger Trying to find [log4j2.properties] using ClassLoader.getSystemResource().
TRACE StatusLogger Trying to find [log4j2.yml] using context class loader ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
.
TRACE StatusLogger Trying to find [log4j2.yml] using ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
 class loader.
TRACE StatusLogger Trying to find [log4j2.yml] using ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
 class loader.
TRACE StatusLogger Trying to find [log4j2.yml] using ClassLoader.getSystemResource().
TRACE StatusLogger Trying to find [log4j2.yaml] using context class loader ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
.
TRACE StatusLogger Trying to find [log4j2.yaml] using ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
 class loader.
TRACE StatusLogger Trying to find [log4j2.yaml] using ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
 class loader.
TRACE StatusLogger Trying to find [log4j2.yaml] using ClassLoader.getSystemResource().
TRACE StatusLogger Trying to find [log4j2.json] using context class loader ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
.
TRACE StatusLogger Trying to find [log4j2.json] using ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
 class loader.
TRACE StatusLogger Trying to find [log4j2.json] using ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
 class loader.
TRACE StatusLogger Trying to find [log4j2.json] using ClassLoader.getSystemResource().
TRACE StatusLogger Trying to find [log4j2.jsn] using context class loader ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
.
TRACE StatusLogger Trying to find [log4j2.jsn] using ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
 class loader.
TRACE StatusLogger Trying to find [log4j2.jsn] using ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
 class loader.
TRACE StatusLogger Trying to find [log4j2.jsn] using ClassLoader.getSystemResource().
TRACE StatusLogger Trying to find [log4j2.xml] using context class loader ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
.
TRACE StatusLogger Trying to find [log4j2.xml] using ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
 class loader.
TRACE StatusLogger Trying to find [log4j2.xml] using ParallelWebappClassLoader
  context: ogd_mdd_backend_app
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@32d2fa64
 class loader.
TRACE StatusLogger Trying to find [log4j2.xml] using ClassLoader.getSystemResource().
WARN StatusLogger No Log4j 2 configuration file found. Using default configuration (logging only errors to the console), or user programmatically provided configurations. Set system property 'log4j2.debug' to show Log4j 2 internal initialization logging. See https://logging.apache.org/log4j/2.x/manual/configuration.html for instructions on how to configure Log4j 2
DEBUG StatusLogger Not in a ServletContext environment, thus not loading WebLookup plugin.
DEBUG StatusLogger PluginManager 'Converter' found 44 plugins
DEBUG StatusLogger Starting OutputStreamManager SYSTEM_OUT.false.false-2
DEBUG StatusLogger Apache Log4j Core 2.14.0 initializing configuration org.apache.logging.log4j.core.config.DefaultConfiguration@3d8505f8
DEBUG StatusLogger Installed 0 script engines
DEBUG StatusLogger PluginManager 'Core' found 123 plugins
DEBUG StatusLogger PluginManager 'Level' found 0 plugins
DEBUG StatusLogger Configuration org.apache.logging.log4j.core.config.DefaultConfiguration@3d8505f8 initialized
DEBUG StatusLogger Starting configuration org.apache.logging.log4j.core.config.DefaultConfiguration@3d8505f8
DEBUG StatusLogger Started configuration org.apache.logging.log4j.core.config.DefaultConfiguration@3d8505f8 OK.
TRACE StatusLogger Stopping org.apache.logging.log4j.core.config.DefaultConfiguration@76770ca9...
TRACE StatusLogger DefaultConfiguration notified 1 ReliabilityStrategies that config will be stopped.
TRACE StatusLogger DefaultConfiguration stopping root LoggerConfig.
TRACE StatusLogger DefaultConfiguration notifying ReliabilityStrategies that appenders will be stopped.
TRACE StatusLogger DefaultConfiguration stopping remaining Appenders.
DEBUG StatusLogger Shutting down OutputStreamManager SYSTEM_OUT.false.false-1
DEBUG StatusLogger OutputStream closed
DEBUG StatusLogger Shut down OutputStreamManager SYSTEM_OUT.false.false-1, all resources released: true
DEBUG StatusLogger Appender DefaultConsole-1 stopped with status true
TRACE StatusLogger DefaultConfiguration stopped 1 remaining Appenders.
TRACE StatusLogger DefaultConfiguration cleaning Appenders from 1 LoggerConfigs.
DEBUG StatusLogger Stopped org.apache.logging.log4j.core.config.DefaultConfiguration@76770ca9 OK
TRACE StatusLogger Reregistering MBeans after reconfigure. Selector=org.apache.logging.log4j.core.selector.ClassLoaderContextSelector@1803ce84
TRACE StatusLogger Reregistering context (1/1): '1fb9201c' org.apache.logging.log4j.core.LoggerContext@65b40e79
TRACE StatusLogger Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=1fb9201c'
TRACE StatusLogger Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=1fb9201c,component=StatusLogger'
TRACE StatusLogger Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=1fb9201c,component=ContextSelector'
TRACE StatusLogger Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=1fb9201c,component=Loggers,name=*'
TRACE StatusLogger Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=1fb9201c,component=Appenders,name=*'
TRACE StatusLogger Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=1fb9201c,component=AsyncAppenders,name=*'
TRACE StatusLogger Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=1fb9201c,component=AsyncLoggerRingBuffer'
TRACE StatusLogger Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=1fb9201c,component=Loggers,name=*,subtype=RingBuffer'
DEBUG StatusLogger Registering MBean org.apache.logging.log4j2:type=1fb9201c
DEBUG StatusLogger Registering MBean org.apache.logging.log4j2:type=1fb9201c,component=StatusLogger
DEBUG StatusLogger Registering MBean org.apache.logging.log4j2:type=1fb9201c,component=ContextSelector
DEBUG StatusLogger Registering MBean org.apache.logging.log4j2:type=1fb9201c,component=Appenders,name=DefaultConsole-2
TRACE StatusLogger Using default SystemClock for timestamps.
DEBUG StatusLogger org.apache.logging.log4j.core.util.SystemClock supports precise timestamps.
TRACE StatusLogger Using DummyNanoClock for nanosecond timestamps.
DEBUG StatusLogger Reconfiguration complete for context[name=1fb9201c] at URI NULL_SOURCE (org.apache.logging.log4j.core.LoggerContext@65b40e79) with optional ClassLoader: null
DEBUG StatusLogger Shutdown hook enabled. Registering a new one.
DEBUG StatusLogger LoggerContext[name=1fb9201c, org.apache.logging.log4j.core.LoggerContext@65b40e79] started OK.
4

1 回答 1

1

您使用了错误的log4jConfiguration参数值:file:///config/log4j-dev.properties指向/config/log4j-dev.properties本地文件系统的文件。

由于log4jConfiguration可以是要传递到的资源路径ServletContext#getResource或绝对 URI,因此您可以使用:

  • 文件相对于 Web 应用程序根目录的路径:/WEB-INF/classes/config/log4j-dev.properties,
  • 类路径 URI: classpath:config/log4j-dev.properties.

编辑:您的配置也有一点问题:它缺少触发策略:

status = warn
name= properties_configuration

property.basePath = ${sys:catalina.base}/logs/ogd_mdd/

# RollingFileAppender will print logs in file which can be rotated based on time or size
appender.rolling.type = RollingFile
appender.rolling.name = fileLogger
appender.rolling.fileName= ${basePath}app.log
appender.rolling.filePattern= ${basePath}app_%d{yyyyMMdd}.log.gz
appender.rolling.policy.type = TimeBasedTriggeringPolicy
appender.rolling.layout.type = PatternLayout
appender.rolling.layout.pattern = %d{yyyy-MM-dd HH:mm:ss.SSS} %level [%M] [%l] - %msg%n

# Configure root logger for logging error logs in classes which are in package other than above specified package
rootLogger.level = info
rootLogger.appenderRef.rolling.ref = fileLogger
于 2021-05-12T11:48:05.873 回答