simple_logger-class | R Documentation |
A simple logger that uses R's built-in signaling conditions.
## Instance creation
simple_logger(file = NULL, bufferlimit = 50L, domain = NULL)
## Get logger used by matter
matter_logger()
## Additional methods documented below
file |
The name of the log file. If |
bufferlimit |
The maximum number of buffered log entries before they are flushed to the log file. |
domain |
See |
An object of reference class simple_logger
.
id
:An identifier for file synchronization.
buffer
:A character vector of buffered log entries that have not yet been flushed to the log file.
bufferlimit
:The maximum number of buffered log entries before they are flushed to the log file.
logfile
:The path to the log file.
domain
:See gettext
for details. If NA
, log entries will not be translated.
Class-specific methods:
$flush():
Flush buffered log entries to the log file.
$append(entry):
Append a plain text entry to the log.
$append_session():
Append the sessionInfo()
to the log.
$append_trace():
Append the traceback()
to the log.
$history(print = TRUE):
Print the complete log to the console (TRUE
) or return it as a character vector (FALSE
).
$log(..., signal = FALSE, call = NULL):
Record a log entry with a timestamp, optionally signaling a "message"
, "warning"
, or "error"
condition. For "warning"
and "error"
conditions (only), the call
may also be passed to be deparsed and recorded in the log entry.
$message(...):
Record a log entry with a timestamp and signal a message
condition.
$warning(...):
Record a log entry with a timestamp and signal a warning
condition.
$stop(...):
Record a log entry with a timestamp and signal an error
condition.
$move(file):
Move the log file to a new location. Moving the log file automatically appends the current sessionInfo()
.
$copy(file):
Copy the log file to a different location.
$close():
Flush buffered log entries (including sessionInfo()
) and detach the log file. This is called automatically at the end of an R session. Note that log files in the temporary directory will be deleted after the R session ends if they are not $move()
ed to a persistent directory before quitting.
Standard generic methods:
path(x), path(x) <- value:
Get or set the path to the log file. The replacement method is the same as $move()
.
Kylie A. Bemis
sl <- simple_logger(tempfile(fileext=".log"))
sl$log("This is a silent log entry that doesn't signal a condition.")
sl$log("This log entry signals a message condition.", signal=TRUE)
sl$log("This log entry signals a message condition.", signal="message")
sl$message("This log entry also signals a message condition")
sl$flush()
readLines(path(sl))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.