简体   繁体   中英

log4j not working in the first time

I am tring to implement log4j for the first time. My log4j.properties file is as given below.

# Define the root logger with appender file
log = /log/log4j
log4j.rootLogger = debug, NewStudentListDAO

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

# Define the layout for file appender
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.conversionPattern=%m%n

I have placed this file under classes folder and src folder. Still it does not give out to file. The log4j is invoked in my class NewStudentListDAO in the following lines. The site is not allowing me to submit this much alone so I am adding some special characters to fill the gap. Kindly ignore the same...

static Logger logger = Logger.getLogger( NewStudentListDAO.class.getName());
logger.setLevel(Level.ALL);
logger.debug("This is debug message from logger");
logger.info("This is info message from logger");
logger.log(Level.DEBUG, "This is a debug message from logger");

Kindly help me in fixing the issue.

Thanks Saji

Try this adding to your logger file, and check whether it is first displaying on your console.

log4j.rootLogger=INFO, CONSOLE
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender

Look at this link

Log4j: How to configure simplest possible file logging? .

I hope it helps.

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