gpt4 book ai didi

java - logback 日志记录的时间戳错误

转载 作者:行者123 更新时间:2023-12-02 09:59:45 24 4
gpt4 key购买 nike

我正在尝试使用 springboot logback 日志框架来记录我的信息。不幸的是,当我记录信息警告错误时,时间戳完全相同,与应用程序服务器启动时间相同。

My logback.xml configuration information is as follows:


<?xml version="1.0" encoding="UTF-8"?>
<configuration
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://www.padual.com/java/logback.xsd"
debug="false" scan="true" scanPeriod="30 second">
<property name="PROJECT" value="AmazonRss" />
<property name="ROOT" value="logs/${PROJECT}/" />
<property name="FILESIZE" value="10MB" />
<property name="MAXHISTORY" value="100" />
<timestamp key="DATETIME" datePattern="yyyy/MM/dd HH:mm:ss" />
<!-- Console printing -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder charset="utf-8">
<pattern>[%-5level] %d{${DATETIME}} [%thread] %logger{36} - %m%n
</pattern>
</encoder>
</appender>

........

我的日志是这样的:

[INFO ] 2019-04-17 16:48:44 [main] o.a.coyote.http11.Http11NioProtocol - Initializing ProtocolHandler ["http-nio-8888"]
[INFO ] 2019-04-17 16:48:44 [main] o.a.catalina.core.StandardService - Starting service [Tomcat]
[INFO ] 2019-04-17 16:48:44 [main] o.a.catalina.core.StandardEngine - Starting Servlet engine: [Apache Tomcat/9.0.14]
[INFO ] 2019-04-17 16:48:44 [main] o.a.c.core.AprLifecycleListener - The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib]
[INFO ] 2019-04-17 16:48:44 [main] o.a.c.c.C.[Tomcat].[localhost].[/] - Initializing Spring embedded WebApplicationContext
[INFO ] 2019-04-17 16:48:44 [main] o.s.web.context.ContextLoader - Root WebApplicationContext: initialization completed in 6725 ms
[INFO ] 2019-04-17 16:48:44 [main] com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Starting...
[INFO ] 2019-04-17 16:48:44 [main] com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Start completed.
[INFO ] 2019-04-17 16:48:44 [main] o.h.jpa.internal.util.LogHelper - HHH000204: Processing PersistenceUnitInfo [
name: default
...]
[INFO ] 2019-04-17 16:48:44 [main] org.hibernate.Version - HHH000412: Hibernate Core {5.3.7.Final}
[INFO ] 2019-04-17 16:48:44 [main] org.hibernate.cfg.Environment - HHH000206: hibernate.properties not found
[INFO ] 2019-04-17 16:48:44 [main] o.h.annotations.common.Version - HCANN000001: Hibernate Commons Annotations {5.0.4.Final}
[INFO ] 2019-04-17 16:48:44 [main] org.hibernate.dialect.Dialect - HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
[INFO ] 2019-04-17 16:48:44 [main] o.s.o.j.LocalContainerEntityManagerFactoryBean - Initialized JPA EntityManagerFactory for persistence unit 'default'
[INFO ] 2019-04-17 16:48:44 [main] com.denistek.rss.utils.SpringUtil - ---------------------------------------------------------------------
[INFO ] 2019-04-17 16:48:44 [main] com.denistek.rss.utils.SpringUtil - ========The ApplicationContext configuration is successful. In the normal class, you can get the applicationContext object by calling SpringUtils.getAppContext(). applicationContext=org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@c818063, started on Wed Apr 17 16:48:45 CST 2019========
[INFO ] 2019-04-17 16:48:44 [main] o.s.b.a.e.web.EndpointLinksResolver - Exposing 2 endpoint(s) beneath base path '/actuator'
[INFO ] 2019-04-17 16:48:44 [main] o.s.s.c.ThreadPoolTaskExecutor - Initializing ExecutorService 'applicationTaskExecutor'
[INFO ] 2019-04-17 16:48:44 [main] s.d.s.w.p.DocumentationPluginsBootstrapper - Context refreshed
[INFO ] 2019-04-17 16:48:44 [main] s.d.s.w.p.DocumentationPluginsBootstrapper - Found 1 custom documentation plugin(s)
[INFO ] 2019-04-17 16:48:44 [main] s.d.s.w.s.ApiListingReferenceScanner - Scanning for api listing references
[INFO ] 2019-04-17 16:48:44 [main] o.a.coyote.http11.Http11NioProtocol - Starting ProtocolHandler ["http-nio-8888"]
[INFO ] 2019-04-17 16:48:44 [main] o.s.b.w.e.tomcat.TomcatWebServer - Tomcat started on port(s): 8888 (http) with context path ''
[INFO ] 2019-04-17 16:48:44 [main] com.denistek.rss.RssApplication - Started RssApplication in 32.748 seconds (JVM running for 34.213)
[INFO ] 2019-04-17 16:48:44 [http-nio-8888-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] - Initializing Spring DispatcherServlet 'dispatcherServlet'
[INFO ] 2019-04-17 16:48:44 [http-nio-8888-exec-1] o.s.web.servlet.DispatcherServlet - Initializing Servlet 'dispatcherServlet'
[INFO ] 2019-04-17 16:48:44 [http-nio-8888-exec-1] o.s.web.servlet.DispatcherServlet - Completed initialization in 22 ms
[INFO ] 2019-04-17 16:48:44 [http-nio-8888-exec-4] e.u.i.c.crawler.CrawlController - Deleted contents of: /tmp/frontier ( as you have configured resumable crawling to false )
[INFO ] 2019-04-17 16:48:44 [http-nio-8888-exec-4] e.u.i.c.crawler.CrawlController - Crawler 1 started
[INFO ] 2019-04-17 16:48:44 [http-nio-8888-exec-4] e.u.i.c.crawler.CrawlController - Crawler 2 started
[INFO ] 2019-04-17 16:4

显然,我在服务器启动很长时间后运行我的服务,但运行时日志信息与服务启动时的时间戳相同。

我是logback新手,不知道这个问题是怎么产生的。如果您能提供一些建议,我将非常感激。

最佳答案

<timestamp标签并不意味着用于包含属性。它在开始时被评估,并且它的值被结果替换。这意味着您最终得到的结果相当于:

<pattern>[%-5level] %d{2019-04-17 16:48:44} [%thread] %logger{36} - %m%n

因此是固定的日期时间。 The documentation澄清这一点:

The timestamp element takes two mandatory attributes key and datePattern and an optional timeReference attribute. The key attribute is the name of the key under which the timestamp will be available to subsequent configuration elements as a variable. The datePattern attribute denotes the date pattern used to convert the current time (at which the configuration file is parsed) into a string. The date pattern should follow the conventions defined in SimpleDateFormat. The timeReference attribute denotes the time reference for the time stamp. The default is the interpretation/parsing time of the configuration file, i.e. the current time. However, under certain circumstances it might be useful to use the context birth time as time reference. This can be accomplished by setting the timeReference attribute to "contextBirth".

改用普通属性:

<property name="MAXHISTORY" value="100" />
<property name="DATETIME" value="yyyy/MM/dd HH:mm:ss" />
<!-- Console printing -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder charset="utf-8">
<pattern>[%-5level] %d{${DATETIME}} [%thread] %logger{36} - %m%n
</pattern>
</encoder>
</appender>

关于java - logback 日志记录的时间戳错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55726914/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com