I use this class to do JDK-> commons-logging (which could either be modified to go directly to log4j or, just through CL and then to log4j)...
import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Handler; import java.util.logging.Level; import java.util.logging.LogManager; import java.util.logging.LogRecord; import java.util.logging.Logger; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** * Writes JDK log messages to commons logging. * * @see "http://wiki.apache.org/myfaces/Trinidad_and_Common_Logging" */ public class JavaLoggingToCommonLoggingRedirector { static JDKLogHandler activeHandler; /** * Activates this feature. */ public static void activate() { try { Logger rootLogger = LogManager.getLogManager().getLogger(""); // remove old handlers for (Handler handler : rootLogger.getHandlers()) { rootLogger.removeHandler(handler); } // add our own activeHandler = new JDKLogHandler(); activeHandler.setLevel(Level.ALL); rootLogger.addHandler(activeHandler); rootLogger.setLevel(Level.ALL); // done, let's check it right away!!! Logger.getLogger(JavaLoggingToCommonLoggingRedirector.class.getName()).info( "activated: sending JDK log messages to Commons Logging"); } catch (Exception exc) { LogFactory.getLog(JavaLoggingToCommonLoggingRedirector.class).error("activation failed", exc); } } public static void deactivate() { Logger rootLogger = LogManager.getLogManager().getLogger(""); rootLogger.removeHandler(activeHandler); Logger.getLogger(JavaLoggingToCommonLoggingRedirector.class.getName()).info("dactivated"); } protected static class JDKLogHandler extends Handler { private Map<String, Log> cachedLogs = new ConcurrentHashMap<String, Log>(); private Log getLog(String logName) { Log log = this.cachedLogs.get(logName); if (log == null) { log = LogFactory.getLog(logName); this.cachedLogs.put(logName, log); } return log; } @Override public void publish(LogRecord record) { Log log = this.getLog(record.getLoggerName()); String message = record.getMessage(); Throwable exception = record.getThrown(); Level level = record.getLevel(); if (level == Level.SEVERE) { log.error(message, exception); } else if (level == Level.WARNING) { log.warn(message, exception); } else if (level == Level.INFO) { log.info(message, exception); } else if (level == Level.CONFIG) { log.debug(message, exception); } else { log.trace(message, exception); } } @Override public void flush() { // nothing to do } @Override public void close() { // nothing to do } } } On Fri, Apr 2, 2010 at 12:14 PM, Scott Ferguson <[email protected]> wrote: > Stargazer wrote: > > If I have an entry in log4j.properties like this > > > > log4j.rootCategory=DEBUG, Console, R > > log4j.appender.R=org.apache.log4j.RollingFileAppender > > log4j.appender.R.File=log/mywebapp.log > > ... > > > > the logs from the webapp appear in $RESIN_HOME/log. Is there an entry I > > can use to get them to appear in the webapps WEB-INF/log without having > > to hard code the path please? > > > I'm not as familiar with log4j as I should be. Is there a configuration > to send the results to java.util.logging? All of Resin's logging is > built around the JDK's logging system. > > -- Scott > > > > > > _______________________________________________ > > resin-interest mailing list > > [email protected] > > http://maillist.caucho.com/mailman/listinfo/resin-interest > > > > > > > > _______________________________________________ > resin-interest mailing list > [email protected] > http://maillist.caucho.com/mailman/listinfo/resin-interest >
_______________________________________________ resin-interest mailing list [email protected] http://maillist.caucho.com/mailman/listinfo/resin-interest
