55# ' @section Symbology:
66# '
77# ' * unconfigured Loggers are displayed in gray (if your terminal supports
8- # ' colors and you have the package ** crayon** installed).
8+ # ' colors and you have the package \pkg{ crayon} installed).
99# ' * If a logger's `threshold` is set, it is displayed in square brackets next
1010# ' to the logger name. If the threshold is not set, it inherits the threshold
1111# ' of the next logger up the logger tree.
3131# ' get_logger("fancymodel/plumber")
3232# '
3333# ' if (requireNamespace("cli")){
34- # ' logger_tree()
34+ # ' print( logger_tree() )
3535# ' }
3636# '
37- # ' "blah"
3837logger_tree <- function (
3938){
4039 names <- ls(envir = loggers )
@@ -103,12 +102,45 @@ logger_tree <- function(
103102# ' Print Logger Trees
104103# '
105104# ' @param x a [logger_tree][logger_tree()]
106- # ' @param ... pased on to [cli::tree]#'
105+ # ' @param color `logical` scalar. If `TRUE` terminal output is colorized via
106+ # ' the package \pkg{crayon}?
107+ # ' @param ... pased on to [cli::tree()]
107108# ' @return `x` (invisibly)
108109# ' @export
109- print.logger_tree <- function (x , ... ){
110+ print.logger_tree <- function (
111+ x ,
112+ color = requireNamespace(" crayon" , quietly = TRUE ),
113+ ...
114+ ){
115+ if (requireNamespace(" cli" , quietly = TRUE )){
116+ cat(format(x , color = color , ... ), sep = " \n " )
117+ } else {
118+ warning(
119+ " Console output of logger trees requires the package 'cli'. You can" ,
120+ " install it with `install.packages(\" cli\" )`."
121+ )
122+ print(as.data.frame(x ))
123+ }
124+ invisible (x )
125+ }
126+
127+
128+
129+
130+ # ' @rdname print.logger_tree
131+ # ' @export
132+ format.logger_tree <- function (
133+ x ,
134+ color = FALSE ,
135+ ...
136+ ){
110137 assert_namespace(" cli" )
111138
139+ if (! color ){
140+ style_fatal <- identity
141+ style_color <- identity
142+ }
143+
112144 label <- ifelse(x $ configured , x $ parent , style_subtle(x $ parent ))
113145 label <- ifelse(
114146 x $ threshold_inherited ,
@@ -132,6 +164,5 @@ print.logger_tree <- function(x, ...){
132164 label = label
133165 )
134166
135- print(cli :: tree(x_print , root = " root" , ... ))
136- x
167+ format(cli :: tree(x_print , root = " root" , ... ))
137168}
0 commit comments