simple_logger-class: Simple Logging

simple_logger-classR Documentation

Simple Logging

Description

A simple logger that uses R's built-in signaling conditions.

Usage

## Instance creation
simple_logger(file = NULL, bufferlimit = 50L, domain = NULL)

## Get logger used by matter
matter_logger()

## Additional methods documented below

Arguments

file

The name of the log file. If NULL, then no log file is used, and the log is kept in memory.

bufferlimit

The maximum number of buffered log entries before they are flushed to the log file.

domain

See gettext for details. If NA, log entries will not be translated.

Value

An object of reference class simple_logger.

Fields

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.

Methods

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().

Author(s)

Kylie A. Bemis

Examples

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))

kuwisdelu/matter documentation built on Dec. 8, 2024, 8:09 p.m.