bl双性强迫侵犯h_国产在线观看人成激情视频_蜜芽188_被诱拐的少孩全彩啪啪漫画

Tomcat的支持log4j及日志輸出為json格式是怎樣的

今天就跟大家聊聊有關Tomcat的支持log4j及日志輸出為json格式是怎樣的,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結了以下內容,希望大家根據(jù)這篇文章可以有所收獲。

創(chuàng)新互聯(lián)專注于塔什庫爾干塔吉克網站建設服務及定制,我們擁有豐富的企業(yè)做網站經驗。 熱誠為您提供塔什庫爾干塔吉克營銷型網站建設,塔什庫爾干塔吉克網站制作、塔什庫爾干塔吉克網頁設計、塔什庫爾干塔吉克網站官網定制、小程序制作服務,打造塔什庫爾干塔吉克網絡公司原創(chuàng)品牌,更為您提供塔什庫爾干塔吉克網站排名全網營銷落地服務。

1.下載apache-tomcat-7.0.42及解壓

[root@sht-sgmhadoopnn-01 app]# pwd
/root/learnproject/app
[root@sht-sgmhadoopnn-01 app]# wget http://archive.apache.org/dist/tomcat/tomcat-7/v7.0.42/bin/apache-tomcat-7.0.42.tar.gz
[root@sht-sgmhadoopnn-01 app]# tar -xzvf apache-tomcat-7.0.42.tar.gz

2.下載 tomcat-juli.jar and tomcat-juli-adapters.jar

[root@sht-sgmhadoopnn-01 app]# cd apache-tomcat-7.0.42/lib/
[root@sht-sgmhadoopnn-01 lib]# wget http://archive.apache.org/dist/tomcat/tomcat-7/v7.0.42/bin/extras/tomcat-juli-adapters.jar

3.下載 Download Log4J (Tomcat requires v1.2.x)

[root@sht-sgmhadoopnn-01 lib]# wget https://archive.apache.org/dist/logging/log4j/1.2.17/log4j-1.2.17.jar


4.替換 $CATALINA_HOME/bin/tomcat-juli.jar

[root@sht-sgmhadoopnn-01 lib]# cd ../bin[root@sht-sgmhadoopnn-01 bin]# mv tomcat-juli.jar tomcat-juli.jar.bak[root@sht-sgmhadoopnn-01 bin]# wget http://archive.apache.org/dist/tomcat/tomcat-7/v7.0.42/bin/extras/tomcat-juli.jar

5.重命名 $CATALINA_BASE/conf/logging.properties to prevent java.util.logging generating zero length log files.

[root@sht-sgmhadoopnn-01 lib]# cd ../conf
[root@sht-sgmhadoopnn-01 conf]# mv logging.properties  logging.properties.bak
[root@sht-sgmhadoopnn-01 conf]#

6.修改conf/context.xml ,將<Context>為<Context swallowOutput="true">

[root@sht-sgmhadoopnn-01 conf]# vi context.xml
<Context swallowOutput="true">

7.創(chuàng)建log4j.properties,其catalina日志為滾動日志,json格式輸出
[root@sht-sgmhadoopnn-01 conf]# cd ../lib

[root@sht-sgmhadoopnn-01 lib]# vi log4j.properties
log4j.rootLogger = INFO, CATALINA

# Define all the appenders
log4j.appender.CATALINA=org.apache.log4j.RollingFileAppender
log4j.appender.CATALINA.File=${catalina.base}/logs/catalina
log4j.appender.CATALINA.layout=org.apache.log4j.PatternLayout
log4j.appender.CATALINA.layout.ConversionPattern={"time":"%d{yyyy-MM-dd HH:mm:ss,SSS}","logtype":"%p","loginfo":"%c:%m"}%n
log4j.appender.CATALINA.MaxFileSize=2MB
log4j.appender.CATALINA.MaxBackupIndex=10

log4j.appender.LOCALHOST = org.apache.log4j.DailyRollingFileAppender
log4j.appender.LOCALHOST.File = ${catalina.base}/logs/localhost
log4j.appender.LOCALHOST.Append = true
log4j.appender.LOCALHOST.Encoding = UTF-8
log4j.appender.LOCALHOST.DatePattern = '.'yyyy-MM-dd'.log'
log4j.appender.LOCALHOST.layout = org.apache.log4j.PatternLayout
log4j.appender.LOCALHOST.layout.ConversionPattern = %d [%t] %-5p %c- %m%n

log4j.appender.MANAGER = org.apache.log4j.DailyRollingFileAppender
log4j.appender.MANAGER.File = ${catalina.base}/logs/manager
log4j.appender.MANAGER.Append = true
log4j.appender.MANAGER.Encoding = UTF-8
log4j.appender.MANAGER.DatePattern = '.'yyyy-MM-dd'.log'
log4j.appender.MANAGER.layout = org.apache.log4j.PatternLayout
log4j.appender.MANAGER.layout.ConversionPattern = %d [%t] %-5p %c- %m%n

log4j.appender.HOST-MANAGER = org.apache.log4j.DailyRollingFileAppender
log4j.appender.HOST-MANAGER.File = ${catalina.base}/logs/host-manager
log4j.appender.HOST-MANAGER.Append = true
log4j.appender.HOST-MANAGER.Encoding = UTF-8
log4j.appender.HOST-MANAGER.DatePattern = '.'yyyy-MM-dd'.log'
log4j.appender.HOST-MANAGER.layout = org.apache.log4j.PatternLayout
log4j.appender.HOST-MANAGER.layout.ConversionPattern = %d [%t] %-5p %c- %m%n

log4j.appender.CONSOLE = org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.Encoding = UTF-8
log4j.appender.CONSOLE.layout = org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern = %d [%t] %-5p %c- %m%n

# Configure which loggers log to which appenders
log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost] = INFO, LOCALHOST
log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager] =\
  INFO, MANAGER
log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager] =\
  INFO, HOST-MANAGER


8.啟動
[root@sht-sgmhadoopnn-01 apache-tomcat-7.0.42]#
[root@sht-sgmhadoopnn-01 apache-tomcat-7.0.42]# bin/startup.sh
Using CATALINA_BASE:   /root/learnproject/app/apache-tomcat-7.0.42
Using CATALINA_HOME:   /root/learnproject/app/apache-tomcat-7.0.42
Using CATALINA_TMPDIR: /root/learnproject/app/apache-tomcat-7.0.42/temp
Using JRE_HOME:        /usr/java/jdk1.7.0_67-cloudera
Using CLASSPATH:       /root/learnproject/app/apache-tomcat-7.0.42/bin/bootstrap.jar:/root/learnproject/app/apache-tomcat-7.0.42/bin/tomcat-juli.jar

9.檢查日志格式
[root@sht-sgmhadoopnn-01 apache-tomcat-7.0.42]# tail -f ./logs/catalina
{"time":"2017-03-31 21:39:27,137","logtype":"INFO","loginfo":"org.apache.catalina.startup.HostConfig:Deploying web application directory /root/learnproject/app/apache-tomcat-7.0.42/webapps/docs"}
{"time":"2017-03-31 21:39:27,231","logtype":"INFO","loginfo":"org.apache.catalina.startup.HostConfig:Deploying web application directory /root/learnproject/app/apache-tomcat-7.0.42/webapps/ROOT"}
{"time":"2017-03-31 21:39:27,311","logtype":"INFO","loginfo":"org.apache.catalina.startup.HostConfig:Deploying web application directory /root/learnproject/app/apache-tomcat-7.0.42/webapps/manager"}
{"time":"2017-03-31 21:39:27,452","logtype":"INFO","loginfo":"org.apache.catalina.startup.HostConfig:Deploying web application directory /root/learnproject/app/apache-tomcat-7.0.42/webapps/examples"}
{"time":"2017-03-31 21:39:27,864","logtype":"INFO","loginfo":"org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/examples]:ContextListener: contextInitialized()"}
{"time":"2017-03-31 21:39:27,865","logtype":"INFO","loginfo":"org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/examples]:SessionListener: contextInitialized()"}
{"time":"2017-03-31 21:39:27,889","logtype":"INFO","loginfo":"org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/examples]:ContextListener: attributeAdded('org.apache.jasper.compiler.TldLocationsCache', 'org.apache.jasper.compiler.TldLocationsCache@6770983a')"}
{"time":"2017-03-31 21:39:27,897","logtype":"INFO","loginfo":"org.apache.coyote.http11.Http11Protocol:Starting ProtocolHandler ["http-bio-8080"]"}
{"time":"2017-03-31 21:39:27,922","logtype":"INFO","loginfo":"org.apache.coyote.ajp.AjpProtocol:Starting ProtocolHandler ["ajp-bio-8009"]"}
{"time":"2017-03-31 21:39:27,929","logtype":"INFO","loginfo":"org.apache.catalina.startup.Catalina:Server startup in 1828 ms"}

【備注】
log4j 的PatternLayout參數(shù)含義速查:

log4j.appender.CATALINA.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss,SSS} %p %c:%m%n

%d{yyyy-MM-dd HH:mm:ss,SSS} : 輸出日期。允許使用%d{yyyy-MM-dd HH:mm:ss}格式化日期

%p: 輸出優(yōu)先級,即DEBUG,INFO,WARN,ERROR,F(xiàn)ATAL

%c: 輸出Logger所在的類別(即Logger的名字)。允許使用%c{數(shù)字}輸出部分的名稱(從右邊往左邊數(shù))

%m: 輸出代碼中指定的消息
%n: 輸出一個回車換行符,Windows平臺為“\r\n”,Unix平臺為“\n”
%l: 輸出日志事件的發(fā)生位置,包括類目名、發(fā)生的線程,以及在代碼中的行數(shù)。舉例:Testlog4.main(TestLog4.java: 10 )

看完上述內容,你們對Tomcat的支持log4j及日志輸出為json格式是怎樣的有進一步的了解嗎?如果還想了解更多知識或者相關內容,請關注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝大家的支持。

當前名稱:Tomcat的支持log4j及日志輸出為json格式是怎樣的
鏈接分享:http://vcdvsql.cn/article4/pocdoe.html

成都網站建設公司_創(chuàng)新互聯(lián),為您提供標簽優(yōu)化企業(yè)建站服務器托管網站收錄網頁設計公司動態(tài)網站

廣告

聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

h5響應式網站建設