log_message {thisutils} | R Documentation |
Print diagnostic message
Description
Integrate the message printing function with the cli
package,
and the base::message function.
The message could be suppressed by base::suppressMessages.
Usage
log_message(
...,
verbose = TRUE,
message_type = c("info", "success", "warning", "error"),
cli_model = TRUE,
timestamp = TRUE,
timestamp_format = "%Y-%m-%d %H:%M:%S",
level = 1,
symbol = " ",
text_color = NULL,
back_color = NULL,
multiline_indent = TRUE,
.envir = parent.frame(),
.frame = .envir
)
Arguments
... |
Text to print. |
verbose |
Logical value, default is |
message_type |
Type of message, default is |
cli_model |
Logical value, default is |
timestamp |
Logical value, default is |
timestamp_format |
Character value, default is |
level |
Integer value, default is |
symbol |
Character value, default is |
text_color |
Character value, default is |
back_color |
Character value, default is |
multiline_indent |
Logical value, default is |
.envir |
The environment to evaluate calls in. Default is |
.frame |
The frame to use for error reporting. Default is |
Value
Formated message
printed to the console.
References
https://cli.r-lib.org/articles/index.html
Examples
# basic usage
log_message("Hello, ", "world!")
log_message("hello, world!")
log_message("Hello, world!", timestamp = FALSE)
log_message("Hello, ", "world!", message_type = "success")
log_message("Hello, world!", message_type = "warning")
log_message("Hello, ", "world!", cli_model = FALSE)
# suppress messages
suppressMessages(log_message("Hello, world!"))
log_message("Hello, world!", verbose = FALSE)
options(log_message.verbose = FALSE)
log_message("Hello, world!")
options(log_message.verbose = TRUE)
# cli formatting
log_message("hello, {.arg world}!")
message("hello, {.arg world}!")
log_message("hello, {.code world}!")
message("hello, {.code world}!")
log_message("{.emph R}")
log_message("Hello, {.file world}!")
log_message("press {.kbd ENTER}")
log_message("address: {.email example@example.com}")
log_message("URL: {.url https://example.com}")
log_message("Some {.field field}")
log_message("Hello, {.pkg world}!")
log_message("Hello, {.val world}!")
# set indentation
log_message("Hello, world!", level = 2)
log_message("Hello, world!", symbol = "->")
# multiline message
log_message("Line 1\nLine 2\nLine 3", multiline_indent = TRUE)
log_message(
"Multi-line\ncolored\nmessage",
text_color = "blue",
multiline_indent = FALSE
)
log_message(
"Multi-line\ncolored\nmessage",
text_color = "blue",
multiline_indent = FALSE,
timestamp = FALSE
)
# color formatting
log_message(
"This is a red message",
text_color = "red"
)
log_message(
"This is a message with background",
back_color = "cyan"
)
log_message(
"This is a message with both text and background",
text_color = "red",
back_color = "cyan"
)
# color formatting also works with `cli_model = FALSE`
log_message(
"This is a red message",
text_color = "red",
cli_model = FALSE
)
log_message(
"This is a message with background",
back_color = "cyan",
cli_model = FALSE
)
log_message(
"This is a message with both text and background",
text_color = "red",
back_color = "cyan",
cli_model = FALSE
)
# cli variables
fun <- function(x) {
log_message("{.val x}")
log_message("{.val {x}}")
log_message("{.val {x + 1}}")
}
fun(1)