-
-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add KotlinLogging to support class level logging - a suggestion for i…
…ssue #12 (#13) add KotlinLogging to support class level logging This is another flavour of how to obtain a logger that might be the preferred way it the future.
- Loading branch information
Showing
4 changed files
with
57 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package mu | ||
|
||
import mu.internal.KLoggerFactory | ||
|
||
|
||
object KotlinLogging { | ||
/** | ||
* This methods allow defining the logger in a file in the following way: | ||
* val logger = KotlinLogging.logger {} | ||
*/ | ||
fun logger(func: () -> Unit): KLogger = KLoggerFactory.logger(func) | ||
|
||
fun logger(name: String): KLogger = KLoggerFactory.logger(name) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package mu | ||
|
||
import org.junit.Assert.* | ||
import org.junit.Test | ||
|
||
val logger = KotlinLogging.logger { } | ||
|
||
class ForKotlinLoggingTest { | ||
val loggerInClass = KotlinLogging.logger { } | ||
companion object { | ||
val loggerInCompanion = KotlinLogging.logger { } | ||
} | ||
} | ||
class KotlinLoggingTest { | ||
|
||
@Test fun testLoggerName() { | ||
assertEquals("mu.KotlinLoggingTest", logger.name) | ||
assertEquals("mu.ForKotlinLoggingTest", ForKotlinLoggingTest().loggerInClass.name) | ||
assertEquals("mu.ForKotlinLoggingTest", ForKotlinLoggingTest.loggerInCompanion.name) | ||
} | ||
} |