Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Convenient logback/slf4j logging closures for Groovy script authors.
@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) }
@razvangvr

This comment has been minimized.

Copy link

commented Jun 18, 2018

Managed to use logging in my groovy script. Thank you for posting this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.