lg <- get_logger("test")
default <- tempfile()
fancy <- tempfile()
json <- tempfile()
lg$add_appender(AppenderFile$new(default), "default")
lg$add_appender(
AppenderFile$new(fancy, layout = LayoutFormat$new("[%t] %c(): %L %m")), "fancy"
)
lg$add_appender(
AppenderFile$new(json, layout = LayoutJson$new()), "json"
)
lg$info("A test message")
readLines(default)
readLines(fancy)
readLines(json)
# cleanup
lg$config(NULL)
unlink(default)
unlink(fancy)
unlink(json)
tf <- tempfile()
lg <- get_logger("test")$
set_appenders(AppenderJson$new(tf))$
set_propagate(FALSE)
lg$info("A test message")
lg$info("A test message %s strings", "with format strings", and = "custom_fields")
lg$appenders[[1]]$show()
lg$appenders[[1]]$data
# cleanup
lg$config(NULL)
unlink(tf)
Run the code above in your browser using DataLab