Author: chirino
Date: Sun Aug 26 17:11:30 2012
New Revision: 1377460
URL: http://svn.apache.org/viewvc?rev=1377460&view=rev
Log:
Fixes APLO-248: Log stack traces to a separate log file by default.
Modified:
activemq/activemq-apollo/trunk/apollo-cli/src/main/resources/org/apache/activemq/apollo/cli/commands/etc/log4j.properties
activemq/activemq-apollo/trunk/apollo-stomp/src/main/scala/org/apache/activemq/apollo/stomp/StompProtocolHandler.scala
activemq/activemq-apollo/trunk/apollo-util/src/main/scala/org/apache/activemq/apollo/util/Logging.scala
Modified:
activemq/activemq-apollo/trunk/apollo-cli/src/main/resources/org/apache/activemq/apollo/cli/commands/etc/log4j.properties
URL:
http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-cli/src/main/resources/org/apache/activemq/apollo/cli/commands/etc/log4j.properties?rev=1377460&r1=1377459&r2=1377460&view=diff
==============================================================================
---
activemq/activemq-apollo/trunk/apollo-cli/src/main/resources/org/apache/activemq/apollo/cli/commands/etc/log4j.properties
(original)
+++
activemq/activemq-apollo/trunk/apollo-cli/src/main/resources/org/apache/activemq/apollo/cli/commands/etc/log4j.properties
Sun Aug 26 17:11:30 2012
@@ -29,6 +29,8 @@ log4j.logger.security=INFO, security
log4j.additivity.security=false
log4j.logger.connection=INFO, connection
log4j.additivity.connection=false
+log4j.logger.stacktrace=WARN, stacktrace
+log4j.additivity.stacktrace=false
log4j.logger.org.apache.activemq.apollo=INFO
@@ -58,7 +60,7 @@ log4j.appender.apollo.maxFileSize=5MB
log4j.appender.apollo.maxBackupIndex=5
log4j.appender.apollo.append=true
log4j.appender.apollo.layout=org.apache.log4j.PatternLayout
-log4j.appender.apollo.layout.ConversionPattern=%d | %-5p | %m | %c | %t%n
+log4j.appender.apollo.layout.ConversionPattern=%d | %-5p | %m | %X{stackref}%n
log4j.appender.connection=org.apache.log4j.RollingFileAppender
log4j.appender.connection.file=${apollo.base}/log/connection.log
@@ -75,3 +77,11 @@ log4j.appender.security.maxBackupIndex=5
log4j.appender.security.append=true
log4j.appender.security.layout=org.apache.log4j.PatternLayout
log4j.appender.security.layout.ConversionPattern=%d %m%n
+
+log4j.appender.stacktrace=org.apache.log4j.RollingFileAppender
+log4j.appender.stacktrace.file=${apollo.base}/log/stacktrace.log
+log4j.appender.stacktrace.maxFileSize=5MB
+log4j.appender.stacktrace.maxBackupIndex=2
+log4j.appender.stacktrace.append=true
+log4j.appender.stacktrace.layout=org.apache.log4j.PatternLayout
+log4j.appender.stacktrace.layout.ConversionPattern=%d | %-5p |
stackref=%X{stackref}%n
Modified:
activemq/activemq-apollo/trunk/apollo-stomp/src/main/scala/org/apache/activemq/apollo/stomp/StompProtocolHandler.scala
URL:
http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-stomp/src/main/scala/org/apache/activemq/apollo/stomp/StompProtocolHandler.scala?rev=1377460&r1=1377459&r2=1377460&view=diff
==============================================================================
---
activemq/activemq-apollo/trunk/apollo-stomp/src/main/scala/org/apache/activemq/apollo/stomp/StompProtocolHandler.scala
(original)
+++
activemq/activemq-apollo/trunk/apollo-stomp/src/main/scala/org/apache/activemq/apollo/stomp/StompProtocolHandler.scala
Sun Aug 26 17:11:30 2012
@@ -1480,7 +1480,7 @@ class StompProtocolHandler extends Proto
override def on_transport_failure(error: IOException) = {
if( !connection.stopped ) {
suspend_read("shutdown")
- connection_log.info(error, "Shutting connection '%s' down due to: %s",
security_context.remote_address, error)
+ connection_log.info("Shutting connection '%s' down due to: %s",
security_context.remote_address, error)
super.on_transport_failure(error);
}
}
Modified:
activemq/activemq-apollo/trunk/apollo-util/src/main/scala/org/apache/activemq/apollo/util/Logging.scala
URL:
http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-util/src/main/scala/org/apache/activemq/apollo/util/Logging.scala?rev=1377460&r1=1377459&r2=1377460&view=diff
==============================================================================
---
activemq/activemq-apollo/trunk/apollo-util/src/main/scala/org/apache/activemq/apollo/util/Logging.scala
(original)
+++
activemq/activemq-apollo/trunk/apollo-util/src/main/scala/org/apache/activemq/apollo/util/Logging.scala
Sun Aug 26 17:11:30 2012
@@ -25,6 +25,7 @@ import collection.mutable.ListBuffer
* @author <a href="http://hiramchirino.com">Hiram Chirino</a>
*/
object Log {
+ val stack_trace_log = LoggerFactory.getLogger("stacktrace")
def apply(clazz:Class[_]):Log = apply(clazz.getName.stripSuffix("$"))
@@ -47,25 +48,6 @@ trait Log {
import Log._
val log = LoggerFactory.getLogger(getClass.getName.stripSuffix("$"))
- private def with_throwable(e:Throwable)(func: =>Unit) = {
- if( e!=null ) {
- val stack_ref = if( log.isDebugEnabled ) {
- val id = next_exception_id
- MDC.put("stackref", id.toString);
- Some(id)
- } else {
- None
- }
- func
- stack_ref.foreach { id=>
- log.debug(e.toString, e)
- MDC.remove("stackref")
- }
- } else {
- func
- }
- }
-
private def format(message:String, args:Seq[Any]) = {
if( args.isEmpty ) {
message
@@ -81,18 +63,24 @@ trait Log {
}
def error(e: Throwable, m: => String, args:Any*): Unit = {
- with_throwable(e) {
- if( log.isErrorEnabled ) {
+ if( log.isErrorEnabled ) {
+ if( e!=null ) {
+ MDC.put("stackref", next_exception_id.toString);
+ log.error(format(m, args.toSeq))
+ stack_trace_log.error(e.toString, e)
+ MDC.remove("stackref")
+ } else {
log.error(format(m, args.toSeq))
}
}
}
def error(e: Throwable): Unit = {
- with_throwable(e) {
- if( log.isErrorEnabled ) {
- log.error(e.getMessage)
- }
+ if( e!=null && log.isErrorEnabled ) {
+ MDC.put("stackref", next_exception_id.toString);
+ log.error(e.toString)
+ stack_trace_log.error(e.toString, e)
+ MDC.remove("stackref")
}
}
@@ -103,18 +91,24 @@ trait Log {
}
def warn(e: Throwable, m: => String, args:Any*): Unit = {
- with_throwable(e) {
- if( log.isWarnEnabled ) {
+ if( log.isWarnEnabled ) {
+ if( e!=null ) {
+ MDC.put("stackref", next_exception_id.toString);
+ log.warn(format(m, args.toSeq))
+ stack_trace_log.warn(e.toString, e)
+ MDC.remove("stackref")
+ } else {
log.warn(format(m, args.toSeq))
}
}
}
def warn(e: Throwable): Unit = {
- with_throwable(e) {
- if( log.isWarnEnabled ) {
- log.warn(e.toString)
- }
+ if( e!=null && log.isWarnEnabled ) {
+ MDC.put("stackref", next_exception_id.toString);
+ log.warn(e.toString)
+ stack_trace_log.warn(e.toString, e)
+ MDC.remove("stackref")
}
}
@@ -125,18 +119,24 @@ trait Log {
}
def info(e: Throwable, m: => String, args:Any*): Unit = {
- with_throwable(e) {
- if( log.isInfoEnabled ) {
+ if( log.isInfoEnabled ) {
+ if( e!=null ) {
+ MDC.put("stackref", next_exception_id.toString);
+ log.info(format(m, args.toSeq))
+ stack_trace_log.info(e.toString, e)
+ MDC.remove("stackref")
+ } else {
log.info(format(m, args.toSeq))
}
}
}
def info(e: Throwable): Unit = {
- with_throwable(e) {
- if( log.isInfoEnabled ) {
- log.info(e.toString)
- }
+ if( e!=null && log.isInfoEnabled ) {
+ MDC.put("stackref", next_exception_id.toString);
+ log.info(e.toString)
+ stack_trace_log.info(e.toString, e)
+ MDC.remove("stackref")
}
}
@@ -149,13 +149,23 @@ trait Log {
def debug(e: Throwable, m: => String, args:Any*): Unit = {
if( log.isDebugEnabled ) {
- log.debug(format(m, args.toSeq), e)
+ if( e!=null ) {
+ MDC.put("stackref", next_exception_id.toString);
+ log.debug(format(m, args.toSeq))
+ stack_trace_log.debug(e.toString, e)
+ MDC.remove("stackref")
+ } else {
+ log.debug(format(m, args.toSeq))
+ }
}
}
def debug(e: Throwable): Unit = {
- if( log.isDebugEnabled ) {
- log.debug(e.toString, e)
+ if( e!=null && log.isDebugEnabled ) {
+ MDC.put("stackref", next_exception_id.toString);
+ log.debug(e.toString)
+ stack_trace_log.debug(e.toString, e)
+ MDC.remove("stackref")
}
}
@@ -167,13 +177,23 @@ trait Log {
def trace(e: Throwable, m: => String, args:Any*): Unit = {
if( log.isTraceEnabled ) {
- log.trace(format(m, args.toSeq), e)
+ if( e!=null ) {
+ MDC.put("stackref", next_exception_id.toString);
+ log.trace(format(m, args.toSeq))
+ stack_trace_log.trace(e.toString, e)
+ MDC.remove("stackref")
+ } else {
+ log.trace(format(m, args.toSeq))
+ }
}
}
def trace(e: Throwable): Unit = {
- if( log.isTraceEnabled ) {
- log.trace(e.toString, e)
+ if( e!=null && log.isTraceEnabled ) {
+ MDC.put("stackref", next_exception_id.toString);
+ log.trace(e.toString)
+ stack_trace_log.trace(e.toString, e)
+ MDC.remove("stackref")
}
}