我有一个相当普通的 Ubuntu 20.04LTS 盒子,我从 repo 部署了 Tomcat9。开箱即用,这似乎被配置为将其日志写入 /var/log/tomcat9/ 并且那里确实有日志文件。然而,这些信息只有我期望的一小部分——其余部分在输出中可见,systemctl status tomcat9
并且正在写入 /var/log/syslog。
提供的单元文件中唯一相关的是......
SyslogIdentifier=tomcat9
在安装tomcat的同时还创建了/etc/rsyslog.d/tomcat9.conf 包含...。
# Send Tomcat messages to catalina.out when using systemd
$template TomcatFormat,"[%timegenerated:::date-year%-%timegenerated:::date-month%-%timegenerated:::date-day% %timegenerated:::date-hour%:%timegenerated:::date-minute%:%timegenerated:::date-second%] [%syslogseverity-text%]%msg%\n"
:programname, startswith, "tomcat9" {
/var/log/tomcat9/catalina.out;TomcatFormat
stop
}
的输出示例systemctl status tomcat9
● tomcat9.service - Apache Tomcat 9 Web Application Server
Loaded: loaded (/lib/systemd/system/tomcat9.service; enabled; vendor preset: enabled)
Drop-In: /etc/systemd/system/tomcat9.service.d
└─override.conf
Active: active (running) since Fri 2022-04-08 13:07:39 UTC; 17min ago
Docs: https://tomcat.apache.org/tomcat-9.0-doc/index.html
Process: 1006 ExecStartPre=/usr/libexec/tomcat9/tomcat-update-policy.sh (code=exited, status=0/SUCCESS)
Main PID: 1026 (java)
Tasks: 53 (limit: 2274)
Memory: 332.9M
CGroup: /system.slice/tomcat9.service
└─1026 /usr/lib/jvm/java-8-openjdk-amd64/bin/java -Djava.util.logging.config.file=/var/lib/tomcat9/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.C>
Apr 08 13:20:14 myhost.example.com tomcat9[1026]: [cfPullService] DEBUG 13:20:14 ConnectionManager.openConnection(444) | opening JDBC connection
Apr 08 13:20:14 myhost.example.com tomcat9[1026]: [cfPullService] DEBUG 13:20:14 JDBCTransaction.begin(87) | current autocommit status: true
Apr 08 13:20:14 myhost.example.com tomcat9[1026]: [cfPullService] DEBUG 13:20:14 JDBCTransaction.begin(90) | disabling autocommit
Apr 08 13:20:14 myhost.example.com tomcat9[1026]: [cfPullService] DEBUG 13:20:14 JDBCTransaction.commit(134) | commit
Apr 08 13:20:14 myhost.example.com tomcat9[1026]: [cfPullService] DEBUG 13:20:14 JDBCTransaction.toggleAutoCommit(227) | re-enabling autocommit
上面的“cfPullService”来自已部署的 java 代码(实际上是一个黑盒子),并且可能在其他时间包含其他值。
以及 /var/log/syslog 中的条目示例...
Apr 8 13:20:12 myhost tomcat9[1026]: [cfPullService] INFO 13:20:12 RunSearchManagerImpl.runEarlyEngagementSearch(165) | Finished saving early engagement notices.
Apr 8 13:20:12 myhost tomcat9[1026]: [cfPullService] INFO 13:20:12 RunSearchManagerImpl.runPipelineSearch(176) | Running pipeline search
提供的 /etc/rsyslog.d/tomcat9.conf 如下所示:
# Send Tomcat messages to catalina.out when using systemd
$template TomcatFormat,"[%timegenerated:::date-year%-%timegenerated:::date-month%-%timegenerated:::date-day% %timegenerated:::date-hour%:%timegenerated:::date-minute%:%timegenerated:::date-second%] [%syslogseverity-text%]%msg%\n"
:programname, startswith, "tomcat9" {
/var/log/tomcat9/catalina.out;TomcatFormat
stop
}
我尝试使用...创建一个 systemd 覆盖文件(并应用了守护程序重新加载)。
[Service]
StandardOutput=syslog
StandardError=syslog
但这对行为没有影响。
我如何能
- 获取 tomcat 的输出到 /var/log/tomcat9 中的文件
- 停止将 tomcat 的输出发送到 /var/log/syslog
似乎部分问题在错误 #1861881中进行了描述。
我能够通过以下方式获得一个工作日志文件,同时从 syslog 中排除条目: