Functions to manage archiving of logs at Rapporteket. To be applied mainly as helpers within the raplog package.
createArchive(archivePath) logsOverSize(logPath, overSize = 1024 * 1000, pattern = ".csv$") archiveLog(archivePath, logPath, logs = c("appLog.csv", "reportLog.csv")) cleanArchive(archivePath, eolDays = -1, pattern = ".rda$")
archivePath | String providing the path to the archive directory |
---|---|
logPath | String providing the path to the log directory |
overSize | Integer size in bytes from where larger files will be listed as candidates for archiving. Default value set to 1 Mb (1024 * 1000) |
pattern | String regexp defining file name pattern |
logs | String vector defining the log file names. Defaults to
|
eolDays | Integer age in days definig archive file end-of-life. When
|
crateArchive
simply creates a directory for the archived files to
live in.
logsOverSize
provides a character vector of relevant files
for archiving based on the given size limit and file name pattern.
archiveLog
do the actual archiving and deletes the source log files
after the archive files where sucessfully created. Returns prematurely NULL
if no log file(s) provided
cleanArchive
deletes files from the archive as their days are
numbered.
# Create an archive createArchive(archivePath = tempfile()) # List all files (with alphanumeric names) larger than 1 Kb in tempdir() logsOverSize(logPath = tempdir(), overSize = 1024, pattern = "^[1-9a-zA-Z]")#> [1] "file3ac249fdc07.so" "libloc_173_c7ca16f4b15c0cc.rds" #> [3] "libloc_183_27f76f287b614bfa.rds"# Archive a file under the same directory fileName <- paste0(tempfile(), ".csv") file.create(fileName)#> [1] TRUEwrite.csv(mtcars, fileName) archiveLog(archivePath = dirname(fileName), logPath = dirname(fileName), logs = c(basename(fileName)))#> [1] TRUE#> NULL