Debian Codegraph @

R/logger_index.R

raw
1 #' Return a data.frame of all registered loggers
2 #'
3 #' @return a `logger_index` `data.frame`
4 #' @export
5 #' @seealso [logger_tree()] for a more visual representation of registered
6 #' loggers
7 #'
8 #' @examples
9 #' get_logger("tree/leaf")
10 #' get_logger("shrub/leaf")
11 #' get_logger("plant/shrub/leaf")
12 #' logger_index()
13 logger_index <- function(){
14
15 initialize_implicit_loggers()
16 names <- sort(ls(envir = loggers))
17 names <- union("root", names) # ensure root logger is sorted first
18
19 res <- lapply(names, function(logger_name){
20 cur_logger <- get_logger(logger_name)
21
22 data.frame(
23 name = logger_name,
24 configured = !is_virgin_Logger(logger_name),
25 threshold = cur_logger$threshold,
26 threshold_inherited = is_threshold_inherited(cur_logger),
27 propagate = cur_logger$propagate,
28 n_appenders = length(cur_logger$appenders)
29 )
30 })
31
32 res <- do.call(rbind, res)
33 structure(
34 res,
35 class = union("logger_index", class(res))
36 )
37 }
38
39
40
41 #' Initialize all loggers along all logger paths
42 #'
43 #' This is usually not necessary because all loggers along the path are
44 #' initialized the first time they are needed (even when printing a
45 #' logger!); however, it is sometimes necessary to do this explicitely
46 #' when calling `logger_index()`.
47 #' @noRd
48 initialize_implicit_loggers <- function(){
49 names <- sort(ls(envir = loggers))
50 for (n in names){
51 x <- unlist(strsplit(n, "/", fixed = TRUE))
52 for (i in seq_along(x)){
53 get_logger(paste(x[1:i], collapse = "/"))
54 }
55 }
56 }