Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #174 restyle with styler::style_dir #185

Merged
merged 13 commits into from
Aug 7, 2024
34 changes: 34 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

name: lint.yaml

permissions: read-all

jobs:
lint:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::lintr, local::.
needs: lint

- name: Lint
run: lintr::lint_package()
shell: Rscript {0}
env:
LINTR_ERROR_ON_LINT: true
12 changes: 12 additions & 0 deletions .lintr
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
linters: linters_with_defaults(
line_length_linter(120),
object_usage_linter(interpret_glue = TRUE),
object_name_linter(styles = c("snake_case", "symbols", "UPPERCASE"))
)
exclude: '# nolint'
exclude_start: '# nolint start'
exclude_end: '# nolint end'
exclusions: list(
"inst/demo-packages/logger-tester-package/R/tester.R",
"vignettes/migration.Rmd"
)
632 changes: 351 additions & 281 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
Loading