save_log: Save and report log for scripts

View source: R/save_log.R

save_logR Documentation

Save and report log for scripts

Description

Reads the log file, identifies error messages and sends an email with the status for running the main script. The log file can be saved with the current date last in file name.

Usage

save_log(
  log_file,
  log_path,
  save = TRUE,
  archive = NULL,
  email = TRUE,
  from = NULL,
  to = NULL,
  email_subject = tools::file_path_sans_ext(log_file),
  include_text = NULL,
  attach_object = NULL,
  smtp_server = NULL,
  ...
)

Arguments

log_file

[character(1)]
File name of the log file.

log_path

[character(1)]
Path for the log file.

save

[logical(1)]
Whether the log file should be saved or not. Defaults to TRUE.

archive

[character(1)]
The path to the directory to save the log file. Defaults to NULL.

email

[logical(1)]
Whether an email with a report of the status in the log and the log file attached and the results file should be sent or not. Defaults to TRUE.

from

[character(1)]
The email address of the sender. Defaults to NULL.

to

[character]
The email address' of the recipients. Defaults to NULL.

email_subject

[character(1)]
Text to include in subject after "Status for running:" or "Error when running:". Defaults to 'log_file' without file extension.

include_text

[character(1)]
Text to include in the first part of the body of the email. Defaults to NULL.

attach_object

[character]
Full path and file name of object(s) to attach to the email. Defaults to NULL.

smtp_server

[character(1)]
The email server that sends the emails. Defaults to NULL.

...

Other arguments to be passed to gather_messages and sendmailR::sendmail.

Details

The function collects warnings and error messages from log file when a script has been run. The script must be set up to produce the log file. There the name and path of the log file will have been given.

The log file will be renamed so that the current date in the format "yyyymmdd" is included last in the file name before the file extension. This file should be permanently saved in an archive directory for example a subdirectory named "batchlog".

If an email should report the status, an email is produced. The subject of the email indicates whether the script run without problems or if warnings or error messages were produced. The log file is attached the email. If there are warnings or error messages, these are written in the email text.

It is possible include an short message first in the email text by giving it as input to the argument include_text. Such a message can give more information of the status of running the script. Such a message can be produced by the script and saved. Thereafter, the message can be fetched and be used as input to include_text.

Value

None. Saves the log after a script has been run and reports the error and warnings written in the log.

Author(s)

Petter Hopp Petter.Hopp@vetinst.no


NorwegianVeterinaryInstitute/NVIbatch documentation built on Dec. 15, 2024, 3:15 p.m.