简体   繁体   中英

How to log in root project with Log4j

I want to log in my project, but it is logging on my desktop by default. How can I fix it?

Here are the log4j.properties

log4j.rootLogger=DEBUG, stdout, FILE
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d [%-5p] (%F:%M:%L) %m%n

# Define the file appender
log4j.appender.FILE=org.apache.log4j.FileAppender
log4j.appender.FILE.File=logs/joss.log

# Define the layout for file appender
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.ConversionPattern=%d [%-5p] (%F:%M:%L) %m%n

Edit log4j.appender.FILE.File where you want to save location.

I think your project is located at your desktop so log4j is logging on your desktop because your log4j.properties is written by logs/joss.log

AS-IS

log4j.appender.FILE.File=logs/joss.log

TO-BE

log4j.appender.FILE.File=C:/LOGGING_FILES_DIRECTORY/LOG_FILE_NAME.log

or just change from absolute path to relative path like below properties value. Then the log file(=joss.log) will be saved in your project directory([project root]/logs/joss.log).

log4j.appender.FILE.File=./logs/joss.log

I resolve the problem, it was because of this:

在此处输入图像描述

In Tomcat run configurations, you can specify the working folder, which is normally parameter inside some Tomcat conf file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM