Skip to content

Instantly share code, notes, and snippets.

@matthewadams
Created May 2, 2013 13:59
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewadams/5502379 to your computer and use it in GitHub Desktop.
Save matthewadams/5502379 to your computer and use it in GitHub Desktop.
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
Copy link

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