mirror of https://github.com/qos-ch/slf4j
Initial contribution from SLF4S: Release 1.0.1 without stupid implicit conversion. OSGi stuff still missing!
This commit is contained in:
parent
f31b487e0c
commit
adab6086ed
|
|
@ -3,5 +3,7 @@ target
|
|||
.classpath
|
||||
.project
|
||||
*~
|
||||
*.tmproj
|
||||
.scala_dependencies
|
||||
integration/bundle/
|
||||
integration/felix-cache/
|
||||
integration/felix-cache/
|
||||
|
|
|
|||
3
pom.xml
3
pom.xml
|
|
@ -35,6 +35,7 @@
|
|||
|
||||
<modules>
|
||||
<module>slf4j-api</module>
|
||||
<module>slf4j-scala-api</module>
|
||||
<module>slf4j-simple</module>
|
||||
<module>slf4j-nop</module>
|
||||
<module>slf4j-jdk14</module>
|
||||
|
|
@ -349,4 +350,4 @@
|
|||
|
||||
</distributionManagement>
|
||||
|
||||
</project>
|
||||
</project>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,175 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
|
||||
<parent>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-parent</artifactId>
|
||||
<version>1.6.1</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-scala-api</artifactId>
|
||||
<packaging>jar</packaging><!-- TODO: Switch to bundle! -->
|
||||
<name>SLF4J Scala API Module</name>
|
||||
|
||||
<url>http://www.slf4j.org</url>
|
||||
<description>The slf4j Scala API</description>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<scala.version>2.8.0</scala.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.scala-lang</groupId>
|
||||
<artifactId>scala-library</artifactId>
|
||||
<version>${scala.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.scala-tools.testing</groupId>
|
||||
<artifactId>specs_2.8.0</artifactId>
|
||||
<version>1.6.5</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-all</artifactId>
|
||||
<version>1.8.4</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.7</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-simple</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.scala-tools</groupId>
|
||||
<artifactId>maven-scala-plugin</artifactId>
|
||||
<version>2.14.1</version>
|
||||
<configuration>
|
||||
<scalaVersion>${scala.version}</scalaVersion>
|
||||
<charset>${project.build.sourceEncoding}</charset>
|
||||
<jvmArgs>
|
||||
<jvmArg>-Xmx1024m</jvmArg>
|
||||
</jvmArgs>
|
||||
<args>
|
||||
<arg>-make:changed</arg>
|
||||
<arg>-deprecation</arg>
|
||||
<arg>-unchecked</arg>
|
||||
</args>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
<goal>testCompile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.4.3</version>
|
||||
<configuration>
|
||||
<includes>
|
||||
<include>**/*Spec.java</include>
|
||||
<include>**/*Test.java</include>
|
||||
</includes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<!--plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<forkMode>once</forkMode>
|
||||
<reportFormat>plain</reportFormat>
|
||||
<trimStackTrace>false</trimStackTrace>
|
||||
<excludes>
|
||||
<exclude>**/AllTest.java</exclude>
|
||||
<exclude>**/PackageTest.java</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin-->
|
||||
|
||||
<!--plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifestEntries>
|
||||
<Bundle-Version>${parsedVersion.osgiVersion}</Bundle-Version>
|
||||
<Bundle-Description>${project.description}</Bundle-Description>
|
||||
<Implementation-Version>${project.version}</Implementation-Version>
|
||||
</manifestEntries>
|
||||
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
|
||||
</archive>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>bundle-test-jar</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
<goal>test-jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin-->
|
||||
|
||||
<!--plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-antrun-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>process-classes</phase>
|
||||
<goals>
|
||||
<goal>run</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<tasks>
|
||||
<echo>Removing slf4j-api's dummy StaticLoggerBinder and StaticMarkerBinder</echo>
|
||||
<delete dir="target/classes/org/slf4j/impl"/>
|
||||
</tasks>
|
||||
</configuration>
|
||||
</plugin-->
|
||||
|
||||
</plugins>
|
||||
|
||||
</build>
|
||||
|
||||
<reporting>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>clirr-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<comparisonVersion>1.5.6</comparisonVersion>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</reporting>
|
||||
|
||||
</project>
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Copyright (c) 2010 Weigle Wilczek GmbH
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
package org.slf4j.scala
|
||||
|
||||
import org.slf4j.LoggerFactory
|
||||
|
||||
/**
|
||||
* Mixin providing a Logger for the type mixed into.
|
||||
*/
|
||||
trait Logging {
|
||||
|
||||
/**
|
||||
* Logger for the type mixed into.
|
||||
*/
|
||||
protected[scala] lazy val logger = Logger(this.getClass)
|
||||
}
|
||||
|
|
@ -0,0 +1,153 @@
|
|||
/*
|
||||
* Copyright (c) 2010 Weigle Wilczek GmbH
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
package org.slf4j.scala
|
||||
|
||||
import org.slf4j.{ Logger => SLF4JLogger, LoggerFactory }
|
||||
|
||||
/**
|
||||
* Factory for Loggers.
|
||||
*/
|
||||
object Logger {
|
||||
|
||||
/**
|
||||
* Creates a Logger named corresponding to the given class.
|
||||
* @param clazz Class used for the Logger's name. Must not be null!
|
||||
*/
|
||||
def apply(clazz: Class[_]) = {
|
||||
require(clazz != null, "clazz must not be null!")
|
||||
new DefaultLogger(LoggerFactory getLogger clazz)
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Logger with the given name.
|
||||
* @param name The Logger's name. Must not be null!
|
||||
*/
|
||||
def apply(name: String) = {
|
||||
require(name != null, "loggerName must not be null!")
|
||||
new DefaultLogger(LoggerFactory getLogger name)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Thin wrapper for SLF4J making use of by-name parameters to improve performance.
|
||||
*/
|
||||
trait Logger {
|
||||
|
||||
/**
|
||||
* The name of this Logger.
|
||||
*/
|
||||
lazy val name = slf4jLogger.getName
|
||||
|
||||
/**
|
||||
* Log a message with ERROR level.
|
||||
* @param msg The message to be logged
|
||||
*/
|
||||
def error(msg: => String) {
|
||||
if (slf4jLogger.isErrorEnabled) slf4jLogger error msg
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a message with ERROR level.
|
||||
* @param msg The message to be logged
|
||||
* @param t The Throwable to be logged
|
||||
*/
|
||||
def error(msg: => String, t: Throwable) {
|
||||
if (slf4jLogger.isErrorEnabled) slf4jLogger.error(msg, t)
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a message with WARN level.
|
||||
* @param msg The message to be logged
|
||||
*/
|
||||
def warn(msg: => String) {
|
||||
if (slf4jLogger.isWarnEnabled) slf4jLogger warn msg
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a message with WARN level.
|
||||
* @param msg The message to be logged
|
||||
* @param t The Throwable to be logged
|
||||
*/
|
||||
def warn(msg: => String, t: Throwable) {
|
||||
if (slf4jLogger.isWarnEnabled) slf4jLogger.warn(msg, t)
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a message with INFO level.
|
||||
* @param msg The message to be logged
|
||||
*/
|
||||
def info(msg: => String) {
|
||||
if (slf4jLogger.isInfoEnabled) slf4jLogger info msg
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a message with INFO level.
|
||||
* @param msg The message to be logged
|
||||
* @param t The Throwable to be logged
|
||||
*/
|
||||
def info(msg: => String, t: Throwable) {
|
||||
if (slf4jLogger.isInfoEnabled) slf4jLogger.info(msg, t)
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a message with DEBUG level.
|
||||
* @param msg The message to be logged
|
||||
*/
|
||||
def debug(msg: => String) {
|
||||
if (slf4jLogger.isDebugEnabled) slf4jLogger debug msg
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a message with DEBUG level.
|
||||
* @param msg The message to be logged
|
||||
* @param t The Throwable to be logged
|
||||
*/
|
||||
def debug(msg: => String, t: Throwable) {
|
||||
if (slf4jLogger.isDebugEnabled) slf4jLogger.debug(msg, t)
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a message with TRACE level.
|
||||
* @param msg The message to be logged
|
||||
*/
|
||||
def trace(msg: => String) {
|
||||
if (slf4jLogger.isTraceEnabled) slf4jLogger trace msg
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a message with TRACE level.
|
||||
* @param msg The message to be logged
|
||||
* @param t The Throwable to be logged
|
||||
*/
|
||||
def trace(msg: => String, t: Throwable) {
|
||||
if (slf4jLogger.isTraceEnabled) slf4jLogger.trace(msg, t)
|
||||
}
|
||||
|
||||
/**
|
||||
* The wrapped SLF4J Logger.
|
||||
*/
|
||||
protected val slf4jLogger: SLF4JLogger
|
||||
}
|
||||
|
||||
private[scala] class DefaultLogger(override protected val slf4jLogger: SLF4JLogger) extends Logger
|
||||
|
|
@ -0,0 +1,297 @@
|
|||
/*
|
||||
* Copyright (c) 2010 Weigle Wilczek GmbH
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
package org.slf4j.scala
|
||||
|
||||
import org.slf4j.{ Logger => SLF4JLogger }
|
||||
import org.specs.SpecificationWithJUnit
|
||||
import org.specs.mock.Mockito
|
||||
|
||||
class LoggerSpec extends SpecificationWithJUnit with Mockito {
|
||||
|
||||
"Creating a Logger using Logger(clazz: Class[_])" should {
|
||||
|
||||
"return a Logger namend like the given class" in {
|
||||
val clazz = classOf[String]
|
||||
Logger(clazz).name mustEqual clazz.getName
|
||||
}
|
||||
|
||||
"throw an IAE when creating a Logger with a null class" in {
|
||||
Logger(null: Class[_]) must throwA[IllegalArgumentException]
|
||||
}
|
||||
}
|
||||
|
||||
"Creating a Logger using Logger(name: String)" should {
|
||||
|
||||
"return a Logger namend like the given name" in {
|
||||
val name = "MyLogger"
|
||||
Logger(name).name mustEqual name
|
||||
}
|
||||
|
||||
"throw an IAE when creating a Logger with a null String" in {
|
||||
Logger(null: String) must throwA [IllegalArgumentException]
|
||||
}
|
||||
}
|
||||
|
||||
"Calling Logger.error(msg)" should {
|
||||
val (logger, slf4jLogger) = loggers
|
||||
var evaluated = false
|
||||
def msg = {
|
||||
evaluated = true
|
||||
Msg
|
||||
}
|
||||
|
||||
"not call SLF4JLogger.error when error not enabled" in {
|
||||
slf4jLogger.isErrorEnabled returns false
|
||||
logger error msg
|
||||
there was no(slf4jLogger).error(Msg)
|
||||
evaluated mustBe false
|
||||
}
|
||||
|
||||
"call SLF4JLogger.error when error enabled" in {
|
||||
slf4jLogger.isErrorEnabled returns true
|
||||
logger error msg
|
||||
there was one(slf4jLogger).error(Msg)
|
||||
evaluated mustBe true
|
||||
}
|
||||
}
|
||||
|
||||
"Calling Logger.error(msg, t)" should {
|
||||
val (logger, slf4jLogger) = loggers
|
||||
var evaluated = false
|
||||
def msg = {
|
||||
evaluated = true
|
||||
Msg
|
||||
}
|
||||
|
||||
"not call SLF4JLogger.error when error not enabled" in {
|
||||
slf4jLogger.isErrorEnabled returns false
|
||||
logger.error(msg, t)
|
||||
there was no(slf4jLogger).error(Msg, t)
|
||||
evaluated mustBe false
|
||||
}
|
||||
|
||||
"call SLF4JLogger.error when error enabled" in {
|
||||
slf4jLogger.isErrorEnabled returns true
|
||||
logger.error(msg, t)
|
||||
there was one(slf4jLogger).error(Msg ,t)
|
||||
evaluated mustBe true
|
||||
}
|
||||
}
|
||||
|
||||
"Calling Logger.warn(msg)" should {
|
||||
val (logger, slf4jLogger) = loggers
|
||||
var evaluated = false
|
||||
def msg = {
|
||||
evaluated = true
|
||||
Msg
|
||||
}
|
||||
|
||||
"not call SLF4JLogger.warn when warn not enabled" in {
|
||||
slf4jLogger.isWarnEnabled returns false
|
||||
logger warn msg
|
||||
there was no(slf4jLogger).warn(Msg)
|
||||
evaluated mustBe false
|
||||
}
|
||||
|
||||
"call SLF4JLogger.warn when warn enabled" in {
|
||||
slf4jLogger.isWarnEnabled returns true
|
||||
logger warn msg
|
||||
there was one(slf4jLogger).warn(Msg)
|
||||
evaluated mustBe true
|
||||
}
|
||||
}
|
||||
|
||||
"Calling Logger.warn(msg, t)" should {
|
||||
val (logger, slf4jLogger) = loggers
|
||||
var evaluated = false
|
||||
def msg = {
|
||||
evaluated = true
|
||||
Msg
|
||||
}
|
||||
|
||||
"not call SLF4JLogger.warn when warn not enabled" in {
|
||||
slf4jLogger.isErrorEnabled returns false
|
||||
logger.warn(msg, t)
|
||||
there was no(slf4jLogger).warn(Msg, t)
|
||||
evaluated mustBe false
|
||||
}
|
||||
|
||||
"call SLF4JLogger.warn when warn enabled" in {
|
||||
slf4jLogger.isWarnEnabled returns true
|
||||
logger.warn(msg, t)
|
||||
there was one(slf4jLogger).warn(Msg ,t)
|
||||
evaluated mustBe true
|
||||
}
|
||||
}
|
||||
|
||||
"Calling Logger.info(msg)" should {
|
||||
val (logger, slf4jLogger) = loggers
|
||||
var evaluated = false
|
||||
def msg = {
|
||||
evaluated = true
|
||||
Msg
|
||||
}
|
||||
|
||||
"not call SLF4JLogger.info when info not enabled" in {
|
||||
slf4jLogger.isInfoEnabled returns false
|
||||
logger info msg
|
||||
there was no(slf4jLogger).info(Msg)
|
||||
evaluated mustBe false
|
||||
}
|
||||
|
||||
"call SLF4JLogger.info when info enabled" in {
|
||||
slf4jLogger.isInfoEnabled returns true
|
||||
logger info msg
|
||||
there was one(slf4jLogger).info(Msg)
|
||||
evaluated mustBe true
|
||||
}
|
||||
}
|
||||
|
||||
"Calling Logger.info(msg, t)" should {
|
||||
val (logger, slf4jLogger) = loggers
|
||||
var evaluated = false
|
||||
def msg = {
|
||||
evaluated = true
|
||||
Msg
|
||||
}
|
||||
|
||||
"not call SLF4JLogger.info when info not enabled" in {
|
||||
slf4jLogger.isInfoEnabled returns false
|
||||
logger.info(msg, t)
|
||||
there was no(slf4jLogger).info(Msg, t)
|
||||
evaluated mustBe false
|
||||
}
|
||||
|
||||
"call SLF4JLogger.info when info enabled" in {
|
||||
slf4jLogger.isInfoEnabled returns true
|
||||
logger.info(msg, t)
|
||||
there was one(slf4jLogger).info(Msg, t)
|
||||
evaluated mustBe true
|
||||
}
|
||||
}
|
||||
|
||||
"Calling Logger.debug(msg)" should {
|
||||
val (logger, slf4jLogger) = loggers
|
||||
var evaluated = false
|
||||
def msg = {
|
||||
evaluated = true
|
||||
Msg
|
||||
}
|
||||
|
||||
"not call SLF4JLogger.debug when debug not enabled" in {
|
||||
slf4jLogger.isDebugEnabled returns false
|
||||
logger debug msg
|
||||
there was no(slf4jLogger).debug(Msg)
|
||||
evaluated mustBe false
|
||||
}
|
||||
|
||||
"call SLF4JLogger.debug when debug enabled" in {
|
||||
slf4jLogger.isDebugEnabled returns true
|
||||
logger debug msg
|
||||
there was one(slf4jLogger).debug(Msg)
|
||||
evaluated mustBe true
|
||||
}
|
||||
}
|
||||
|
||||
"Calling Logger.debug(msg ,t)" should {
|
||||
val (logger, slf4jLogger) = loggers
|
||||
var evaluated = false
|
||||
def msg = {
|
||||
evaluated = true
|
||||
Msg
|
||||
}
|
||||
|
||||
"not call SLF4JLogger.debug when debug not enabled" in {
|
||||
slf4jLogger.isDebugEnabled returns false
|
||||
logger.debug(msg, t)
|
||||
there was no(slf4jLogger).debug(Msg, t)
|
||||
evaluated mustBe false
|
||||
}
|
||||
|
||||
"call SLF4JLogger.debug when debug enabled" in {
|
||||
slf4jLogger.isDebugEnabled returns true
|
||||
logger.debug(msg, t)
|
||||
there was one(slf4jLogger).debug(Msg, t)
|
||||
evaluated mustBe true
|
||||
}
|
||||
}
|
||||
|
||||
"Calling Logger.trace(msg)" should {
|
||||
val (logger, slf4jLogger) = loggers
|
||||
var evaluated = false
|
||||
def msg = {
|
||||
evaluated = true
|
||||
Msg
|
||||
}
|
||||
|
||||
"not call SLF4JLogger.trace when trace not enabled" in {
|
||||
slf4jLogger.isTraceEnabled returns false
|
||||
logger trace msg
|
||||
there was no(slf4jLogger).trace(Msg)
|
||||
evaluated mustBe false
|
||||
}
|
||||
|
||||
"call SLF4JLogger.trace when trace enabled" in {
|
||||
slf4jLogger.isTraceEnabled returns true
|
||||
logger trace msg
|
||||
there was one(slf4jLogger).trace(Msg)
|
||||
evaluated mustBe true
|
||||
}
|
||||
}
|
||||
|
||||
"Calling Logger.trace(msg, t)" should {
|
||||
val (logger, slf4jLogger) = loggers
|
||||
var evaluated = false
|
||||
def msg = {
|
||||
evaluated = true
|
||||
Msg
|
||||
}
|
||||
|
||||
"not call SLF4JLogger.trace when trace not enabled" in {
|
||||
slf4jLogger.isTraceEnabled returns false
|
||||
logger.trace(msg, t)
|
||||
there was no(slf4jLogger).trace(Msg, t)
|
||||
evaluated mustBe false
|
||||
}
|
||||
|
||||
"call SLF4JLogger.trace when trace enabled" in {
|
||||
slf4jLogger.isTraceEnabled returns true
|
||||
logger.trace(msg, t)
|
||||
there was one(slf4jLogger).trace(Msg, t)
|
||||
evaluated mustBe true
|
||||
}
|
||||
}
|
||||
|
||||
private lazy val Msg = "MESSAGE"
|
||||
|
||||
private lazy val t = new Throwable
|
||||
|
||||
private def loggers = {
|
||||
val mockSLF4JLogger = mock[SLF4JLogger]
|
||||
val logger = new Logger {
|
||||
override protected val slf4jLogger = mockSLF4JLogger
|
||||
}
|
||||
(logger, mockSLF4JLogger)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* Copyright (c) 2010 Weigle Wilczek GmbH
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
package org.slf4j.scala
|
||||
|
||||
import org.specs.SpecificationWithJUnit
|
||||
|
||||
class LoggingSpec extends SpecificationWithJUnit {
|
||||
|
||||
"Mixing Logging into SomeClass" should {
|
||||
"yield a Logger named to SomeClass's FQCN" in {
|
||||
val someClass = new SomeClass
|
||||
someClass.logger.name mustEqual classOf[SomeClass].getName
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class SomeClass extends Logging
|
||||
Loading…
Reference in New Issue