Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Log4J too many files

Status
Not open for further replies.

kirankanukuntla

Programmer
May 21, 2007
1
US
Hi I am using Log4j.
I have created one utility class which I use in other classes to get the logger.
public class CommonLogger {



private static Logger logur;



private TimeLogger() {

}



private static Logger Logur(String className) {

Configuration configur = null;



//default values for logging

String pattern = null, logFile = null, level = null;



try {

configur = new PropertiesConfiguration("/WEB-INF/Time.properties");

pattern = configur.getString("Log4j.pattern");

logFile = configur.getString("Log4J.path.logFile");

level = configur.getString("Log4J.level").toUpperCase();

logur = Logger.getLogger(className);

PatternLayout patternLayout = new PatternLayout(pattern);

FileAppender appender = null;

try {

appender = new FileAppender(patternLayout, logFile, true);

} catch (IOException ioe) {

System.out.println("Exception in class="+ className+" method="+"Logur"

+ " " + ioe.getMessage());

}

logur.addAppender(appender);



if ("INFO".equals(level))

logur.setLevel((Level) Level.INFO);

else if ("DEBUG".equals(level))

logur.setLevel((Level) Level.DEBUG);

else if ("ERROR".equals(level))

logur.setLevel((Level) Level.ERROR);

else if ("FATAL".equals(level))

logur.setLevel((Level) Level.FATAL);

else if ("TRACE".equals(level))

logur.setLevel((Level) Level.TRACE);

else if ("WARN".equals(level))

logur.setLevel((Level) Level.WARN);

else

logur.setLevel((Level) Level.INFO);



} catch (ConfigurationException ce) {

System.out.println("ConfigurationException in class=" + className+" method="

+ "Logur. " + ce.getMessage());

}

return logur;

}



public static Logger getLogger(String className) {

logur = Logur(className);

return logur;

}







}


I use this class in other classes to get logger like,
Logger logger = CommonLogger.getLogger(SomeDao.class.getName());

Its opening too many file descriptors and giving me the message too many files open.

I dont know how to limit number of open file descriptors.
What mistake am i doing
Any light on this?
Thanks in advance.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top