Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ Description: Inspired by the the 'futile.logger' R package and 'logging'
License: AGPL-3
URL: https://daroczig.github.io/logger/
BugReports: https://github.com/daroczig/logger/issues
Depends:
Depends:
R (>= 4.0.0)
Imports:
glue,
utils
Suggests:
botor,
callr,
covr,
crayon,
devtools,
glue,
jsonlite,
knitr,
pander,
Expand All @@ -45,7 +45,7 @@ Enhances:
futile.logger,
log4r,
logging
VignetteBuilder:
VignetteBuilder:
knitr
Config/testthat/edition: 3
Config/testthat/parallel: TRUE
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# logger (development version)

* logger now imports glue, always making `formatter_glue()` the default.
* `log_appender()`, `log_layout()` and `log_formatter()` now check that you are calling them with a function, and return the previously set value.

# logger 0.3.0 (2024-03-03)
Expand Down
8 changes: 3 additions & 5 deletions R/formatters.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,19 @@ formatter_sprintf <- function(fmt,
attr(formatter_sprintf, "generator") <- quote(formatter_sprintf())

#' Apply `glue` to convert R objects into a character vector
#'
#' This is the default formatter.
#'
#' @param ... passed to `glue` for the text interpolation
#' @inheritParams log_level
#' @return character vector
#' @export
#' @note Although this is the default log message formatter function,
#' but when \pkg{glue} is not installed, [formatter_sprintf()]
#' will be used as a fallback.
#' @family `log_formatters`
#' @importFrom utils str
formatter_glue <- function(...,
.logcall = sys.call(),
.topcall = sys.call(-1),
.topenv = parent.frame()) {
fail_on_missing_package("glue")

withCallingHandlers(
glue::glue(..., .envir = .topenv),
error = function(e) {
Expand Down
3 changes: 1 addition & 2 deletions R/logger.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
#'
#' * [INFO()] (or as per the `LOGGER_LOG_LEVEL` environment variable override) as the log level threshold
#' * [layout_simple()] as the layout function showing the log level, timestamp and log message
#' * [formatter_glue()] (or [formatter_sprintf()] if \pkg{glue} is not installed) as the
#' default formatter function transforming the R objects to be logged to a character vector
#' * [formatter_glue()] as the default formatter function transforming the R objects to be logged to a character vector
#' * [appender_console()] as the default log record destination
#'
#' @param threshold omit log messages below this [log_levels()]
Expand Down
6 changes: 1 addition & 5 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,11 @@ namespaces_reset <- function() {
default = list(
threshold = as.loglevel(Sys.getenv("LOGGER_LOG_LEVEL", unset = "INFO")),
layout = layout_simple,
formatter = formatter_sprintf,
formatter = formatter_glue,
appender = if (in_pkgdown()) appender_stdout else appender_console
)
)

if (requireNamespace("glue", quietly = TRUE)) {
log_formatter(formatter_glue, namespace = "global", index = 1)
}

## internal namespace for debugging logger
namespaces$.logger <- list(
default = list(
Expand Down
2 changes: 1 addition & 1 deletion _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ reference:
- title: Formatters
desc: >
Log formatters control how the inputs to the `log_` functions are converted
to a string. The default is `formatter_glue()` when `glue` is installed.
to a string. The default is `formatter_glue()`.
contents:
- log_formatter
- starts_with("formatter_")
Expand Down
7 changes: 1 addition & 6 deletions man/formatter_glue.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/logger.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vignettes/customize_logger.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ log_info("There are {nrow(mtcars)} cars in the mtcars dataset")
log_info("2 + 2 = {2+2}")
```

If you don't like this syntax, or want to save a dependency, you can use other formatter functions as well, such as `?formatter_sprintf` (being the default in eg the [`logging` and `futile.logger` packages](https://daroczig.github.io/logger/articles/migration.html)) or `?formatter_paste`, or [write your own formatter function](https://daroczig.github.io/logger/articles/write_custom_extensions.html) converting R objects into string.
If you don't like this syntax you can use other formatter functions as well, such as `?formatter_sprintf` (being the default in eg the [`logging` and `futile.logger` packages](https://daroczig.github.io/logger/articles/migration.html)) or `?formatter_paste`, or [write your own formatter function](https://daroczig.github.io/logger/articles/write_custom_extensions.html) converting R objects into string.

## Log message layouts

Expand Down