Skip to content

Instantly share code, notes, and snippets.

@arnauldvm
Last active March 13, 2019 15:36
Show Gist options
  • Save arnauldvm/90e88574070e254339271e50b5ef26b4 to your computer and use it in GitHub Desktop.
Save arnauldvm/90e88574070e254339271e50b5ef26b4 to your computer and use it in GitHub Desktop.
R logging framework
require(logging)
# LOG_LEVEL = "FINEST"
# LOG_LEVEL = "DEBUG"
LOG_LEVEL = "INFO"
# LOG_LEVEL = "ERROR"
logReset()
basicConfig(LOG_LEVEL) # bootstrapping the logging package
removeHandler("basic.stdout")
addHandler("mybasic.stdout", action=writeToConsole, level=LOG_LEVEL,
formatter=function(record) paste0(paste0(rep(" ", (50-record$level)/5), collapse=""), gsub("\\n", "\\\\n", record$msg)) )
# Usage:
logfinest("x=%s", x)
logfiner(...)
logdebug(...)
loginfo(...)
logwarn(...)
logerror(...)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment