Log4j和Tomcat 8不生成日志并打开JDK

时间:2017-05-01 11:37:32

标签: logging java-8 log4j tomcat8

我正在尝试使用Log4j,Tomcat 8和OpenJDK 8生成日志。

我尝试了$ {catalina.home}和$ {catalina.base}

我使用THIS URL安装了我的tomcat。

但是日志/文件夹中没有生成日志。

目前,我正在使用Log4j的以下属性

# Root logger option
log4j.rootLogger=DEBUG ,file ,stdout ,upload

# Redirect log messages to console
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %C{1}:%L - %m%n

# Redirect log messages to a log file
log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
log4j.appender.file.DatePattern='.'yyyy-MM-dd
log4j.appender.file.File=${catalina.home}/logs/filelog.log
log4j.appender.file.MaxFileSize=20MB
log4j.appender.file.MaxBackupIndex=1
log4j.appender.file.Append=true
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %C{1}:%L - %m%n
#log4j.additivity.file=false

# Redirect log messages to a log file
log4j.appender.upload=org.apache.log4j.DailyRollingFileAppender
log4j.appender.upload.DatePattern='.'yyyy-MM-dd
log4j.appender.upload.File=${catalina.home}/logs/file_upload_log.log
log4j.appender.upload.MaxFileSize=20MB
log4j.appender.upload.MaxBackupIndex=1
log4j.appender.upload.Append=true
log4j.appender.upload.layout=org.apache.log4j.PatternLayout
log4j.appender.upload.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %C{1}:%L - %m%n
#log4j.additivity.upload=false

提供配置的文件" /etc/systemd/system/tomcat.service"如下所示。

[Unit]
Description=Apache Tomcat Web Application Container
After=network.target

[Service]
Type=forking

Environment=JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/jre/
Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat
Environment=CATALINA_BASE=/opt/tomcat
Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server - XX:+UseParallelGC'
Environment='JAVA_OPTS=-Djava.awt.headless=true -    Djava.security.egd=file:/dev/./urandom'

ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh

User=tomcat
Group=tomcat
UMask=0007
RestartSec=10
Restart=always

[Install]
WantedBy=multi-user.target

根据上述文件,CATALINA_HOME应为/ opt / tomcat

提前致谢。

1 个答案:

答案 0 :(得分:0)

@Pranav Pathak,我想你缺少log4j库来添加tomcat本身的依赖。

查看官方文档,tomcat logging using log4j,(使用 log4j 部分)