daroczig / logger

A lightweight, modern and flexible, log4j and futile.logger inspired logging utility for R
https://daroczig.github.io/logger
280 stars 41 forks source link

`formatter_glue_or_sprintf`: error if `msg` is of length zero #74

Closed deeenes closed 10 months ago

deeenes commented 3 years ago

If the first argument for the log_* functions is a zero length vector the following error happens:

library(logger)
log_formatter(formatter_glue_or_sprintf)
log_success(character(0))
Error in regmatches(msg, gregexpr("%[0-9.+0]*[aAdifeEgGosxX]", msg))[[1]] : 
  subscript out of bounds

From here: https://github.com/daroczig/logger/blob/e88153b49678227f693115d0ca19c73cf87e355a/R/formatters.R#L83

I think this can happen easily in an unpredictable way, so would be nice to handle without error. Because there is no message, for logger the best would be to output nothing (or maybe one empty line).

daroczig commented 10 months ago

thanks for the report :+1: