如何阻止 Tomcat / rsyslog 記錄到控制台?

如何阻止 Tomcat / rsyslog 記錄到控制台?

在我的工作中,有人曾經設定 Tomcat 來記錄系統日誌。問題是這些訊息也會發送到控制台。

系統是RHEL6,這些是涉及的RPM

rsyslog-5.8.10-10.el6_6.x86_64
tomcat-7.0.64-1.x86_64

我嘗試使用這兩個命令使控制台訊息靜音:

dmesg -n 1
sysctl -w kernel.printk="1 4 1 3"

這些沒有什麼區別,這些訊息仍然不斷出現。Log4j似乎沒有在這個系統上使用。在server.xmlTomcat 中,此部分用於日誌記錄:

<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
       prefix="localhost_access_log." suffix=".txt" rotatable="false"
       pattern="%h %l %u %t &quot;%r&quot; %s %b" />

如果我停止rsyslog它就會停止這些訊息。我不知道如何設定rsyslogTomcat 的日誌記錄,我不是 Tomcat 專家。 Tomcat 是唯一向控制台發送訊息的應用程式。其他內容被發送到,rsyslog但除了 Tomcat 內容之外,沒有任何內容被記錄到控制台。

由於我嘗試了命令,dmesg -n 1我懷疑 Tomcat 正在最高層級發送訊息,但我找不到任何可能導致此問題的程式碼。

控制台上的訊息範例(請注意,它顯示 tomcat-instance06,這是一個允許多個 Tomcat 實例的自製 RPM)。我只是注意到它總是在控制台上顯示一條 [FATAL] 訊息,然後顯示第二個相同的訊息:

Message from syslogd@localhost at Jun 22 16:52:12 ...
 [FATAL] some.portal-app: [model.website.PageService] RequestID already used - ...#012Detail: #012detail#012Tag context: #012/opt/tomcat-instance06/webapps/ROOT/model/WebserviceRequest.cfc, line 486#012/opt/tomcat-instance06/webapps/ROOT/model/WebserviceRequest.cfc, line 484#012/opt/tomcat-instance06/webapps/ROOT/model/WebserviceRequest.cfc, line 482#012/opt/tomcat-instance06/webapps/ROOT/model/WebserviceRequest.cfc, line 482#012/opt/tomcat-instance06/webapps/ROOT/model/WebserviceRequest.cfc, line 482#012/opt/tomcat-instance06/webapps/ROOT/model/WebserviceRequest.cfc, line 482#012/opt/tomcat-instance06/webapps/ROOT/model/WebserviceRequest.cfc, line 482#012/opt/tomcat-instance06/webapps/ROOT/model/WebserviceRequest.cfc, line 482#012/opt/tomcat-instance06/webapps/ROOT/model/WebserviceRequest.cfc, line 482#012/opt/tomcat-instance06/webapps/ROOT/model/WebserviceRequest.cfc, line 482#012/opt/tomcat-instance06/webapps/ROOT/model/WebserviceRequest.cfc, line 482#012/opt/tomcat-instance06/webapps/ROOT/model/WebserviceRequest.cfc, l...

Message from [email protected] at Jun 22 16:52:12 ...
 482#012/opt/tomcat-instance06/webapps/ROOT/model/WebserviceRequest.cfc, line 482#012/opt/tomcat-instance06/webapps/ROOT/model/WebserviceRequest.cfc, line 268#012/opt/tomcat-instance06/webapps/ROOT/model/website/PageService.cfc, line 194#012/opt/tomcat-instance06/webapps/ROOT/model/website/PageService.cfc, line 86#012/opt/tomcat-instance06/webapps/ROOT/model/RequestContextDecorator.cfc, line 16#012/opt/tomcat-instance06/webapps/ROOT/model/RequestContextDecorator.cfc, line 232#012/opt/tomcat-instance06/webapps/ROOT/handlers/General.cfc, line 596#012/opt/tomcat-instance06/webapps/ROOT/coldbox/system/web/Controller.cfc, line 764#012/opt/tomcat-instance06/webapps/ROOT/coldbox/system/web/Controller.cfc, line 648#012/opt/tomcat-instance06/webapps/ROOT/coldbox/system/web/services/ExceptionService.cfc, line 51#012/opt/tomcat-instance06/webapps/ROOT/coldbox/system/Coldbox.cfc, line 350#012/opt/tomcat-instance06/webapps/ROOT/coldbox/system/Coldbox.cfc, line 382#012/opt/tomcat-instance06/webapps/ROOT/Application.cfc, line 60

這是以下內容/etc/rsyslog.conf

#
# Use traditional timestamp format
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat

# Provides kernel logging support (previously done by rklogd)
$ModLoad imklog

# Provides --MARK-- message capability
$ModLoad immark

# Provides support for local system logging (e.g. via logger command)
$ModLoad  imuxsock

# set ratelimit interval
$SystemLogRateLimitInterval 2
$SystemLogRateLimitBurst 150

# Provides UDP syslog reception
$ModLoad  imudp

# Syslog server listen address
$UDPServerAddress 127.0.0.1

# Syslog server listen UDP port
$UDPServerRun 514

# Log all kernel messages to the console.
# Logging much else clutters up the screen.
kern.*                                                  /dev/console

# Log anything (except mail) of level info or higher.
# Don't log private authentication messages!
*.info;mail.none;authpriv.none;cron.none;local0.none;local6.none  /var/log/messages

# The authpriv file has restricted access.
authpriv.*                                                        /var/log/secure
# Log all the mail messages in one place.
mail.*                                                           -/var/log/mail.log

# Log cron stuff
cron.*                                                            /var/log/cron

# Everybody gets emergency messages
*.emerg                                                           *

# Save news errors of level crit and higher in a special file.
uucp,news.crit                                                    /var/log/spooler

# Save boot messages also to boot.log
local6.warning                                                    /var/log/audit_orcl.log
LOCAL6.WARNING                                                    /var/log/audit_orcl.log

# Save boot messages also to boot.log
local7.*                                                          /var/log/boot.log

# Log all messages to the following syslog servers
<I have removed this section containing ip's of syslogservers>

在 /etc/rsyslog.conf 中嘗試註解掉 kern.*

#kern.*                                                  /dev/console

但重新啟動 rsyslog 後,它仍然將這些 tomcat 訊息記錄到控制台:(

知道在哪裡可以停用這些訊息嗎?

答案1

找到了(廢話)。

/etc/rsyslog.conf在停止訊息中註解掉這一點:

# Everybody gets emergency messages
*.emerg                        *

並且還發現,tomcat 是唯一連續記錄此日誌的應用程序,這是由於編程錯誤的應用程式將每個訊息記錄為致命訊息,導致其轉到控制台。

相關內容