Skip to content

Commit

Permalink
Inline log function with message lambda
Browse files Browse the repository at this point in the history
  • Loading branch information
octa-one committed Jan 13, 2022
1 parent 336aae6 commit 5b948ab
Showing 1 changed file with 6 additions and 6 deletions.
Expand Up @@ -24,10 +24,8 @@ abstract class Logger(var level: Level = Level.INFO) {

abstract fun log(level: Level, msg: MESSAGE)

private fun canLog(level: Level): Boolean = this.level <= level

private fun doLog(level: Level, msg: MESSAGE) {
if (canLog(level)) {
if (isAt(level)) {
log(level, msg)
}
}
Expand All @@ -44,10 +42,12 @@ abstract class Logger(var level: Level = Level.INFO) {
doLog(Level.ERROR, msg)
}

fun isAt(lvl: Level): Boolean = this.level <= lvl
fun isAt(level: Level): Boolean = this.level <= level

fun log(lvl: Level, msg : () -> String){
if (isAt(lvl)) doLog(lvl,msg())
inline fun log(level: Level, msg: () -> MESSAGE) {
if (isAt(level)) {
log(level, msg())
}
}
}

Expand Down

0 comments on commit 5b948ab

Please sign in to comment.