当前位置: 首页 > 知识库问答 >
问题:

log4j2.xml已加载但未应用[JVM参数]

景宏盛
2023-03-14
-Dlog4j.configurationFile=file://C:\{path}\Workspace\demo-indexeur\config\log4j2.xml

Spring boot检测我的文件(我在控制台中没有错误)并加载它,但不应用我放在文件中的配置。

下面是我的配置文件加载的调试:

2015-05-06 15:36:53,279 DEBUG Starting configuration XmlConfiguration[location=C:\{path}\Workspace\demo-indexeur\config\log4j2.xml]
2015-05-06 15:36:53,279 DEBUG PluginManager 'Core' found 69 plugins
2015-05-06 15:36:53,279 DEBUG PluginManager 'Level' found 0 plugins
2015-05-06 15:36:53,279 DEBUG PluginManager 'Lookup' found 10 plugins
2015-05-06 15:36:53,279 DEBUG Building Plugin[name=layout, class=org.apache.logging.log4j.core.layout.PatternLayout]. Searching for builder factory method...
2015-05-06 15:36:53,279 DEBUG Found builder factory method [newBuilder]: public static org.apache.logging.log4j.core.layout.PatternLayout$Builder org.apache.logging.log4j.core.layout.PatternLayout.newBuilder().
2015-05-06 15:36:53,289 DEBUG TypeConverterRegistry initializing.
2015-05-06 15:36:53,289 DEBUG PluginManager 'TypeConverter' found 21 plugins
2015-05-06 15:36:53,299 DEBUG Calling build() on class class org.apache.logging.log4j.core.layout.PatternLayout$Builder for element PatternLayout with params(pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n", Configuration(C:\{path}\Workspace\demo-indexeur\config\log4j2.xml), null, charset="null", alwaysWriteExceptions="null", noConsoleNoAnsi="null", header="null", footer="null")
2015-05-06 15:36:53,299 DEBUG PluginManager 'Converter' found 33 plugins
2015-05-06 15:36:53,299 DEBUG Built Plugin[name=layout] OK from builder factory method.
2015-05-06 15:36:53,299 DEBUG Building Plugin[name=appender, class=org.apache.logging.log4j.core.appender.ConsoleAppender]. Searching for builder factory method...
2015-05-06 15:36:53,299 INFO Log4j appears to be running in a Servlet environment, but there's no log4j-web module available. If you want better web container support, please add the log4j-web JAR to your web archive or server lib directory.
2015-05-06 15:36:53,299 DEBUG PluginManager 'Converter' found 33 plugins
2015-05-06 15:36:53,299 DEBUG Jansi is not installed, cannot find org.fusesource.jansi.WindowsAnsiOutputStream
2015-05-06 15:36:53,299 DEBUG Found builder factory method [newBuilder]: public static org.apache.logging.log4j.core.appender.ConsoleAppender$Builder org.apache.logging.log4j.core.appender.ConsoleAppender.newBuilder().
2015-05-06 15:36:53,299 DEBUG No PluginVisitorStrategy found on annotation [interface org.apache.logging.log4j.core.config.plugins.validation.constraints.Required]. Ignoring.
2015-05-06 15:36:53,299 DEBUG Encountered type [org.apache.logging.log4j.core.layout.PatternLayout] which can only be checked for null.
2015-05-06 15:36:53,309 DEBUG No PluginVisitorStrategy found on annotation [interface org.apache.logging.log4j.core.config.plugins.validation.constraints.Required]. Ignoring.
2015-05-06 15:36:53,309 DEBUG Encountered type [org.apache.logging.log4j.core.appender.ConsoleAppender$Target] which can only be checked for null.
2015-05-06 15:36:53,309 DEBUG No PluginVisitorStrategy found on annotation [interface org.apache.logging.log4j.core.config.plugins.validation.constraints.Required]. Ignoring.
2015-05-06 15:36:53,309 DEBUG Calling build() on class class org.apache.logging.log4j.core.appender.ConsoleAppender$Builder for element Console with params(PatternLayout(%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n), null, target="SYSTEM_OUT", name="Console", follow="null", ignoreExceptions="null")
2015-05-06 15:36:53,309 DEBUG Jansi is not installed, cannot find org.fusesource.jansi.WindowsAnsiOutputStream
2015-05-06 15:36:53,309 DEBUG Built Plugin[name=appender] OK from builder factory method.
2015-05-06 15:36:53,309 DEBUG Building Plugin[name=appenders, class=org.apache.logging.log4j.core.config.AppendersPlugin]. Searching for builder factory method...
2015-05-06 15:36:53,309 DEBUG No builder factory method found in class org.apache.logging.log4j.core.config.AppendersPlugin. Going to try finding a factory method instead.
2015-05-06 15:36:53,309 DEBUG Still building Plugin[name=appenders, class=org.apache.logging.log4j.core.config.AppendersPlugin]. Searching for factory method...
2015-05-06 15:36:53,309 DEBUG Found factory method [createAppenders]: public static java.util.concurrent.ConcurrentMap org.apache.logging.log4j.core.config.AppendersPlugin.createAppenders(org.apache.logging.log4j.core.Appender[]).
2015-05-06 15:36:53,309 DEBUG Calling createAppenders on class org.apache.logging.log4j.core.config.AppendersPlugin for element Appenders with params(={Console})
2015-05-06 15:36:53,309 DEBUG Built Plugin[name=appenders] OK from factory method.
2015-05-06 15:36:53,309 DEBUG Building Plugin[name=AppenderRef, class=org.apache.logging.log4j.core.config.AppenderRef]. Searching for builder factory method...
2015-05-06 15:36:53,309 DEBUG No builder factory method found in class org.apache.logging.log4j.core.config.AppenderRef. Going to try finding a factory method instead.
2015-05-06 15:36:53,309 DEBUG Still building Plugin[name=AppenderRef, class=org.apache.logging.log4j.core.config.AppenderRef]. Searching for factory method...
2015-05-06 15:36:53,309 DEBUG Found factory method [createAppenderRef]: public static org.apache.logging.log4j.core.config.AppenderRef org.apache.logging.log4j.core.config.AppenderRef.createAppenderRef(java.lang.String,org.apache.logging.log4j.Level,org.apache.logging.log4j.core.Filter).
2015-05-06 15:36:53,309 DEBUG Calling createAppenderRef on class org.apache.logging.log4j.core.config.AppenderRef for element AppenderRef with params(ref="Console", level="null", null)
2015-05-06 15:36:53,309 DEBUG Built Plugin[name=AppenderRef] OK from factory method.
2015-05-06 15:36:53,309 DEBUG Building Plugin[name=root, class=org.apache.logging.log4j.core.config.LoggerConfig$RootLogger]. Searching for builder factory method...
2015-05-06 15:36:53,309 DEBUG No builder factory method found in class org.apache.logging.log4j.core.config.LoggerConfig$RootLogger. Going to try finding a factory method instead.
2015-05-06 15:36:53,309 DEBUG Still building Plugin[name=root, class=org.apache.logging.log4j.core.config.LoggerConfig$RootLogger]. Searching for factory method...
2015-05-06 15:36:53,309 DEBUG Found factory method [createLogger]: public static org.apache.logging.log4j.core.config.LoggerConfig org.apache.logging.log4j.core.config.LoggerConfig$RootLogger.createLogger(java.lang.String,org.apache.logging.log4j.Level,java.lang.String,org.apache.logging.log4j.core.config.AppenderRef[],org.apache.logging.log4j.core.config.Property[],org.apache.logging.log4j.core.config.Configuration,org.apache.logging.log4j.core.Filter).
2015-05-06 15:36:53,319 DEBUG Calling createLogger on class org.apache.logging.log4j.core.config.LoggerConfig$RootLogger for element Root with params(additivity="null", level="ERROR", includeLocation="null", ={Console}, ={}, Configuration(C:\{path}\Workspace\demo-indexeur\config\log4j2.xml), null)
2015-05-06 15:36:53,319 DEBUG Built Plugin[name=root] OK from factory method.
2015-05-06 15:36:53,319 DEBUG Building Plugin[name=loggers, class=org.apache.logging.log4j.core.config.LoggersPlugin]. Searching for builder factory method...
2015-05-06 15:36:53,319 DEBUG No builder factory method found in class org.apache.logging.log4j.core.config.LoggersPlugin. Going to try finding a factory method instead.
2015-05-06 15:36:53,319 DEBUG Still building Plugin[name=loggers, class=org.apache.logging.log4j.core.config.LoggersPlugin]. Searching for factory method...
2015-05-06 15:36:53,319 DEBUG Found factory method [createLoggers]: public static org.apache.logging.log4j.core.config.Loggers org.apache.logging.log4j.core.config.LoggersPlugin.createLoggers(org.apache.logging.log4j.core.config.LoggerConfig[]).
2015-05-06 15:36:53,319 DEBUG Calling createLoggers on class org.apache.logging.log4j.core.config.LoggersPlugin for element Loggers with params(={root})
2015-05-06 15:36:53,319 DEBUG Built Plugin[name=loggers] OK from factory method.
2015-05-06 15:36:53,319 DEBUG Started configuration XmlConfiguration[location=C:\{path}\Workspace\demo-indexeur\config\log4j2.xml] OK.
2015-05-06 15:36:53,319 TRACE Stopping org.apache.logging.log4j.core.config.DefaultConfiguration@5b87edb3...
2015-05-06 15:36:53,319 TRACE AbstractConfiguration stopped 0 AsyncLoggerConfigs.
2015-05-06 15:36:53,319 TRACE AbstractConfiguration stopped 0 AsyncAppenders.
2015-05-06 15:36:53,319 TRACE AbstractConfiguration stopped 1 Appenders.
2015-05-06 15:36:53,319 TRACE AbstractConfiguration stopped 0 Loggers.
2015-05-06 15:36:53,319 DEBUG Stopped org.apache.logging.log4j.core.config.DefaultConfiguration@5bc79274 OK
2015-05-06 15:36:53,319 DEBUG Registering MBean org.apache.logging.log4j2:type=sun.misc.Launcher$AppClassLoader@c387f44
2015-05-06 15:36:53,329 DEBUG Registering MBean org.apache.logging.log4j2:type=sun.misc.Launcher$AppClassLoader@c387f44,component=StatusLogger
2015-05-06 15:36:53,329 DEBUG Registering MBean org.apache.logging.log4j2:type=sun.misc.Launcher$AppClassLoader@c387f44,component=ContextSelector
2015-05-06 15:36:53,329 DEBUG Registering MBean org.apache.logging.log4j2:type=sun.misc.Launcher$AppClassLoader@c387f44,component=Loggers,name=
2015-05-06 15:36:53,329 DEBUG Registering MBean org.apache.logging.log4j2:type=sun.misc.Launcher$AppClassLoader@c387f44,component=Appenders,name=Console
2015-05-06 15:36:53,329 DEBUG Reconfiguration complete for context[name=sun.misc.Launcher$AppClassLoader@c387f44] at null (org.apache.logging.log4j.core.LoggerContext@72b6cbeb) with optional ClassLoader: null
2015-05-06 15:36:53,329 DEBUG Shutdown hook enabled. Registering a new one.
2015-05-06 15:36:53,329 DEBUG LoggerContext[name=sun.misc.Launcher$AppClassLoader@c387f44, org.apache.logging.log4j.core.LoggerContext@7fac633a] started OK.
2015-05-06 15:36:53,489 DEBUG Using configurationFactory org.apache.logging.log4j.core.config.ConfigurationFactory$Factory@6973bf95
2015-05-06 15:36:53,489 INFO Log4j appears to be running in a Servlet environment, but there's no log4j-web module available. If you want better web container support, please add the log4j-web JAR to your web archive or server lib directory.

当我在“src/main/resources”中移动文件时,它工作得很好,但当我试图外部化文件时,它就不工作了。

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
  <Appenders>
    <Console name="Console" target="SYSTEM_OUT">
      <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
    </Console>
  </Appenders>
  <Loggers>
    <Root level="error">
      <AppenderRef ref="Console"/>
    </Root>
  </Loggers>
</Configuration>
<!--    Spring Batch -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-batch</artifactId>
        <exclusions>
<!--            Suppression de SLF4J -->
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

<!--    Spring web-->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
<!--            Suppression de SLF4J -->
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

<!--    Utilisation de LOG4J2 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-log4j2</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>

共有1个答案

祁鸿哲
2023-03-14

Log4j具有在初始化期间自动配置自身的能力。Log4j将检查“Log4j.configurationfile”系统属性,如果设置了该属性,将尝试加载配置。

这就是为什么我的文件没有错误地被检测和加载,但没有被spring Boot使用。

我忘了告诉spring boot在哪里可以找到日志配置文件,为此,我必须在spring boot的application.properties中添加:

logging.config= # location of logging config file
 类似资料:
  • 我正在从log4j1.x升级到log4j2,并将log4j.xml配置文件更新为一个新的log4j2.xml配置。我在运行maven,spring和Mule。 当运行一个测试maven构建时,log4j2.xml文件不会被拾取。但是,如果我重命名该文件log4j2-test.xml,它就会被拾取(例如,带有自定义PatternLayout的控制台记录器在第二种情况下可以正常工作,但在第一种情况下使

  • 你能帮我找出配置中缺少的步骤吗? 我正试图将logger添加到我非常简单的web应用程序中:为了做到这一点,我使用了log4j2 (beta9)。 我写下了我的<code>log4j2.xml<code>如下 我把它放在WEB-INF文件夹里。 然后,我有一个简单的servlet,它执行以下操作 正如你所看到的,这只是一个尝试,看看是否如预期的那样工作,但它没有。通过阅读此处的web app,我不

  • 我试图在spring boot应用程序中添加log4j2框架,并使用spring AOP将日志记录问题与逻辑业务分离开来。不幸的是,当我尝试记录消息时,log4j2不起作用,它使用spring默认的日志记录。 这是我的LoggingAspect类,我尝试在其中记录消息:LoggingAspect。JAVA 这是我的pom。xml文件: 最后这是我的log4j2。xml文件: 当我尝试使用logge

  • 我对log4j相当陌生。正在尝试使用log4j2。要配置的xml。我将该文件添加到构建路径,它工作了一次,但不再工作。 这是我的log4j2.xml: 我把它拆下来,只是为了测试它,让它工作。我检查了调试,并且记录器配置使用默认值。 我还试着给文件命名log4j2-test.xml. 有什么想法吗? 谢啦

  • 在用户关闭间隙广告后,我将在我的应用程序中添加奖励广告,它将显示一个屏幕,显示之前输入的文本,并在下方有一个显示奖励广告的视频按钮(我处于测试阶段,因此我还不包括任何奖励项目,只想先显示视频广告)。 当我使用Toast小部件来识别广告是否已加载时,我意识到广告已加载(显示“onRewardedAdLoade”文本)。但是,当我单击观看视频按钮时,似乎没有调用show RewardedVideo()

  • 我已经将log4j从1.2.17升级到了2.16.0。因此我不得不重写我的log4j。并将其重命名为log4j2.xml。我已经做了必要的改变。然而,我的新配置似乎没有加载。我试图通过两个web配置log4j。xml: 和。两种方法都失败了,我在mylog.log文件中没有任何日志。但是当在本地运行应用程序时,控制台会显示日志。 这是我的log4j2.xml: 我尝试使用以下工具调试log4j配置