這幾天工作上有針對日誌設定做討論,但是單純對tomcat 日誌設定似乎缺少了實做探究,於是在下班之餘稍微探究了一下。今天先對日誌格式做研究。
在官網對於 log 工具預設是由 java 原生日誌工具處理 java.util.logging
原始設定
以下是 tomcat9 對 log 的始設定檔
- conf/logging.properties
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
handlers = 1catalina.org.apache.juli.AsyncFileHandler, 2localhost.org.apache.juli.AsyncFileHandler, 3manager.org.apache.juli.AsyncFileHandler, 4host-manager.org.apache.juli.AsyncFileHandler, java.util.logging.ConsoleHandler
.handlers = 1catalina.org.apache.juli.AsyncFileHandler, java.util.logging.ConsoleHandler
############################################################
# Handler specific properties.
# Describes specific configuration info for Handlers.
############################################################
1catalina.org.apache.juli.AsyncFileHandler.level = ALL
1catalina.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs
1catalina.org.apache.juli.AsyncFileHandler.prefix = catalina.
1catalina.org.apache.juli.AsyncFileHandler.maxDays = 90
1catalina.org.apache.juli.AsyncFileHandler.encoding = UTF-8
2localhost.org.apache.juli.AsyncFileHandler.level = ALL
2localhost.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs
2localhost.org.apache.juli.AsyncFileHandler.prefix = localhost.
2localhost.org.apache.juli.AsyncFileHandler.maxDays = 90
2localhost.org.apache.juli.AsyncFileHandler.encoding = UTF-8
3manager.org.apache.juli.AsyncFileHandler.level = ALL
3manager.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs
3manager.org.apache.juli.AsyncFileHandler.prefix = manager.
3manager.org.apache.juli.AsyncFileHandler.maxDays = 90
3manager.org.apache.juli.AsyncFileHandler.encoding = UTF-8
4host-manager.org.apache.juli.AsyncFileHandler.level = ALL
4host-manager.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs
4host-manager.org.apache.juli.AsyncFileHandler.prefix = host-manager.
4host-manager.org.apache.juli.AsyncFileHandler.maxDays = 90
4host-manager.org.apache.juli.AsyncFileHandler.encoding = UTF-8
java.util.logging.ConsoleHandler.level = ALL
java.util.logging.ConsoleHandler.formatter = org.apache.juli.OneLineFormatter
java.util.logging.ConsoleHandler.encoding = UTF-8
############################################################
# Facility specific properties.
# Provides extra control for each logger.
############################################################
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].level = INFO
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].handlers = 2localhost.org.apache.juli.AsyncFileHandler
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].level = INFO
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].handlers = 3manager.org.apache.juli.AsyncFileHandler
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager].level = INFO
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager].handlers = 4host-manager.org.apache.juli.AsyncFileHandler
# For example, set the org.apache.catalina.util.LifecycleBase logger to log
# each component that extends LifecycleBase changing state:
#org.apache.catalina.util.LifecycleBase.level = FINE
# To see debug messages for HTTP/2 handling, uncomment the following line:
#org.apache.coyote.http2.level = FINE
# To see debug messages for WebSocket handling, uncomment the following line:
#org.apache.tomcat.websocket.level = FINE
探究項目
在這邊有發現日誌格式主要是由 java.util.logging.ConsoleHandler.formatter
進行設定
操作環境如下:
- OS: Oracle Linux 9
- tomcat verion: Apache Tomcat/9.0.98
- java Option:
-Duser.language=zh -Duser.region=TW
以下是設定值與對應的輸出出結果
java.util.logging.ConsoleHandler.formatter
值: org.apache.juli.OneLineFormatter
輸出內容如下:
NOTE: Picked up JDK_JAVA_OPTIONS: --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED
OpenJDK 64-Bit Server VM warning: Option UseBiasedLocking was deprecated in version 15.0 and will likely be removed in a future release.
02-Jan-2025 23:35:12.075 警告 [main] org.apache.tomcat.util.digester.SetPropertiesRule.begin Match [Server/Service/Engine/Host] failed to set property [reloadable] to [false]
02-Jan-2025 23:35:12.094 資訊 [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent The Apache Tomcat Native library which allows using OpenSSL was not found on the java.library.path: [/usr/java/packages/lib:/usr/lib64:/lib64:/lib:/usr/lib]
02-Jan-2025 23:35:12.288 資訊 [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio2-10010"]
02-Jan-2025 23:35:12.315 資訊 [main] org.apache.catalina.startup.Catalina.load Server initialization in [331] milliseconds
02-Jan-2025 23:35:12.341 資訊 [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
02-Jan-2025 23:35:12.341 資訊 [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet engine: [Apache Tomcat/9.0.98]
02-Jan-2025 23:35:12.346 資訊 [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/data/webapps/w1/grailsException]
02-Jan-2025 23:35:14.411 資訊 [main] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
02-Jan-2025 23:35:20.530 資訊 [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/data/webapps/w1/grailsException] has finished in [8,184] ms
02-Jan-2025 23:35:20.599 資訊 [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio2-10010"]
02-Jan-2025 23:35:20.604 資訊 [main] org.apache.catalina.startup.Catalina.start Server startup in [8288] milliseconds
02-Jan-2025 23:36:11.754 資訊 [Thread-7] org.apache.coyote.AbstractProtocol.pause Pausing ProtocolHandler ["http-nio2-10010"]
02-Jan-2025 23:36:11.766 資訊 [Thread-7] org.apache.catalina.core.StandardService.stopInternal Stopping service [Catalina]
02-Jan-2025 23:36:11.822 資訊 [Thread-7] org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler ["http-nio2-10010"]
02-Jan-2025 23:36:11.824 資訊 [Thread-7] org.apache.coyote.AbstractProtocol.destroy Destroying ProtocolHandler ["http-nio2-10010"]
值: org.apache.juli.VerbatimFormatter
輸出內容如下:
NOTE: Picked up JDK_JAVA_OPTIONS: --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED
OpenJDK 64-Bit Server VM warning: Option UseBiasedLocking was deprecated in version 15.0 and will likely be removed in a future release.
Match [Server/Service/Engine/Host] failed to set property [reloadable] to [false]
The Apache Tomcat Native library which allows using OpenSSL was not found on the java.library.path: [/usr/java/packages/lib:/usr/lib64:/lib64:/lib:/usr/lib]
Initializing ProtocolHandler ["http-nio2-10010"]
Server initialization in [327] milliseconds
Starting service [Catalina]
Starting Servlet engine: [Apache Tomcat/9.0.98]
Deploying web application directory [/data/webapps/w1/grailsException]
At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Deployment of web application directory [/data/webapps/w1/grailsException] has finished in [8,438] ms
Starting ProtocolHandler ["http-nio2-10010"]
Server startup in [8479] milliseconds
值: org.apache.juli.JdkLoggerFormatter
輸出內容如下:
NOTE: Picked up JDK_JAVA_OPTIONS: --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED
OpenJDK 64-Bit Server VM warning: Option UseBiasedLocking was deprecated in version 15.0 and will likely be removed in a future release.
1735832335650 W Digester Match [Server/Service/Engine/Host] failed to set property [reloadable] to [false]
1735832335665 I AprLifecycleListener The Apache Tomcat Native library which allows using OpenSSL was not found on the java.library.path: [/usr/java/packages/lib:/usr/lib64:/lib64:/lib:/usr/lib]
1735832335807 I Http11Nio2Protocol Initializing ProtocolHandler ["http-nio2-10010"]
1735832335847 I Catalina Server initialization in [299] milliseconds
1735832335876 I StandardService Starting service [Catalina]
1735832335877 I StandardEngine Starting Servlet engine: [Apache Tomcat/9.0.98]
1735832335881 I HostConfig Deploying web application directory [/data/webapps/w1/grailsException]
1735832338012 I TldScanner At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
1735832344553 I HostConfig Deployment of web application directory [/data/webapps/w1/grailsException] has finished in [8,672] ms
1735832344556 I Http11Nio2Protocol Starting ProtocolHandler ["http-nio2-10010"]
1735832344558 I Catalina Server startup in [8710] milliseconds
值: java.util.logging.SimpleFormatter
輸出內容如下:
NOTE: Picked up JDK_JAVA_OPTIONS: --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED
OpenJDK 64-Bit Server VM warning: Option UseBiasedLocking was deprecated in version 15.0 and will likely be removed in a future release.
1月 03, 2025 12:06:24 上午 org.apache.tomcat.util.digester.SetPropertiesRule begin
警告: Match [Server/Service/Engine/Host] failed to set property [reloadable] to [false]
1月 03, 2025 12:06:24 上午 org.apache.catalina.core.AprLifecycleListener lifecycleEvent
資訊: The Apache Tomcat Native library which allows using OpenSSL was not found on the java.library.path: [/usr/java/packages/lib:/usr/lib64:/lib64:/lib:/usr/lib]
1月 03, 2025 12:06:24 上午 org.apache.coyote.AbstractProtocol init
資訊: Initializing ProtocolHandler ["http-nio2-10010"]
1月 03, 2025 12:06:25 上午 org.apache.catalina.startup.Catalina load
資訊: Server initialization in [326] milliseconds
1月 03, 2025 12:06:25 上午 org.apache.catalina.core.StandardService startInternal
資訊: Starting service [Catalina]
1月 03, 2025 12:06:25 上午 org.apache.catalina.core.StandardEngine startInternal
資訊: Starting Servlet engine: [Apache Tomcat/9.0.98]
1月 03, 2025 12:06:25 上午 org.apache.catalina.startup.HostConfig deployDirectory
資訊: Deploying web application directory [/data/webapps/w1/grailsException]
1月 03, 2025 12:06:27 上午 org.apache.jasper.servlet.TldScanner scanJars
資訊: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
1月 03, 2025 12:06:33 上午 org.apache.catalina.startup.HostConfig deployDirectory
資訊: Deployment of web application directory [/data/webapps/w1/grailsException] has finished in [8,700] ms
1月 03, 2025 12:06:33 上午 org.apache.coyote.AbstractProtocol start
資訊: Starting ProtocolHandler ["http-nio2-10010"]
1月 03, 2025 12:06:33 上午 org.apache.catalina.startup.Catalina start
資訊: Server startup in [8744] milliseconds
值: java.util.logging.XMLFormatter
輸出內容如下:
NOTE: Picked up JDK_JAVA_OPTIONS: --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED
OpenJDK 64-Bit Server VM warning: Option UseBiasedLocking was deprecated in version 15.0 and will likely be removed in a future release.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE log SYSTEM "logger.dtd">
<log>
<record>
<date>2025-01-02T16:08:13.008713022Z</date>
<millis>1735834093008</millis>
<nanos>713022</nanos>
<sequence>0</sequence>
<logger>org.apache.tomcat.util.digester.Digester</logger>
<level>WARNING</level>
<class>org.apache.tomcat.util.digester.SetPropertiesRule</class>
<method>begin</method>
<thread>1</thread>
<message>Match [Server/Service/Engine/Host] failed to set property [reloadable] to [false]</message>
</record>
<record>
<date>2025-01-02T16:08:13.021339079Z</date>
<millis>1735834093021</millis>
<nanos>339079</nanos>
<sequence>1</sequence>
<logger>org.apache.catalina.core.AprLifecycleListener</logger>
<level>INFO</level>
<class>org.apache.catalina.core.AprLifecycleListener</class>
<method>lifecycleEvent</method>
<thread>1</thread>
<message>The Apache Tomcat Native library which allows using OpenSSL was not found on the java.library.path: [/usr/java/packages/lib:/usr/lib64:/lib64:/lib:/usr/lib]</message>
</record>
<record>
<date>2025-01-02T16:08:13.162949950Z</date>
<millis>1735834093162</millis>
<nanos>949950</nanos>
<sequence>2</sequence>
<logger>org.apache.coyote.http11.Http11Nio2Protocol</logger>
<level>INFO</level>
<class>org.apache.coyote.AbstractProtocol</class>
<method>init</method>
<thread>1</thread>
<message>Initializing ProtocolHandler ["http-nio2-10010"]</message>
</record>
<record>
<date>2025-01-02T16:08:13.199216579Z</date>
<millis>1735834093199</millis>
<nanos>216579</nanos>
<sequence>3</sequence>
<logger>org.apache.catalina.startup.Catalina</logger>
<level>INFO</level>
<class>org.apache.catalina.startup.Catalina</class>
<method>load</method>
<thread>1</thread>
<message>Server initialization in [320] milliseconds</message>
</record>
<record>
<date>2025-01-02T16:08:13.228305592Z</date>
<millis>1735834093228</millis>
<nanos>305592</nanos>
<sequence>4</sequence>
<logger>org.apache.catalina.core.StandardService</logger>
<level>INFO</level>
<class>org.apache.catalina.core.StandardService</class>
<method>startInternal</method>
<thread>1</thread>
<message>Starting service [Catalina]</message>
</record>
<record>
<date>2025-01-02T16:08:13.228692741Z</date>
<millis>1735834093228</millis>
<nanos>692741</nanos>
<sequence>5</sequence>
<logger>org.apache.catalina.core.StandardEngine</logger>
<level>INFO</level>
<class>org.apache.catalina.core.StandardEngine</class>
<method>startInternal</method>
<thread>1</thread>
<message>Starting Servlet engine: [Apache Tomcat/9.0.98]</message>
</record>
<record>
<date>2025-01-02T16:08:13.234136370Z</date>
<millis>1735834093234</millis>
<nanos>136370</nanos>
<sequence>6</sequence>
<logger>org.apache.catalina.startup.HostConfig</logger>
<level>INFO</level>
<class>org.apache.catalina.startup.HostConfig</class>
<method>deployDirectory</method>
<thread>1</thread>
<message>Deploying web application directory [/data/webapps/w1/grailsException]</message>
</record>
<record>
<date>2025-01-02T16:08:15.464016570Z</date>
<millis>1735834095464</millis>
<nanos>16570</nanos>
<sequence>7</sequence>
<logger>org.apache.jasper.servlet.TldScanner</logger>
<level>INFO</level>
<class>org.apache.jasper.servlet.TldScanner</class>
<method>scanJars</method>
<thread>1</thread>
<message>At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.</message>
</record>
<record>
<date>2025-01-02T16:08:21.824003613Z</date>
<millis>1735834101824</millis>
<nanos>3613</nanos>
<sequence>8</sequence>
<logger>org.apache.catalina.startup.HostConfig</logger>
<level>INFO</level>
<class>org.apache.catalina.startup.HostConfig</class>
<method>deployDirectory</method>
<thread>1</thread>
<message>Deployment of web application directory [/data/webapps/w1/grailsException] has finished in [8,589] ms</message>
</record>
<record>
<date>2025-01-02T16:08:21.825764012Z</date>
<millis>1735834101825</millis>
<nanos>764012</nanos>
<sequence>9</sequence>
<logger>org.apache.coyote.http11.Http11Nio2Protocol</logger>
<level>INFO</level>
<class>org.apache.coyote.AbstractProtocol</class>
<method>start</method>
<thread>1</thread>
<message>Starting ProtocolHandler ["http-nio2-10010"]</message>
</record>
<record>
<date>2025-01-02T16:08:21.830333429Z</date>
<millis>1735834101830</millis>
<nanos>333429</nanos>
<sequence>10</sequence>
<logger>org.apache.catalina.startup.Catalina</logger>
<level>INFO</level>
<class>org.apache.catalina.startup.Catalina</class>
<method>start</method>
<thread>1</thread>
<message>Server startup in [8630] milliseconds</message>
</record>
至於套用 log4j 或是 slf4j 就不在此篇範圍了,因為我要去睡覺了