Hi Jeff, Thanks for responding. I have written a simple Listener class that is loaded at startup by Tomcat, which makes a static logger available to the web-app (both as a static getter and a servlet context param), and I have no problem using it from other areas such as jsp or servlets or non-maverick pojo's. The logger itself is a simple custom jdk1.4 logger (ie not log4j) and uses a very simple formatter. It uses a FileHandler that points to a txt file in WEB-INF. No errors appear to be generated and as far as I'm aware there are no weird classloader issues. here is the Listener that creates the logger: public class SiteLogger implements ServletContextListener { private static Logger logger; public static Logger getLogger() { return logger; } public void contextInitialized(ServletContextEvent e) { ServletContext sc = e.getServletContext(); // get logger instance. logger = Logger.getLogger("global"); // TODO: Should really be injected. logger.setLevel(Level.INFO); try { FileHandler fh = null; String root = sc.getRealPath("/"); // TODO: Again value should be injected. fh = new FileHandler(root+"WEB-INF/log.txt"); CustomFormatter cf = new CustomFormatter(); fh.setFormatter(cf); logger.addHandler(fh); } catch(IOException ioe) { System.err.println("Can't load logger" + ioe.getMessage()); } sc.setAttribute("fw.logging.SiteLogger", logger); } ...etc here is the web.xml entry for the listener: <listener> <listener-class>fw.logging.SiteLogger</listener-class> </listener> here is the code that does the logging in the controller's perform() method: import fw.logging.SiteLogger; ... SiteLogger.getLogger().log(Level.INFO, obj); LM Jeff Schnitzer wrote: Unfortunately I'm pretty sure that's going to be far too general a question. You need to explain how your logging framework works if anyone's going to be able to help you. Does it do anything weird with classloaders? |
- [Mav-user] Logging from controller Louis Malenica
- Re: [Mav-user] Logging from controller Jeff Schnitzer
- Re: [Mav-user] Logging from controller Louis Malenica