aspose file tools*
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 Spring in Action this week in the Spring 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
Author

log4j apache-log4j-1.2.17 DEBUG

joao coelho
Greenhorn

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.


ofilha
joao coelho
Greenhorn

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 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);

}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: log4j apache-log4j-1.2.17 DEBUG