File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Other Open Source Projects and the fly likes log4j apache-log4j-1.2.17 DEBUG Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "log4j apache-log4j-1.2.17 DEBUG" Watch "log4j apache-log4j-1.2.17 DEBUG" New topic

log4j apache-log4j-1.2.17 DEBUG

joao coelho

Joined: Mar 28, 2005
Posts: 11
I installed this version of log4j for a small application that is console based. I noticed the install file only indicates to put the path of log4j in the classpath. After installing it, i started using log4j and it works great, except that it keeps showing me DEBUG messages which i do not want. Since i did not have a properties file as the install did not indicate it as a requirement, i have no idea as to how to prevent the DEBUG messages, i only want fatal messages which i coded using Logger.fatal and i even set up the Logger.setLevel to Fatal. What am i doing wrong and do i need a log4j properties file, and if so, where would i place such a file?
Thank you.

joao coelho

Joined: Mar 28, 2005
Posts: 11
This question certainly was a newbie. I finaly figured out a way to handle this problem. One of the reasons why i did not want to use the properties file was that the log file for log4j had to be named dynamically using current date. Maybe my choice was not the best but here it is in case someone else runs into this problem. In my properties file for the application, not the file, i added a key for the severity level.
Then all i did was to get my filename then i obtain the lo4j level. then i get a patternlayout and a new FileAppender with the layout and filename for parameters. Then i call Logger.getRootLogger and finally i add the appender to the logger and that did the job.

properties = new Properties();
try {
properties.load(new FileInputStream(""));
catch (IOException ex)
logFilename = new String();
String filename = properties.getProperty("process_xxx_error_log");
String level = properties.getProperty("log4j_level");
//add date to filename.
logFilename = GetFileName(filename);
PatternLayout layout = new PatternLayout("%d{dd MMM yyyy HH:mm:ss} %-r [%t] %-5p %x - %m%n");
appender = new FileAppender(layout,logFilename);
logger = Logger.getRootLogger();

Level logLevel = getLog4jLevel(level);

I agree. Here's the link:
subject: log4j apache-log4j-1.2.17 DEBUG
It's not a secret anymore!