Skip to content

Commit

Permalink
transform to loglevel in time
Browse files Browse the repository at this point in the history
  • Loading branch information
daroczig committed Mar 4, 2024
1 parent 58abfc4 commit fed038f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
3 changes: 1 addition & 2 deletions R/logger.R
Original file line number Diff line number Diff line change
Expand Up @@ -303,14 +303,13 @@ log_level <- function(level, ..., namespace = NA_character_,
}

definitions <- get_logger_definitions(namespace, .topenv = .topenv)
level <- validate_log_level(level)

## super early return (even before evaluating passed parameters)
if (length(definitions) == 1 && level > definitions[[1]]$threshold) {
return(invisible(NULL))
}

level <- validate_log_level(level)

log_arg <- list(...)
log_arg$level <- level
log_arg$.logcall <- .logcall
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-CRANSKIP-hooks.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ test_that('shiny input initialization is detected with different log-level', {
.globals <- shiny:::.globals
.globals$appState <- new.env(parent = emptyenv())
server <- function(input, output, session) {
logger::log_shiny_input_changes(input, level = 'ERROR')
logger::log_shiny_input_changes(input, level = logger::ERROR)
}
shiny::testServer(server, {})
"
Expand Down Expand Up @@ -89,7 +89,7 @@ test_that('shiny input change is logged with different level', {
.globals <- shiny:::.globals
.globals$appState <- new.env(parent = emptyenv())
server <- function(input, output, session) {
logger::log_shiny_input_changes(input, level = 'ERROR')
logger::log_shiny_input_changes(input, level = logger::ERROR)
x <- shiny::reactive(input$a)
}
shiny::testServer(server, {
Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/test-logger.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ test_that('log levels', {
expect_output(log_info('foo'), NA)
expect_output(log_debug('foo'), NA)
expect_output(log_trace('foo'), NA)
expect_output(log_level('ERROR', 'foo'), 'ERROR.*foo')
expect_output(log_level(ERROR, 'foo'), 'ERROR.*foo')
expect_output(log_level(as.loglevel(ERROR), 'foo'), 'ERROR.*foo')
expect_output(log_level(as.loglevel('ERROR'), 'foo'), 'ERROR.*foo')
expect_output(log_level(as.loglevel(200L), 'foo'), 'ERROR.*foo')
expect_output(log_level('TRACE', 'foo'), NA)
expect_output(log_level(TRACE, 'foo'), NA)
expect_output(log_level(as.loglevel(TRACE), 'foo'), NA)
expect_output(log_level(as.loglevel('TRACE'), 'foo'), NA)
expect_output(log_level(as.loglevel(600L), 'foo'), NA)
Expand Down

0 comments on commit fed038f

Please sign in to comment.