Spring boot tomcat 访问日志 [英] Spring boot tomcat access logs

查看:39
本文介绍了Spring boot tomcat 访问日志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我按照 spring boot 参考文档启用了 tomcat 访问日志.但它不能正常工作.当我启用它时,访问日志文件被创建,我可以看到当天记录的请求.但是在第二天开始时,我没有看到任何新文件.它在 21 小时开始记录.第三天,它从 02 小时开始记录.从第 4 天起没有创建访问日志.

I enabled tomcat access logs as per the spring boot reference documentation. But its not working properly. When I enabled it, access log file got created and I can see requests being logged there for that day. But at the start of the next day I don't see any new file. It started logging at 21hrs. Third day it started logging from 02hrs. From 4th day no access logs created.

这是我使用的属性.

server.tomcat.access-log-enabled=true
server.tomcat.access-log-pattern=%h %l %u %t "%r" %s %b %D
server.tomcat.basedir=/var/lib/org_name/tracking_server 

在 tracking_server 文件夹下创建了日志和工作文件夹.

under tracking_server folder logs and work folder got created.

如果我遗漏了什么,请告诉我.常规日志根据 logback.xml 中指定的配置完美运行

Please let me know if I'm missing something. Regular logging is working perfectly according to the configuration specified in logback.xml

提前感谢您的帮助.

推荐答案

该配置适用于 Spring Boot 版本 1.2.3.RELEASE.但是,如果你有当前版本的 spring boot,这些参数会有点不同,参考这里:

That configuration works for me in spring boot version 1.2.3.RELEASE. However, if you have the current version of spring boot, those parameters are a little bit different, reference here:

server.tomcat.accesslog.directory=logs # Directory in which log files are created. Can be relative to the tomcat base dir or absolute.
server.tomcat.accesslog.enabled=false # Enable access log.
server.tomcat.accesslog.pattern=common # Format pattern for access logs.

如您所见,不同之处在于连字符 (-).

As you note, the difference is the hyphen (-).

另外,tomcat访问日志配置包括以下参数,根据本文件:

Additionally, tomcat access log configuration include the following parameters, according to this document:

  • fileDateFormat.默认值为 yyyy-MM-dd.这意味着日志文件将每天更改.如果您更改为 yyyy-MM-dd.HH,则日志将每小时更改一次.
  • 可旋转.默认值为真.如果您设置为 false,我知道它将只有文件.它不使用 fileDateFormat 参数.
  • fileDateFormat. Default value is yyyy-MM-dd. It means that the log file is going to change daily. If you change for yyyy-MM-dd.HH, the log is going to change hourly.
  • rotatable. Default value is true. If you set to false, I understood that it is going to have just only file. it do not use fileDateFormat parameter.

但是,在我的 spring boot (1.2.3.RELEASE) 类 org.springframework.boot.autoconfigure.web.ServerProperties 中,没有更改这些属性的值(Tomcat 子类).但是如果你检查 org.apache.catalina.valves.AccessLogValve 你可以改变这个属性:

However, in my version of spring boot (1.2.3.RELEASE) the class org.springframework.boot.autoconfigure.web.ServerProperties there are no values to change those properties (Tomcat subclass). But if you check org.apache.catalina.valves.AccessLogValve you could change this properties:

/**
 * Should we rotate our log file? Default is true (like old behavior)
 */
protected boolean rotatable = true;

/**
 * Date format to place in log file name.
 */
protected String fileDateFormat = ".yyyy-MM-dd";

我知道也许您应该使用这些参数.我希望这篇文章能帮助您解决问题.

I know maybe you should play with those parameters. I hope this post help to solve your problem.

这篇关于Spring boot tomcat 访问日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆