Re: [Resin-interest] Sending log4j logs to the web apps log folder

2010-04-02 Thread Scott Ferguson
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
 resin-interest@caucho.com
 http://maillist.caucho.com/mailman/listinfo/resin-interest

   



___
resin-interest mailing list
resin-interest@caucho.com
http://maillist.caucho.com/mailman/listinfo/resin-interest


Re: [Resin-interest] Sending log4j logs to the web apps log folder

2010-04-02 Thread Jon Stevens
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 MapString, Log cachedLogs = new ConcurrentHashMapString, 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 f...@caucho.com 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
  resin-interest@caucho.com
  http://maillist.caucho.com/mailman/listinfo/resin-interest
 
 



 ___
 resin-interest mailing list
 resin-interest@caucho.com
 http://maillist.caucho.com/mailman/listinfo/resin-interest

___
resin-interest mailing list
resin-interest@caucho.com
http://maillist.caucho.com/mailman/listinfo/resin-interest


Re: [Resin-interest] Sending log4j logs to the web apps log folder

2010-04-02 Thread Scott Ferguson
Jon Stevens wrote:
 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)...
I think he needs the other way around, from log4j to java.util.logging (?)

By the way, in Resin 4.0.6 you'll be able to do the same thing with

resin xmlns=...

system
  logger name= level=
mypkg:JDKLogHandler xmlns=urn:java:org.mycom.mypkg
  levelall/level
/mypkg:JDKLogHandler
  /logger
/system

I'm not sure setting the Logger level to all would be a good idea, 
though, because Logger.isLoggable() would always return true, which 
would harm performance somewhat.

(The system is just to ensure it's configured in the system 
classloader context, since resin is a child of the system loader. And 
at some point I need to look into providing an adapter to log4j handlers 
so you can configure log4j handlers as a java.util.logging handler 
directly in Resin.)

-- Scott

 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 MapString, Log cachedLogs = new ConcurrentHashMapString, 
 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 http://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 f...@caucho.com 
 mailto:f...@caucho.com 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
  resin-interest@caucho.com mailto:resin-interest@caucho.com
  http://maillist.caucho.com/mailman/listinfo/resin-interest
 
 



 ___
 resin-interest mailing list
 resin-interest@caucho.com mailto:resin-interest@caucho.com
 http://maillist.caucho.com/mailman/listinfo/resin-interest


 

 ___
 resin-interest mailing list
 resin-interest@caucho.com
 http://maillist.caucho.com/mailman/listinfo/resin-interest
   



___

Re: [Resin-interest] Sending log4j logs to the web apps log folder

2010-04-02 Thread Chris Pratt
Consider this another vote for a possible switch to using SLF4j as the Resin
logging interface.  It's a very thin API that is an extremely powerful
aggregator of log information.
  (*Chris*)

On Fri, Apr 2, 2010 at 12:57 PM, Jeff Schnitzer j...@infohazard.org wrote:

 I'm pretty sure that it's possible to configure any possible
 combination of input loggers and output destinations by mixing and
 matching the various components of SLF4J.

 To get log4j output to java.util.logging, you could use the
 log4j-slf4j bridge, then use the slf4j output module that dumps to
 java.util.logging.  There's no configuration, you just pick which jar
 files you include in your project.  In this case it would be:

 slf4j-X.X.X.jar (the base jar)
 log4j-over-slf4j-X.X.X.jar (the bridge)
 slf4j-jdk14-X.X.X.jar (the output module)

 Just add these jars to your project (leave out the log4j jar) and I'm
 pretty sure that you'll find all log4j output sent to the resin
 logger.

 Jeff

 On Fri, Apr 2, 2010 at 12:43 PM, Scott Ferguson f...@caucho.com wrote:
  Jon Stevens wrote:
  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)...
  I think he needs the other way around, from log4j to java.util.logging
 (?)
 
  By the way, in Resin 4.0.6 you'll be able to do the same thing with
 
  resin xmlns=...
 
  system
   logger name= level=
 mypkg:JDKLogHandler xmlns=urn:java:org.mycom.mypkg
   levelall/level
 /mypkg:JDKLogHandler
   /logger
  /system
 
  I'm not sure setting the Logger level to all would be a good idea,
  though, because Logger.isLoggable() would always return true, which
  would harm performance somewhat.
 
  (The system is just to ensure it's configured in the system
  classloader context, since resin is a child of the system loader. And
  at some point I need to look into providing an adapter to log4j handlers
  so you can configure log4j handlers as a java.util.logging handler
  directly in Resin.)
 
  -- Scott
 
  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 MapString, Log cachedLogs = new ConcurrentHashMapString,
  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 http://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 f...@caucho.com
  mailto:f...@caucho.com 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
   

Re: [Resin-interest] Sending log4j logs to the web apps log folder

2010-04-02 Thread Jeff Schnitzer
Why would you want Resin to log through slf4j?  I actually think this
would make a really big mess out of our apps, because now the slf4j
jars would be provided for us and potentially cause conflicts.

Resin provides a concrete logging system (in this case, j.u.l).  We
write our code using slf4j and by using the slf4j-jdk14.jar adapter,
everything just works.  This seems pretty straightforward.  I'd hate
to have to configure the slf4j logging in the container.

Jeff

On Fri, Apr 2, 2010 at 1:13 PM, Chris Pratt thechrispr...@gmail.com wrote:
 Consider this another vote for a possible switch to using SLF4j as the Resin
 logging interface.  It's a very thin API that is an extremely powerful
 aggregator of log information.
   (*Chris*)

 On Fri, Apr 2, 2010 at 12:57 PM, Jeff Schnitzer j...@infohazard.org wrote:

 I'm pretty sure that it's possible to configure any possible
 combination of input loggers and output destinations by mixing and
 matching the various components of SLF4J.

 To get log4j output to java.util.logging, you could use the
 log4j-slf4j bridge, then use the slf4j output module that dumps to
 java.util.logging.  There's no configuration, you just pick which jar
 files you include in your project.  In this case it would be:

 slf4j-X.X.X.jar (the base jar)
 log4j-over-slf4j-X.X.X.jar (the bridge)
 slf4j-jdk14-X.X.X.jar (the output module)

 Just add these jars to your project (leave out the log4j jar) and I'm
 pretty sure that you'll find all log4j output sent to the resin
 logger.

 Jeff

 On Fri, Apr 2, 2010 at 12:43 PM, Scott Ferguson f...@caucho.com wrote:
  Jon Stevens wrote:
  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)...
  I think he needs the other way around, from log4j to java.util.logging
  (?)
 
  By the way, in Resin 4.0.6 you'll be able to do the same thing with
 
  resin xmlns=...
 
  system
   logger name= level=
     mypkg:JDKLogHandler xmlns=urn:java:org.mycom.mypkg
       levelall/level
     /mypkg:JDKLogHandler
   /logger
  /system
 
  I'm not sure setting the Logger level to all would be a good idea,
  though, because Logger.isLoggable() would always return true, which
  would harm performance somewhat.
 
  (The system is just to ensure it's configured in the system
  classloader context, since resin is a child of the system loader. And
  at some point I need to look into providing an adapter to log4j handlers
  so you can configure log4j handlers as a java.util.logging handler
  directly in Resin.)
 
  -- Scott
 
  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 MapString, Log cachedLogs = new ConcurrentHashMapString,
  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 http://log.info(message, exception);
  }
  else if (level == 

[Resin-interest] Sending log4j logs to the web apps log folder

2010-04-01 Thread Stargazer
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?



___
resin-interest mailing list
resin-interest@caucho.com
http://maillist.caucho.com/mailman/listinfo/resin-interest