diff --git a/akka-core/src/main/scala/actor/ActorRef.scala b/akka-core/src/main/scala/actor/ActorRef.scala index 2fd205edeb..902943f24d 100644 --- a/akka-core/src/main/scala/actor/ActorRef.scala +++ b/akka-core/src/main/scala/actor/ActorRef.scala @@ -1101,7 +1101,7 @@ class LocalActorRef private[akka]( clearTransactionSet createNewTransactionSet } else oldTxSet - Actor.log.ifTrace("Joining transaction set [" + currentTxSet + + Actor.log.trace("Joining transaction set [" + currentTxSet + "];\n\tactor " + toString + "\n\twith message [" + message + "]") val mtx = ThreadLocalTransaction.getThreadLocalTransaction @@ -1110,7 +1110,7 @@ class LocalActorRef private[akka]( } private def dispatch[T](messageHandle: MessageInvocation) = { - Actor.log.ifTrace("Invoking actor with message:\n" + messageHandle) + Actor.log.trace("Invoking actor with message:\n" + messageHandle) val message = messageHandle.message //serializeMessage(messageHandle.message) var topLevelTransaction = false val txSet: Option[CountDownCommitBarrier] = @@ -1118,7 +1118,7 @@ class LocalActorRef private[akka]( else { topLevelTransaction = true // FIXME create a new internal atomic block that can wait for X seconds if top level tx if (isTransactor) { - Actor.log.ifTrace("Creating a new transaction set (top-level transaction)\n\tfor actor " + toString + + Actor.log.trace("Creating a new transaction set (top-level transaction)\n\tfor actor " + toString + "\n\twith message " + messageHandle) Some(createNewTransactionSet) } else None diff --git a/akka-core/src/main/scala/actor/TypedActor.scala b/akka-core/src/main/scala/actor/TypedActor.scala index ae72da4d70..9c68a7dc01 100644 --- a/akka-core/src/main/scala/actor/TypedActor.scala +++ b/akka-core/src/main/scala/actor/TypedActor.scala @@ -449,7 +449,7 @@ object TypedActor extends Logging { val parent = clazz.getSuperclass if (parent != null) injectTypedActorContext0(typedActor, parent) else { - log.ifTrace("Can't set 'TypedActorContext' for TypedActor [" + + log.trace("Can't set 'TypedActorContext' for TypedActor [" + typedActor.getClass.getName + "] since no field of this type could be found.") None @@ -728,7 +728,7 @@ private[akka] class Dispatcher(transactionalRequired: Boolean) extends Actor { def receive = { case invocation @ Invocation(joinPoint, isOneWay, _, sender, senderFuture) => - TypedActor.log.ifTrace("Invoking Typed Actor with message:\n" + invocation) + TypedActor.log.trace("Invoking Typed Actor with message:\n" + invocation) context.foreach { ctx => if (sender ne null) ctx._sender = sender if (senderFuture ne null) ctx._senderFuture = senderFuture diff --git a/akka-core/src/main/scala/stm/JTA.scala b/akka-core/src/main/scala/stm/JTA.scala index 1c0af88d73..0fb10af4f0 100644 --- a/akka-core/src/main/scala/stm/JTA.scala +++ b/akka-core/src/main/scala/stm/JTA.scala @@ -122,7 +122,7 @@ class TransactionContainer private (val tm: Either[Option[UserTransaction], Opti } def begin = { - TransactionContainer.log.ifTrace("Starting JTA transaction") + TransactionContainer.log.trace("Starting JTA transaction") tm match { case Left(Some(userTx)) => userTx.begin case Right(Some(txMan)) => txMan.begin @@ -131,7 +131,7 @@ class TransactionContainer private (val tm: Either[Option[UserTransaction], Opti } def commit = { - TransactionContainer.log.ifTrace("Committing JTA transaction") + TransactionContainer.log.trace("Committing JTA transaction") tm match { case Left(Some(userTx)) => userTx.commit case Right(Some(txMan)) => txMan.commit @@ -140,7 +140,7 @@ class TransactionContainer private (val tm: Either[Option[UserTransaction], Opti } def rollback = { - TransactionContainer.log.ifTrace("Aborting JTA transaction") + TransactionContainer.log.trace("Aborting JTA transaction") tm match { case Left(Some(userTx)) => userTx.rollback case Right(Some(txMan)) => txMan.rollback diff --git a/akka-core/src/main/scala/stm/Transaction.scala b/akka-core/src/main/scala/stm/Transaction.scala index 0951cbc5c5..a0e2077155 100644 --- a/akka-core/src/main/scala/stm/Transaction.scala +++ b/akka-core/src/main/scala/stm/Transaction.scala @@ -83,12 +83,12 @@ object Transaction { if (JTA_AWARE) Some(TransactionContainer()) else None - log.ifTrace("Creating transaction " + toString) + log.trace("Creating transaction " + toString) // --- public methods --------- def begin = synchronized { - log.ifTrace("Starting transaction " + toString) + log.trace("Starting transaction " + toString) jta.foreach { txContainer => txContainer.begin txContainer.registerSynchronization(new StmSynchronization(txContainer, this)) @@ -96,14 +96,14 @@ object Transaction { } def commit = synchronized { - log.ifTrace("Committing transaction " + toString) + log.trace("Committing transaction " + toString) persistentStateMap.valuesIterator.foreach(_.commit) status = TransactionStatus.Completed jta.foreach(_.commit) } def abort = synchronized { - log.ifTrace("Aborting transaction " + toString) + log.trace("Aborting transaction " + toString) jta.foreach(_.rollback) persistentStateMap.valuesIterator.foreach(_.abort) persistentStateMap.clear diff --git a/akka-core/src/main/scala/stm/TransactionManagement.scala b/akka-core/src/main/scala/stm/TransactionManagement.scala index 65f8d7624c..83bb5f1323 100644 --- a/akka-core/src/main/scala/stm/TransactionManagement.scala +++ b/akka-core/src/main/scala/stm/TransactionManagement.scala @@ -120,7 +120,7 @@ class LocalStm extends TransactionManagement with Logging { def call(mtx: MultiverseTransaction): T = { factory.addHooks val result = body - log.ifTrace("Committing local transaction [" + mtx + "]") + log.trace("Committing local transaction [" + mtx + "]") result } }) @@ -155,7 +155,7 @@ class GlobalStm extends TransactionManagement with Logging { factory.addHooks val result = body val txSet = getTransactionSetInScope - log.ifTrace("Committing global transaction [" + mtx + "]\n\tand joining transaction set [" + txSet + "]") + log.trace("Committing global transaction [" + mtx + "]\n\tand joining transaction set [" + txSet + "]") try { txSet.tryJoinCommit( mtx, diff --git a/akka-core/src/main/scala/util/Logging.scala b/akka-core/src/main/scala/util/Logging.scala index 9be0ba6087..159511f2cc 100644 --- a/akka-core/src/main/scala/util/Logging.scala +++ b/akka-core/src/main/scala/util/Logging.scala @@ -29,6 +29,8 @@ trait Logging { * log.info("My foo is %s","alive") * log.error(new Exception(),"My foo is %s","broken") * } + * + * The if*-methods do not take vararg parameters, and are therefor faster */ class Logger(val logger: SLFLogger) { @@ -41,85 +43,91 @@ class Logger(val logger: SLFLogger) def error_? = logger.isErrorEnabled //Trace - def trace(t: => Throwable,msg: => String,args: Any*){ - ifTrace(t,message(msg,args:_*)) + def trace(t: Throwable, fmt: => String, arg: Any, argN: Any*){ + trace(t,message(fmt,arg,argN)) } - def trace(msg: => String,args: Any*){ - ifTrace(message(msg,args:_*)) - } - - def ifTrace(msg: => String): Unit = if (trace_?) logger trace msg - - def ifTrace(t: => Throwable,msg: => String): Unit = { + def trace(t: Throwable, msg: => String){ if(trace_?) logger.trace(msg,t) } + def trace(fmt: => String, arg: Any, argN: Any*){ + trace(message(fmt,arg,argN)) + } + + def trace(msg: => String){ + if(trace_?) logger trace msg + } //Debug - def debug(t: => Throwable,msg: => String,args: Any*){ - ifDebug(t,message(msg,args:_*)) + def debug(t: Throwable, fmt: => String, arg: Any, argN: Any*){ + debug(t,message(fmt,arg,argN)) } - def debug(msg: => String,args: Any*){ - ifDebug(message(msg,args:_*)) - } - - def ifDebug(msg: => String): Unit = if (debug_?) logger debug msg - - def ifDebug(t: => Throwable,msg: => String): Unit = { + def debug(t: Throwable, msg: => String){ if(debug_?) logger.debug(msg,t) } + def debug(fmt: => String, arg: Any, argN: Any*){ + debug(message(fmt,arg,argN)) + } + + def debug(msg: => String){ + if(debug_?) logger debug msg + } //Info - def info(t: => Throwable,msg: => String,args: Any*){ - ifInfo(t,message(msg,args:_*)) + def info(t: Throwable, fmt: => String, arg: Any, argN: Any*){ + info(t,message(fmt,arg,argN)) } - def info(msg: => String,args: Any*){ - ifInfo(message(msg,args:_*)) - } - - def ifInfo(msg: => String): Unit = if (info_?) logger info msg - - def ifInfo(t: => Throwable,msg: => String): Unit = { + def info(t: Throwable, msg: => String){ if(info_?) logger.info(msg,t) } + def info(fmt: => String, arg: Any, argN: Any*){ + info(message(fmt,arg,argN)) + } + + def info(msg: => String){ + if(info_?) logger info msg + } //Warning - def warning(t: => Throwable,msg: => String,args: Any*){ - ifWarning(t,message(msg,args:_*)) + def warning(t: Throwable, fmt: => String, arg: Any, argN: Any*){ + warning(t,message(fmt,arg,argN)) } - def warning(msg: => String,args: Any*){ - ifWarning(message(msg,args:_*)) - } - - def ifWarning(msg: => String): Unit = if (warning_?) logger warn msg - - def ifWarning(t: => Throwable,msg: => String): Unit = { + def warning(t: Throwable, msg: => String){ if(warning_?) logger.warn(msg,t) } + def warning(fmt: => String, arg: Any, argN: Any*){ + warning(message(fmt,arg,argN)) + } + + def warning(msg: => String){ + if(warning_?) logger warn msg + } //Error - def error(t: => Throwable,msg: => String,args: Any*){ - ifError(t,message(msg,args:_*)) + def error(t: Throwable, fmt: => String, arg: Any, argN: Any*){ + error(t,message(fmt,arg,argN)) } - def error(msg: => String,args: Any*){ - ifError(message(msg,args:_*)) - } - - def ifError(msg: => String): Unit = if (error_?) logger error msg - - def ifError(t: => Throwable,msg: => String): Unit = { + def error(t: Throwable, msg: => String){ if(error_?) logger.error(msg,t) } - protected def message(msg: String, args: Any*) : String = { - if(args.isEmpty || (args eq null)) - msg + def error(fmt: => String, arg: Any, argN: Any*){ + error(message(fmt,arg,argN)) + } + + def error(msg: => String){ + if(error_?) logger error msg + } + + protected def message(msg: String,arg: Any, argN: Any*) : String = { + if((argN eq null) || argN.isEmpty) + msg.format(arg) else - msg.format(args:_*) + msg.format((arg +: argN):_*) } } @@ -131,6 +139,7 @@ class Logger(val logger: SLFLogger) * val logger = Logger("my.cool.logger") * val logger = Logger(classOf[Banana]) * val rootLogger = Logger.root + * */ object Logger {