Skip to content

Commit 6d4a16b

Browse files
authored
Merge pull request #66 from christian-schlichtherle/master
Adds more Logger factory methods.
2 parents ab5a704 + f0dcaa0 commit 6d4a16b

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/main/scala/com/typesafe/scalalogging/Logger.scala

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616

1717
package com.typesafe.scalalogging
1818

19-
import org.slf4j.{ LoggerFactory, Marker, Logger => Underlying }
19+
import org.slf4j.{LoggerFactory, Marker, Logger => Underlying}
20+
21+
import scala.reflect.ClassTag
2022

2123
/**
2224
* Companion for [[Logger]], providing a factory for [[Logger]]s.
@@ -29,11 +31,30 @@ object Logger {
2931
def apply(underlying: Underlying): Logger =
3032
new Logger(underlying)
3133

34+
/** Create a [[Logger]] for the given name.
35+
* Example:
36+
* {{{
37+
* val logger = Logger("application")
38+
* }}}
39+
*/
40+
def apply(name: String): Logger =
41+
new Logger(LoggerFactory.getLogger(name))
42+
3243
/**
3344
* Create a [[Logger]] wrapping the created underlying `org.slf4j.Logger`.
3445
*/
3546
def apply(clazz: Class[_]): Logger =
3647
new Logger(LoggerFactory.getLogger(clazz.getName))
48+
49+
/** Create a [[Logger]] for the runtime class wrapped by the implicit class
50+
* tag parameter.
51+
* Example:
52+
* {{{
53+
* val logger = Logger[MyClass]
54+
* }}}
55+
*/
56+
def apply[T](implicit ct: ClassTag[T]): Logger =
57+
new Logger(LoggerFactory.getLogger(ct.runtimeClass.getName.stripSuffix("$")))
3758
}
3859

3960
/**

0 commit comments

Comments
 (0)