Format a log message with glue
and ANSI escape codes to add colors
Source: R/layouts.R
layout_glue_colors.Rd
Colour log levels based on their severity. Log levels are coloured
with colorize_by_log_level()
and the messages are coloured with
grayscale_by_log_level()
.
Usage
layout_glue_colors(
level,
msg,
namespace = NA_character_,
.logcall = sys.call(),
.topcall = sys.call(-1),
.topenv = parent.frame()
)
Arguments
- level
log level, see
log_levels()
for more details- msg
string message
- namespace
string referring to the
logger
environment / config to be used to override the target of the message record to be used instead of the default namespace, which is defined by the R package name from which the logger was called, and falls back to a common, global namespace.- .logcall
the logging call being evaluated (useful in formatters and layouts when you want to have access to the raw, unevaluated R expression)
- .topcall
R expression from which the logging function was called (useful in formatters and layouts to extract the calling function's name or arguments)
- .topenv
original frame of the
.topcall
calling function where the formatter function will be evaluated and that is used to look up thenamespace
as well vialogger:::top_env_name
See also
This is a log_layout()
, for alternatives, see
layout_blank()
, layout_simple()
, layout_glue()
,
layout_json()
, layout_json_parser()
, or generator functions
such as layout_glue_generator()
Examples
log_layout(layout_glue_colors)
log_threshold(TRACE)
log_info("Starting the script...")
#> INFO [2024-08-07 22:18:15] Starting the script...
log_debug("This is the second line")
#> DEBUG [2024-08-07 22:18:15] This is the second line
log_trace("That is being placed right after the first one.")
#> TRACE [2024-08-07 22:18:15] That is being placed right after the first one.
log_warn("Some errors might come!")
#> WARN [2024-08-07 22:18:15] Some errors might come!
log_error("This is a problem")
#> ERROR [2024-08-07 22:18:15] This is a problem
log_debug("Getting an error is usually bad")
#> DEBUG [2024-08-07 22:18:15] Getting an error is usually bad
log_error("This is another problem")
#> ERROR [2024-08-07 22:18:15] This is another problem
log_fatal("The last problem.")
#> FATAL [2024-08-07 22:18:15] The last problem.