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

日志未根据Log4j2加载。性质

蓬长恨
2023-03-14

我升级到Log4j到Log4j2在我的项目。我已经把log4j2.properties放在类路径中,并加载它。尽管日志不是根据log4j2.properties.中定义的属性来的

例如,我将属性设置为

appender.console.layout.pattern=%d{yyyy-dd HH: mm: ss。SSS}%级别[%t][%c][%M][%l]-%msg%n

但是日志打印为2020-05-20 16:12:43.060 DEBUG 58312---[main]o.s.c.a.ClassPathBeanDefinitionScanner:已识别的候选组件类:文件[D:\workspace\metricsdaillysummarydao.class]

2020-05-20 16:12:43.061调试58312---[main]o.s.c.a.ClassPathBeanDefinitionScanner:已识别的候选组件类:文件[D:\workspace\MetricsDao.class]

2020-05-20 16:12:43.061DEBUG 58312 --- [ main]o. s. c. a.确定的候选组件类:文件[D:\workspace\MetricsHourlySummaryDao.class]我们可以看到...虽然在我的财产我已经删除了月份,但它是打印在日志。

有人能提出解决办法吗?

编辑附加属性文件

status = debug
name= properties_configuration

# Give directory path where log files should get stored


# ConsoleAppender will print logs on console
appender.console.type = Console
appender.console.name = consoleLogger
appender.console.target = SYSTEM_OUT
appender.console.layout.type = PatternLayout

# Specify the pattern of the logs
appender.console.layout.ConversionPattern = %d{yyyy-dd HH:mm:ss} %level [%t] [%c] [%M] [%l] - %msg%n

rootLogger.level=debug
rootLogger.appenderRef.stdout.ref= STDOUT
logger.org.springframework.security=DEBUG
logger.org.apache.commons=ERROR
logger.httpclient.wire.header=WARN,OFA
logger.httpclient.wire.content=WARN,OFA
logger.bitronix.tm=ERROR
logger.org.quartz=INFO
logger.org.hibernate=INFO,RFA
logger.org.hibernate.type=INFO,RFA
logger.org.hibernate.transaction.JDBCTransaction=DEBUG,RFA
logger.org.hibernate.engine.StatefulPersistenceContext=INFO,OFA
logger.org.apache.axis=INFO,OFA
logger.org.apache.http=ERROR
logger.com.br.management.dashboard=ERROR,RFA
logger.com.br.management.security=INFO,RFA
logger.com.googlecode.ehcache=ERROR,OFA
logger.com.br.management.datagrid=INFO,OFA
logger.com.br.management.systemConfig=INFO,RFA
logger.com.br.management.policy=DEBUG
logger.com.br.management.monitoring=DEBUG,OFA
logger.com.br.management.billing=ERROR,OFA
logger.com.br.management.autonomics=DEBUG

共有1个答案

孟洋
2023-03-14

回答涉及评论https://stackoverflow.com/questions/61911283/logs-are-not-loading-according-to-log4j2-properties?noredirect=1comment109537890_61911283

在这里工作。

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.3.0.RELEASE)

2020-21 10:58:59 INFO [main] [com.example.testlog.TestLogApplication] [logStarting] [org.springframework.boot.StartupInfoLogger.logStarting(StartupInfoLogger.java:55)] - Starting TestLogApplication on LAPTOP-S4VIHOJT with PID 23672 (C:\development\algaworks\workspace\test-log\target\classes started by joaozarate in C:\development\algaworks\workspace\test-log)
2020-21 10:58:59 INFO [main] [com.example.testlog.TestLogApplication] [logStartupProfileInfo] [org.springframework.boot.SpringApplication.logStartupProfileInfo(SpringApplication.java:651)] - No active profile set, falling back to default profiles: default
2020-21 10:59:00 INFO [main] [org.springframework.boot.web.embedded.tomcat.TomcatWebServer] [initialize] [org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:108)] - Tomcat initialized with port(s): 8080 (http)
2020-21 10:59:00 INFO [main] [org.apache.coyote.http11.Http11NioProtocol] [log] [org.apache.juli.logging.DirectJDKLog.log(DirectJDKLog.java:173)] - Initializing ProtocolHandler ["http-nio-8080"]
2020-21 10:59:00 INFO [main] [org.apache.catalina.core.StandardService] [log] [org.apache.juli.logging.DirectJDKLog.log(DirectJDKLog.java:173)] - Starting service [Tomcat]
2020-21 10:59:00 INFO [main] [org.apache.catalina.core.StandardEngine] [log] [org.apache.juli.logging.DirectJDKLog.log(DirectJDKLog.java:173)] - Starting Servlet engine: [Apache Tomcat/9.0.35]
2020-21 10:59:00 INFO [main] [org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/]] [log] [org.apache.juli.logging.DirectJDKLog.log(DirectJDKLog.java:173)] - Initializing Spring embedded WebApplicationContext
2020-21 10:59:00 INFO [main] [org.springframework.web.context.ContextLoader] [prepareWebApplicationContext] [org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.prepareWebApplicationContext(ServletWebServerApplicationContext.java:284)] - Root WebApplicationContext: initialization completed in 1144 ms
2020-21 10:59:00 INFO [main] [org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor] [initialize] [org.springframework.scheduling.concurrent.ExecutorConfigurationSupport.initialize(ExecutorConfigurationSupport.java:181)] - Initializing ExecutorService 'applicationTaskExecutor'
2020-21 10:59:00 INFO [main] [org.apache.coyote.http11.Http11NioProtocol] [log] [org.apache.juli.logging.DirectJDKLog.log(DirectJDKLog.java:173)] - Starting ProtocolHandler ["http-nio-8080"]
2020-21 10:59:00 INFO [main] [org.springframework.boot.web.embedded.tomcat.TomcatWebServer] [start] [org.springframework.boot.web.embedded.tomcat.TomcatWebServer.start(TomcatWebServer.java:220)] - Tomcat started on port(s): 8080 (http) with context path ''
2020-21 10:59:00 INFO [main] [com.example.testlog.TestLogApplication] [logStarted] [org.springframework.boot.StartupInfoLogger.logStarted(StartupInfoLogger.java:61)] - Started TestLogApplication in 1.739 seconds (JVM running for 2.539)

文件 /test-log/src/main/resources/application.properties为空

文件:/testlog/pom。xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.0.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>test-log</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>test-log</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>11</java.version>
    </properties>

    <dependencies>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <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>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

文件:/testlog/src/main/resources/log4j2。性质

status = error
name = PropertiesConfig

filters = threshold

filter.threshold.type = ThresholdFilter
filter.threshold.level = info

appenders = console

appender.console.type = Console
appender.console.name = STDOUT
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = %d{yyyy-dd HH:mm:ss} %level [%t] [%c] [%M] [%l] - %msg%n

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

  • 我从log4j1迁移过来。x到log4j2。我删除了log4j。属性文件并创建了log4j2。xml文件。迁移后,我运行了应用程序,但找不到。日志文件。 有没有人能告诉我

  • 我希望由log4j2创建的日志文件在其文件名中包含日期模式,包括当前活动文件。也就是说,如果今天的日期是2016-12-15,我希望当前日志文件是lager-2016-12-15.log。当日期改变时,我希望创建一个名为lager-2016-12-16.log的新文件。 使用,我无法使当前活动日志文件的文件名中具有日期模式。我的log4j2.xml: 使用此配置,翻转时的复制被搞乱了。从fileN

  • 我刚开始使用log4j2 我正在尝试配置xml,以便使用和附加符将日志发送到日志文件中。这个附加器工作得很好。我想使用appender,这样它就可以每天清除日志文件,但是当它第一次创建日志文件时,它没有将任何日志消息写入创建的文件中,所以我来这里是为了得到一些建议

  • 我在spring应用程序中使用log4j2作为我的日志工具。我想为特定的库/包设置不同于根目录的日志级别。例如,我希望< code>org.springframework为INFO,而< code>com.google为WARN。我在< code>log4j2.properties中找到了这个: 我不明白是什么意思?我一直在log4j2文档中找到它,但没有解释那是什么或意味着什么。 如何为特定包添

  • 我在研究这个问题时发现的几乎所有内容都是针对Log4J1.x的,并讨论了一个似乎在2.0中不存在的datePattern参数。 下面是我的log4j2.xml文件: 我正在将信息和以上内容写入日志文件,并将调试写入控制台(目前)。这些文件被写得很好,但它们似乎每天都在滚动(这似乎是默认的)。