Skip to content

Commit

Permalink
+ Add some doc and JitPack Badge
Browse files Browse the repository at this point in the history
  • Loading branch information
Grisu118 committed Aug 15, 2017
1 parent 50fed2e commit 77fb2fa
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# KotlinJS Logger

[![Release](https://jitpack.io/v/Grisu118/jslogger.svg?style=flat-square)](https://jitpack.io/#Grisu118/jslogger)

Simple Logger for KotlinJS

## Usage
Expand Down
18 changes: 18 additions & 0 deletions src/main/kotlin/ch/grisu118/js/logger/LoggerFactory.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
package ch.grisu118.js.logger

/**
* The main factory for managing logger instances.
* @author Benjamin Leber
*/
object LoggerFactory {

private val defaultLevel = Level.INFO
private val levels = mutableSetOf<Pair<Regex, Level>>()
private val loggers = mutableMapOf<String, Logger>()

/**
* @param owner The owner of this logger.
* @return Creates or get the logger for the given owner.
*/
fun logger(owner: Any): ILogger {
val dyn = owner.asDynamic()
return dyn.__g118Logger ?: run {
Expand All @@ -15,6 +23,10 @@ object LoggerFactory {
}
}

/**
* @param name The name of this logger.
* @return Creates or get the logger for the given name.
*/
fun logger(name: String): ILogger {
return loggers[name] ?: run {
val logger = Logger(name, level(name))
Expand All @@ -23,6 +35,12 @@ object LoggerFactory {
}
}

/**
* Set the level for all loggers created after this level is set and which match the given regex.
* If multiple regex matches, then the highest seen level is used.
* @param regex the regex to identify associated loggers.
* @param level the level for the associated loggers.
*/
fun loglevel(regex: Regex, level: Level) {
levels.add(regex to level)
}
Expand Down

0 comments on commit 77fb2fa

Please sign in to comment.