The log_open
function initializes and opens the log file.
This function must be called first, before any logging can occur.
The function determines the log path, attaches event handlers,
clears existing log files, and initiates a new log.
The file_name
parameter may be a full path, a relative path, or
a file name. An relative path or file name will be assumed to be relative
to the current working directory. If the file_name
does
not have a '.log' extension, the log_open
function will add it.
If requested in the logdir
parameter, the log_open
function will write to a 'log' subdirectory of the path specified in the
file_name
. If the 'log' subdirectory does not exist,
the function will create it.
The log file will be initialized with a header that shows the log file name,
the current working directory, the current user, and a timestamp of
when the log_open
function was called.
All errors, the last warning, and any log_print
output will be
written to the log. The log file will exist in the location specified in the
file_name parameter, and will normally have a '.log' extension.
If errors or warnings are generated, a second file will
be written that contains only error and warning messages. This second file
will have a '.msg' extension and will exist in the specified log directory.
If the log is clean, the msg file will not be created.
The purpose of the msg file is to give the user a visual indicator from
the file system that an error or warning occurred. This indicator
msg file is useful when running programs in batch.
To use logr, call log_open
, and then make calls to
log_print
as needed to print variables or data frames to the log.
The log_print
function can be used in place of a standard
print
function. Anything printed with log_print
will
be printed to the log, and to the console if working interactively.
This package provides the functionality of sink
, but in much more
user-friendly way. Recommended usage is to call log_open
at the top
of the script, call log_print
as needed to log interim state,
and call log_close
at the bottom of the script.