11context(" Logger" )
22
33
4+ # Logger ------------------------------------------------------------------
5+
6+
47
58test_that(" logging conditions works" , {
69 e <- error(" blahblah" )
@@ -379,11 +382,17 @@ test_that("$config works with lists", {
379382
380383
381384
385+ # Multi-Logger tests -------------------------------------------------------------
382386
383387test_that(" Logger$log() dispatches to all appenders, even if some throw an error" , {
384388 ln <- Logger $ new(" normal" , propagate = FALSE )
385389 lg <- LoggerGlue $ new(" glue" , propagate = FALSE )
386390
391+ on.exit({
392+ ln $ config(NULL )
393+ lg $ config(NULL )
394+ })
395+
387396 AppErr <- R6 :: R6Class(
388397 inherit = AppenderConsole ,
389398 public = list (
@@ -416,6 +425,11 @@ test_that("Logger error contains useful call object", {
416425 l <- get_logger(" test" )
417426 g <- get_logger_glue(" testglue" )
418427
428+ on.exit({
429+ l $ config(NULL )
430+ g $ config(NULL )
431+ })
432+
419433 expect_warning(l $ info(" this will fail" , e = stop()), " l\\ $info" )
420434 expect_warning(g $ info(" this will fail" , e = stop()), " g\\ $info" )
421435})
@@ -428,6 +442,11 @@ test_that("Appender error contains useful call object", {
428442 l <- get_logger(" test" )$ set_propagate(FALSE )
429443 g <- get_logger_glue(" testglue" )$ set_propagate(FALSE )
430444
445+ on.exit({
446+ l $ config(NULL )
447+ g $ config(NULL )
448+ })
449+
431450 AppenderFail <- R6 :: R6Class(
432451 " AppenderFail" ,
433452 inherit = Appender ,
@@ -445,3 +464,24 @@ test_that("Appender error contains useful call object", {
445464 expect_warning(g $ info(" this will fail" ), " .*AppenderFail.*g\\ $info" )
446465})
447466
467+
468+
469+
470+ test_that(" .rawMsg works" , {
471+ l <- get_logger(" test" )$ set_propagate(FALSE )
472+ g <- get_logger_glue(" testglue" )$ set_propagate(FALSE )
473+
474+ on.exit({
475+ l $ config(NULL )
476+ g $ config(NULL )
477+ })
478+
479+ l $ info(" foo %s" , " bar" )
480+ g $ fatal(" hash {x}" , x = " baz" )
481+
482+ expect_identical(l $ last_event $ msg , " foo bar" )
483+ expect_identical(l $ last_event $ .rawMsg , " foo %s" )
484+
485+ expect_identical(as.character(g $ last_event $ msg ), " hash baz" )
486+ expect_identical(g $ last_event $ .rawMsg , " hash {x}" )
487+ })
0 commit comments