Skip to content

Commit

Permalink
- Updated to version 1.6.1 of the SLF4J library.
Browse files Browse the repository at this point in the history
- Added a Logging trait that can be mixed into a class, providing logging
  functions and a Logger, without changing the public API (similar to the
  Logging trait in the Scalate source. Addresses Issue #1.
  • Loading branch information
bmc committed Jan 30, 2011
1 parent 25d77c9 commit 5078800
Show file tree
Hide file tree
Showing 5 changed files with 174 additions and 2 deletions.
13 changes: 13 additions & 0 deletions .ensime
@@ -0,0 +1,13 @@
;; This config was generated using ensime-config-gen. Feel free to customize its contents manually.

(

:project-package "grizzled.slf4j"

:use-sbt t

:classpath (
(directory-files "lib_managed/scala_2.8.1/compile", nil, "slf4j.*\\.jar")
(directory-files "lib_managed/scala_2.8.1/test", nil, "scalatest.*\\.jar")
)
)
12 changes: 12 additions & 0 deletions notes/0.4.markdown
@@ -0,0 +1,12 @@
* Updated to version 1.6.1 of the [SLF4J][] library.
* Added a `Logging` trait that can be mixed into a class, providing logging
functions and a `Logger`, without changing the public API (similar to the
[`Logging`][scalate-logging] trait in the [Scalate][] source. Addresses
[Issue #1][issue-1].

[Scala]: http://www.scala-lang.org/
[SLF4J]: http://www.slf4j.org/
[scalate-logging]: https://github.com/scalate/scalate/blob/master/scalate-util/src/main/scala/org/fusesource/scalate/util/Logging.scala
[scalate]: http://scalate.fusesource.org/
[issue-1]: https://github.com/bmc/grizzled-slf4j/issues#issue/1

2 changes: 1 addition & 1 deletion project/build.properties
Expand Up @@ -3,6 +3,6 @@
project.organization=org.clapper
project.name=grizzled-slf4j
sbt.version=0.7.4
project.version=0.3.2
project.version=0.4
build.scala.versions=2.8.1 2.8.0 2.7.7
project.initialize=false
4 changes: 3 additions & 1 deletion project/build/GrizzledSLF4JProject.scala
Expand Up @@ -69,7 +69,9 @@ with posterous.Publish
val scalaToolsRepo = "Scala-Tools Maven Repository" at
"http://scala-tools.org/repo-releases/"

val slf4j = "org.slf4j" % "slf4j-api" % "1.6.0"
val slf4j = "org.slf4j" % "slf4j-api" % "1.6.1"

val scalatest = "org.scalatest" % "scalatest" % "1.2" % "test"

/* ---------------------------------------------------------------------- *\
Publishing
Expand Down
145 changes: 145 additions & 0 deletions src/main/scala/grizzled/slf4j/slf4j.scala
Expand Up @@ -175,6 +175,151 @@ class Logger(val logger: SLF4JLogger)
if (isWarnEnabled) logger.warn(msg.toString, t)
}

/**
* Mix the `Logging` trait into a class to get:
*
* - Logging methods
* - A `Logger` object, accessible via the `log` property
*
* Does not affect the public API of the class mixing it in.
*/
trait Logging
{
// The logger. Instantiated the first time it's used.
private lazy val _logger = Logger(getClass)

/**
* Get the `Logger` for the class that mixes this trait in. The `Logger`
* is created the first time this method is call. The other methods (e.g.,
* `error`, `info`, etc.) call this method to get the logger.
*
* @return the `Logger`
*/
protected def logger: Logger = _logger

/**
* Get the name associated with this logger.
*
* @return the name.
*/
protected def loggerName = logger.name

/**
* Determine whether trace logging is enabled.
*/
protected def isTraceEnabled = logger.isTraceEnabled

/**
* Issue a trace logging message.
*
* @param msg the message object. `toString()` is called to convert it
* to a loggable string.
*/
protected def trace(msg: => AnyRef): Unit = logger.trace(msg)

/**
* Issue a trace logging message, with an exception.
*
* @param msg the message object. `toString()` is called to convert it
* to a loggable string.
* @param t the exception to include with the logged message.
*/
protected def trace(msg: => AnyRef, t: => Throwable): Unit =
logger.trace(msg, t)

/**
* Determine whether debug logging is enabled.
*/
protected def isDebugEnabled = logger.isDebugEnabled

/**
* Issue a debug logging message.
*
* @param msg the message object. `toString()` is called to convert it
* to a loggable string.
*/
protected def debug(msg: => AnyRef): Unit = logger.debug(msg)

/**
* Issue a debug logging message, with an exception.
*
* @param msg the message object. `toString()` is called to convert it
* to a loggable string.
* @param t the exception to include with the logged message.
*/
protected def debug(msg: => AnyRef, t: => Throwable): Unit =
logger.debug(msg, t)

/**
* Determine whether trace logging is enabled.
*/
protected def isErrorEnabled = logger.isErrorEnabled

/**
* Issue a trace logging message.
*
* @param msg the message object. `toString()` is called to convert it
* to a loggable string.
*/
protected def error(msg: => AnyRef): Unit = logger.error(msg)

/**
* Issue a trace logging message, with an exception.
*
* @param msg the message object. `toString()` is called to convert it
* to a loggable string.
* @param t the exception to include with the logged message.
*/
protected def error(msg: => AnyRef, t: => Throwable): Unit =
logger.error(msg, t)

/**
* Determine whether trace logging is enabled.
*/
protected def isInfoEnabled = logger.isInfoEnabled

/**
* Issue a trace logging message.
*
* @param msg the message object. `toString()` is called to convert it
* to a loggable string.
*/
protected def info(msg: => AnyRef): Unit = logger.info(msg)

/**
* Issue a trace logging message, with an exception.
*
* @param msg the message object. `toString()` is called to convert it
* to a loggable string.
* @param t the exception to include with the logged message.
*/
protected def info(msg: => AnyRef, t: => Throwable): Unit =
logger.info(msg, t)

/**
* Determine whether trace logging is enabled.
*/
protected def isWarnEnabled = logger.isWarnEnabled

/**
* Issue a trace logging message.
*
* @param msg the message object. `toString()` is called to convert it
* to a loggable string.
*/
protected def warn(msg: => AnyRef): Unit = logger.warn(msg)

/**
* Issue a trace logging message, with an exception.
*
* @param msg the message object. `toString()` is called to convert it
* to a loggable string.
* @param t the exception to include with the logged message.
*/
protected def warn(msg: => AnyRef, t: => Throwable): Unit =
logger.warn(msg, t)
}

/**
* A factory for retrieving an SLF4JLogger.
*/
Expand Down

0 comments on commit 5078800

Please sign in to comment.