Skip to content

Commit

Permalink
fix #174 restyle with styler::style_dir
Browse files Browse the repository at this point in the history
  • Loading branch information
daroczig committed Aug 7, 2024
1 parent 3ef4b65 commit 55bbe80
Show file tree
Hide file tree
Showing 61 changed files with 1,859 additions and 1,836 deletions.
506 changes: 252 additions & 254 deletions R/appenders.R

Large diffs are not rendered by default.

94 changes: 44 additions & 50 deletions R/color.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,65 +3,59 @@
#' Color log messages according to their severity with either a rainbow
#' or grayscale color scheme. The greyscale theme assumes a dark background on
#' the terminal.
#'
#'
#' @param msg String to color.
#' @param level see [log_levels()]
#' @return A string with ANSI escape codes.
#' @export
#' @examplesIf requireNamespace("crayon")
#' cat(colorize_by_log_level('foobar', FATAL), '\n')
#' cat(colorize_by_log_level('foobar', ERROR), '\n')
#' cat(colorize_by_log_level('foobar', WARN), '\n')
#' cat(colorize_by_log_level('foobar', SUCCESS), '\n')
#' cat(colorize_by_log_level('foobar', INFO), '\n')
#' cat(colorize_by_log_level('foobar', DEBUG), '\n')
#' cat(colorize_by_log_level('foobar', TRACE), '\n')
#'
#' cat(grayscale_by_log_level('foobar', FATAL), '\n')
#' cat(grayscale_by_log_level('foobar', ERROR), '\n')
#' cat(grayscale_by_log_level('foobar', WARN), '\n')
#' cat(grayscale_by_log_level('foobar', SUCCESS), '\n')
#' cat(grayscale_by_log_level('foobar', INFO), '\n')
#' cat(grayscale_by_log_level('foobar', DEBUG), '\n')
#' cat(grayscale_by_log_level('foobar', TRACE), '\n')
#' cat(colorize_by_log_level("foobar", FATAL), "\n")
#' cat(colorize_by_log_level("foobar", ERROR), "\n")
#' cat(colorize_by_log_level("foobar", WARN), "\n")
#' cat(colorize_by_log_level("foobar", SUCCESS), "\n")
#' cat(colorize_by_log_level("foobar", INFO), "\n")
#' cat(colorize_by_log_level("foobar", DEBUG), "\n")
#' cat(colorize_by_log_level("foobar", TRACE), "\n")
#'
#' cat(grayscale_by_log_level("foobar", FATAL), "\n")
#' cat(grayscale_by_log_level("foobar", ERROR), "\n")
#' cat(grayscale_by_log_level("foobar", WARN), "\n")
#' cat(grayscale_by_log_level("foobar", SUCCESS), "\n")
#' cat(grayscale_by_log_level("foobar", INFO), "\n")
#' cat(grayscale_by_log_level("foobar", DEBUG), "\n")
#' cat(grayscale_by_log_level("foobar", TRACE), "\n")
colorize_by_log_level <- function(msg, level) {

fail_on_missing_package('crayon')

color <- switch(
attr(level, 'level'),
'FATAL' = crayon::combine_styles(crayon::bold, crayon::make_style('red1')),
'ERROR' = crayon::make_style('red4'),
'WARN' = crayon::make_style('darkorange'),
'SUCCESS' = crayon::combine_styles(crayon::bold, crayon::make_style('green4')),
'INFO' = crayon::reset,
'DEBUG' = crayon::make_style('deepskyblue4'),
'TRACE' = crayon::make_style('dodgerblue4'),
stop('Unknown log level')
)

paste0(color(msg), crayon::reset(''))

fail_on_missing_package("crayon")

color <- switch(attr(level, "level"),
"FATAL" = crayon::combine_styles(crayon::bold, crayon::make_style("red1")),
"ERROR" = crayon::make_style("red4"),
"WARN" = crayon::make_style("darkorange"),
"SUCCESS" = crayon::combine_styles(crayon::bold, crayon::make_style("green4")),
"INFO" = crayon::reset,
"DEBUG" = crayon::make_style("deepskyblue4"),
"TRACE" = crayon::make_style("dodgerblue4"),
stop("Unknown log level")
)

paste0(color(msg), crayon::reset(""))
}

#' @export
#' @rdname colorize_by_log_level
grayscale_by_log_level <- function(msg, level) {

fail_on_missing_package('crayon')

color <- switch(
attr(level, 'level'),
'FATAL' = crayon::make_style('gray100'),
'ERROR' = crayon::make_style('gray90'),
'WARN' = crayon::make_style('gray80'),
'SUCCESS' = crayon::make_style('gray70'),
'INFO' = crayon::make_style('gray60'),
'DEBUG' = crayon::make_style('gray50'),
'TRACE' = crayon::make_style('gray40'),
stop('Unknown log level')
)

paste0(color(msg), crayon::reset(''))

fail_on_missing_package("crayon")

color <- switch(attr(level, "level"),
"FATAL" = crayon::make_style("gray100"),
"ERROR" = crayon::make_style("gray90"),
"WARN" = crayon::make_style("gray80"),
"SUCCESS" = crayon::make_style("gray70"),
"INFO" = crayon::make_style("gray60"),
"DEBUG" = crayon::make_style("gray50"),
"TRACE" = crayon::make_style("gray40"),
stop("Unknown log level")
)

paste0(color(msg), crayon::reset(""))
}
Loading

0 comments on commit 55bbe80

Please sign in to comment.