Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline log function with message lambda #1271

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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