msg {tryr} | R Documentation |
Write Logging Information to STDOUT or STDERR
Description
A simple logging utility that writes the log message to STDOUT or STDERR in plain text, JSON, or comma separated format.
Usage
msg(title = "", message = "", level = "INFO", format = NULL, digits = NULL)
x %+% y
Arguments
title |
Character, the title of the logging message. |
message |
Character, a more detailed logging message. |
level |
Log level; one of |
format |
Log format: |
digits |
Integer of length 1, digits for seconds (default |
x , y |
Strings to combine. |
Details
The TRYR_ERR_LEVEL
environment variable determines where the log message is written.
If the log level is at least the one or above the TRYR_ERR_LEVEL
value
(or "WARN"
when it is unset or null) the message is written to STDERR,
otherwise it is written to STDOUT.
The log message is only written when the log level is at least the one or higher than specified
by the TRYR_LOG_LEVEL
environment variables; or "INFO"
when the variable is unset or null.
The log format can be plain text, JSON, or comma separated text.
When the log format is NULL
the TRYR_LOG_FORMAT
environment variables is checked.
If it is unset or null, the format is considered plain text.
The logging message will be formed by combining the title
and the message
parts.
The log info also contains the process ID, a timestamp (using Sys.time()
), and the log level.
The timestamp prints out fractional seconds according to digits
. When digits
is NULL
it checks the TRYR_LOG_DIGITS
environment variables and uses that value.
The default is 3 when TRYR_LOG_DIGITS
unset or null.
Besides the usual log levels, there is an extra one "SUCCESS"
that is
used to signal successful HTTP response codes (2xx).
Value
msg
invisibly returns logical indicating if the log message was written
(TRUE
) or not (FALSE
). A side effect is a log message to STDOUT or STDERR.
The %+%
special pastes the right and left hand side together into s single string.
See Also
Examples
n <- 5
"Sample " %+% "size " %+% "n = " %+% n %+% "."
msg("Success", "We did it!")
msg("Success", "We did it!", "SUCCESS")
msg("Error", "Oh no! n cannot be " %+% n, "ERROR")
msg("Success", "We did it!", "SUCCESS", format = "JSON")
msg("Success", "We did it!", format = "JSON")
msg("Error", "Oh no ...", "ERROR", format = "JSON")
msg("Success", "We did it!", digits = 0)
msg("Success", "We did it!", digits = 6)