错误时间戳的logback日志记录

时间:2019-04-17 11:48:40

标签: java logback

我正在尝试使用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

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

我是登录的新手,我不知道此问题是如何产生的。如果您能提供一些建议,我将不胜感激。

1 个答案:

答案 0 :(得分:1)

<timestamp标记不用于包含属性。在开始时对其进行评估,并将其值替换为结果。这意味着您最终得到的等同于:

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

因此是固定的日期时间。 The documentation对此进行了澄清:

  

timestamp元素具有两个强制属性key和   datePattern和可选的timeReference属性。 key属性   是密钥的名称,在该密钥下时间戳可用于   后续配置元素作为变量。 datePattern   属性表示用于转换当前时间的日期模式   (在其中解析配置文件)成字符串。日期   模式应遵循SimpleDateFormat中定义的约定。的   timeReference属性表示时间戳的时间参考。   默认值为配置的解释/解析时间   文件,即当前时间。但是,在某些情况下   使用上下文出生时间作为时间参考可能会很有用。这个   可以通过将timeReference属性设置为   "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>
相关问题