Created
May 2, 2013 13:59
-
-
Save matthewadams/5502379 to your computer and use it in GitHub Desktop.
Convenient logback/slf4j logging closures for Groovy script authors.
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
@Grab(group='ch.qos.logback', module='logback-classic', version='[1.0.9,)') | |
import org.slf4j.Logger | |
import org.slf4j.LoggerFactory | |
import ch.qos.logback.classic.Level | |
logger = LoggerFactory.getLogger("yourScript") // or whatever | |
logger.level = Level.INFO // or whatever | |
log = { level, msg, Object... args -> logger."${level.toLowerCase()}"((msg ?: "").toString(), args) } | |
trace = { msg, Object... args -> log("trace", msg, args) } | |
debug = { msg, Object... args -> log("debug", msg, args) } | |
info = { msg, Object... args -> log("info", msg, args) } | |
warn = { msg, Object... args -> log("warn", msg, args) } | |
error = { msg, Object... args -> log("error", msg, args) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Managed to use logging in my groovy script. Thank you for posting this!