I'm having a problem creating my own logs for a application that I'm developing in my work, the next code that I have works perfectly running in a single class method with Main.
try {
LogManager lm = LogManager.getLogManager();
Logger logger;
FileHandler fh = new FileHandler(fileLogger,true);
logger = Logger.getLogger(fileLogger);
lm.addLogger(logger);
logger.setLevel(level);
fh.setFormatter(new SimpleFormatter());
logger.log(level, message);
logger.addHandler(fh);
fh.close();
} catch (Exception e) {
System.out.println("Exception thrown: " + e);
e.printStackTrace();
}
But, when I want to call this function in a doGet 开发者_C百科webService, the log is appended in the catalina log and not in the one that I'm creating. I know that the catalina appends all the information of the call to the webservice but, how I can to create a new log for certain calls that I want?
Thanks!!
You should be looking at logging frameworks like log4j and logback which gives you lot of flexibility in logging. I used log back to create my own log files.
精彩评论