From 64bfba124472789031fe1126844d52b7545c9009 Mon Sep 17 00:00:00 2001 From: MEO265 <99362508+MEO265@users.noreply.github.com> Date: Mon, 8 Jan 2024 20:24:03 +0100 Subject: [PATCH] mnt: Clean up `read_logs` and `rotate_logs` --- R/utils.R | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/R/utils.R b/R/utils.R index 0a94379..613cff0 100644 --- a/R/utils.R +++ b/R/utils.R @@ -17,16 +17,10 @@ #' read_logs() #' #' @export -read_logs <- function(logfile, unsanitizer) { - if (missing(unsanitizer)) { - unsanitizer <- default_ndjson_unsanitizer - } - - if (missing(logfile)) logfile <- get_logfile() - if (!file.exists(logfile)) { - base::stop("Log file does not exist") - } - +read_logs <- function(logfile = get_logfile(), unsanitizer = default_ndjson_unsanitizer) { + + stopifnot("Log file does not exist" = file.exists(logfile)) + read_ndjson(logfile, unsanitizer = unsanitizer) } @@ -57,9 +51,8 @@ read_logs <- function(logfile, unsanitizer) { #' rotate_logs(250, another_log) #' #' @export -rotate_logs <- function(rotate_lines = 100000, logfile) { - if (missing(logfile)) logfile <- get_logfile() +rotate_logs <- function(rotate_lines = 100000L, logfile = get_logfile()) { log_df <- read_logs(logfile) - log_df <- log_df[(nrow(log_df) - rotate_lines + 1):nrow(log_df), ] + log_df <- log_df[(nrow(log_df) - rotate_lines + 1L):nrow(log_df),] write_ndjson(log_df, logfile, echo = FALSE, overwrite = TRUE) }