kittu
kittu

Reputation: 7018

unable to generate log file using log4j

I am using tomcat 6 with eclipse Luna (Along with axis2 for webservices). I have imported the required log4j jar file(log4j-1.2.17.jar) and inserted the following line in the class also

static org.apache.log4j.Logger log = Logger.getLogger(WS.class);

Here is the properties file:

# Define the root logger with appender file
log4j.rootLogger = DEBUG, FILE

# Define the file appender
log4j.appender.FILE=org.apache.log4j.FileAppender
# Set the name of the file
log4j.appender.FILE.File=log.txt

# Set the immediate flush to true (default)
log4j.appender.FILE.ImmediateFlush=true

# Set the threshold to debug mode
log4j.appender.FILE.Threshold=debug

# Set the append to false, overwrite
log4j.appender.FILE.Append=true

# Define the layout for file appender
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.conversionPattern= %d{dd MMM yyyy HH:mm:ss,SSS} %c %p %t %m%n%n

The properties file is in the src folder and jar file is in the build path of eclipse. I tried all different ways but unable to generate log file.

Upvotes: 1

Views: 1408

Answers (2)

shellbye
shellbye

Reputation: 4858

You should put the properties file in resources folder not src folder.

I just tested your properties file and it's ok. And when I put it in src folder, it did not work.

Upvotes: 1

Ruei-Min Lin
Ruei-Min Lin

Reputation: 89

It happens to me before. It might be the issue of write privilege. Do you try to write to stdout or socket instead of file? If that works, then try to redirect your file output to a tmp directory.

Upvotes: 0

Related Questions