Skip to content

Commit

Permalink
mnt: Clean up read_logs and rotate_logs
Browse files Browse the repository at this point in the history
  • Loading branch information
MEO265 committed Jan 8, 2024
1 parent bdefc3d commit 64bfba1
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
}

0 comments on commit 64bfba1

Please sign in to comment.