Closing ticket 337

This commit is contained in:
Viktor Klang 2010-08-06 16:03:36 +02:00
parent 88053cf39a
commit 6c6d3d246b
4 changed files with 136 additions and 22 deletions

View file

@ -4,7 +4,7 @@
package se.scalablesolutions.akka.util
import net.lag.logging.Logger
import org.slf4j.{Logger => SLFLogger,LoggerFactory => SLFLoggerFactory}
import java.io.StringWriter
import java.io.PrintWriter
@ -17,9 +17,132 @@ import java.net.UnknownHostException
* @author <a href="http://jonasboner.com">Jonas Bon&#233;r</a>
*/
trait Logging {
@sjson.json.JSONProperty(ignore = true) @transient lazy val log = Logger.get(this.getClass.getName)
@sjson.json.JSONProperty(ignore = true) @transient lazy val log = Logger(this.getClass.getName)
}
/**
* Scala SLF4J wrapper
*
* ex.
*
* class Foo extends Logging {
* log.info("My foo is %s","alive")
* log.error(new Exception(),"My foo is %s","broken")
* }
*/
class Logger(val logger: SLFLogger)
{
def name = logger.getName
def trace_? = logger.isTraceEnabled
def debug_? = logger.isDebugEnabled
def info_? = logger.isInfoEnabled
def warning_? = logger.isWarnEnabled
def error_? = logger.isErrorEnabled
//Trace
def trace(t: => Throwable,msg: => String,args: Any*){
ifTrace(t,message(msg,args:_*))
}
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 = {
if(trace_?) logger.trace(msg,t)
}
//Debug
def debug(t: => Throwable,msg: => String,args: Any*){
ifDebug(t,message(msg,args:_*))
}
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 = {
if(debug_?) logger.debug(msg,t)
}
//Info
def info(t: => Throwable,msg: => String,args: Any*){
ifInfo(t,message(msg,args:_*))
}
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 = {
if(info_?) logger.info(msg,t)
}
//Warning
def warning(t: => Throwable,msg: => String,args: Any*){
ifWarning(t,message(msg,args:_*))
}
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 = {
if(warning_?) logger.warn(msg,t)
}
//Error
def error(t: => Throwable,msg: => String,args: Any*){
ifError(t,message(msg,args:_*))
}
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 = {
if(error_?) logger.error(msg,t)
}
protected def message(msg: String, args: Any*) : String = {
if(args.isEmpty || (args eq null))
msg
else
msg.format(args:_*)
}
}
/**
* Logger factory
*
* ex.
*
* val logger = Logger("my.cool.logger")
* val logger = Logger(classOf[Banana])
* val rootLogger = Logger.root
*/
object Logger
{
def apply(logger: String) : Logger = new Logger(SLFLoggerFactory getLogger logger)
def apply(clazz: Class[_]) : Logger = apply(clazz.getName)
def root : Logger = apply(SLFLogger.ROOT_LOGGER_NAME)
}
/**
* LoggableException is a subclass of Exception and can be used as the base exception
* for application specific exceptions.

View file

@ -5,20 +5,6 @@
# This file has all the default settings, so all these could be removed with no visible effect.
# Modify as needed.
log {
filename = "./logs/akka.log"
roll = "daily" # Options: never, hourly, daily, sunday/monday/...
level = "debug" # Options: fatal, critical, error, warning, info, debug, trace
console = on
# syslog_host = ""
# syslog_server_name = ""
akka { # example of package level logging settings
node = "se.scalablesolutions.akka"
level = "debug"
}
}
akka {
version = "0.10"

View file

@ -17,4 +17,4 @@ log4j.appender.R.layout.ConversionPattern=%5p [%t] %d{ISO8601} %F (line %L) %m%n
# Edit the next line to point to your logs directory
log4j.appender.R.File=./logs/akka.log
log4j.logger.org.atmosphere=DEBUG
log4j.logger.se.scalablesolutions=INFO

View file

@ -266,7 +266,12 @@ class AkkaParentProject(info: ProjectInfo) extends DefaultProject(info) {
)
// Exclude slf4j1.5.11 from the classpath, it's conflicting...
override def runClasspath = super.runClasspath --- (super.runClasspath ** "slf4j*1.5.11.jar")
override def runClasspath = super.runClasspath +++
descendents(info.projectPath / "config", "*") ---
(super.runClasspath ** "slf4j*1.5.11.jar")
override def mainResources = super.mainResources +++
descendents(info.projectPath / "config", "*")
// ------------------------------------------------------------
// publishing
@ -343,6 +348,9 @@ class AkkaParentProject(info: ProjectInfo) extends DefaultProject(info) {
val sjson = Dependencies.sjson
val werkz = Dependencies.werkz
val werkz_core = Dependencies.werkz_core
val slf4j = Dependencies.slf4j
val slf4j_log4j = Dependencies.slf4j_log4j
val log4j = Dependencies.log4j
// testing
val junit = Dependencies.junit
@ -453,9 +461,6 @@ class AkkaParentProject(info: ProjectInfo) extends DefaultProject(info) {
class AkkaCassandraProject(info: ProjectInfo) extends AkkaDefaultProject(info, distPath) {
val cassandra = Dependencies.cassandra
val log4j = Dependencies.log4j
val slf4j = Dependencies.slf4j
val slf4j_log4j = Dependencies.slf4j_log4j
// testing
val cassandra_clhm = Dependencies.cassandra_clhm
@ -634,6 +639,7 @@ class AkkaParentProject(info: ProjectInfo) extends DefaultProject(info) {
}
class AkkaSampleCamelProject(info: ProjectInfo) extends AkkaDefaultProject(info, deployPath) with CodeFellowPlugin {
//Must be like this to be able to exclude the geronimo-servlet_2.4_spec which is a too old Servlet spec
override def ivyXML =
<dependencies>
<dependency org="org.springframework" name="spring-jms" rev={SPRING_VERSION}>
@ -701,7 +707,6 @@ class AkkaParentProject(info: ProjectInfo) extends DefaultProject(info) {
((outputPath ##) / defaultJarName) +++
mainResources +++
mainDependencies.scalaJars +++
descendents(info.projectPath, "*.conf") +++
descendents(info.projectPath / "scripts", "run_akka.sh") +++
descendents(info.projectPath / "dist", "*.jar") +++
descendents(info.projectPath / "deploy", "*.jar") +++