Forums Register Login

log4j apache-log4j-1.2.17 DEBUG

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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 log4j.properties 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("appname.properties"));
}
catch (IOException ex)
{
ex.printStackTrace();
logger.fatal(ex.getMessage());
System.exit(1);
}
try
{
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);
logger.setLevel(logLevel);
logger.addAppender(appender);

}
girl power ... turns out to be about a hundred watts. But they seriuosly don't like being connected to the grid. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 947 times.
Similar Threads
Log4j and appenders
log4j excessive logging
How to disable struts debug/info messages
Log4j and WSAD 5.0
Why do I get "log4j:WARN No appenders could be found for logger" message on server st
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 10:08:06.