Closed camult closed 3 years ago
Sure, I think you are interested in the index
parameter of the related function for stacking logger configs: https://daroczig.github.io/logger/articles/customize_logger.html#stacking-loggers-1
It seems that the index is for the level, can it be used for the layout?
library("logger")
logLayoutFile <- layout_glue_generator(format = "{node} \t {user} \t {pid} \t {time} \t {fn} \t {level} \t {msg}")
logLayoutConsole <- layout_glue_generator(format = "{fn} {level} {msg}")
log_layout(logLayoutFile)
logfile <- "log.txt"
log_appender(appender_tee(file = logfile))
log_info('This is a log info message!')
log_warn('This is a log warning message!')
log_error('This is a log error message!')
The expected result sent to the console should be just:
function.name INFO This is a log info message!
function.name WARN This is a log warning message!
function.name ERROR This is a log error message!
While the file log.txt
should have:
Linuxsys username 10000 2021-05-17 11:07:56 function.name INFO This is a log info message!
Linuxsys username 10000 2021-05-17 11:07:58 function.name WARN This is a log warning message!
Linuxsys username 10000 2021-05-17 11:07:59 function.name ERROR This is a log error message!
Can you provide an example where the log in the console has a different layout from the log saved to a file?
I wonder if it is possible to print different layouts one for the console and another one with more details to a file.
For example:
Thank you.