Skip to content

Commit bf64ad7

Browse files
committed
implements format.logger_tree and adds logger_tree to pkgdown function reference
1 parent ffa6ca6 commit bf64ad7

38 files changed

+1014
-703
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ S3method(as_logger_config,list)
77
S3method(format,LogEvent)
88
S3method(format,Logger)
99
S3method(format,ancestry)
10+
S3method(format,logger_tree)
1011
S3method(print,Appender)
1112
S3method(print,LogEvent)
1213
S3method(print,Logger)

R/logger_tree.R

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
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.
@@ -31,10 +31,9 @@
3131
#' get_logger("fancymodel/plumber")
3232
#'
3333
#' if (requireNamespace("cli")){
34-
#' logger_tree()
34+
#' print(logger_tree())
3535
#' }
3636
#'
37-
#' "blah"
3837
logger_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
}

_pkgdown.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ reference:
55
- Logger
66
- print.Logger
77
- print.ancestry
8+
- logger_tree
9+
- print.logger_tree
810
- default_exception_handler
911
- get_log_levels
1012
- simple_logging

docs/articles/index.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/articles/lgr-simple.html

Lines changed: 0 additions & 146 deletions
This file was deleted.

0 commit comments

Comments
 (0)