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

Include log_level args explicitly in log_* wrappers #143

Merged
merged 5 commits into from
Mar 3, 2024
Merged
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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Date: 2021-10-10
URL: https://daroczig.github.io/logger/
BugReports: https://github.com/daroczig/logger/issues
Encoding: UTF-8
RoxygenNote: 7.1.2
RoxygenNote: 7.3.1
License: AGPL-3
Imports:
utils
Expand Down
56 changes: 35 additions & 21 deletions R/logger.R
Original file line number Diff line number Diff line change
Expand Up @@ -223,19 +223,26 @@ log_namespaces <- function() {
#' log_level(level, ..., namespace = NA_character_,
#' .logcall = sys.call(), .topcall = sys.call(-1), .topenv = parent.frame())
#'
#' log_trace(...)
#' log_trace(..., namespace = NA_character_,
#' .logcall = sys.call(), .topcall = sys.call(-1), .topenv = parent.frame())
#'
#' log_debug(...)
#' log_debug(..., namespace = NA_character_,
#' .logcall = sys.call(), .topcall = sys.call(-1), .topenv = parent.frame())
#'
#' log_info(...)
#' log_info(..., namespace = NA_character_,
#' .logcall = sys.call(), .topcall = sys.call(-1), .topenv = parent.frame())
#'
#' log_success(...)
#' log_success(..., namespace = NA_character_,
#' .logcall = sys.call(), .topcall = sys.call(-1), .topenv = parent.frame())
#'
#' log_warn(...)
#' log_warn(..., namespace = NA_character_,
#' .logcall = sys.call(), .topcall = sys.call(-1), .topenv = parent.frame())
#'
#' log_error(...)
#' log_error(..., namespace = NA_character_,
#' .logcall = sys.call(), .topcall = sys.call(-1), .topenv = parent.frame())
#'
#' log_fatal(...)
#' log_fatal(..., namespace = NA_character_,
#' .logcall = sys.call(), .topcall = sys.call(-1), .topenv = parent.frame())
#' @examples \dontrun{
#' log_level(INFO, 'hi there')
#' log_info('hi there')
Expand Down Expand Up @@ -312,32 +319,39 @@ validate_log_level <- function(level) {


#' @export
log_fatal <- function(...) {
log_level(FATAL, ..., .logcall = sys.call(), .topcall = sys.call(-1), .topenv = parent.frame())
log_fatal <- function(..., namespace = NA_character_,
.logcall = sys.call(), .topcall = sys.call(-1), .topenv = parent.frame()) {
log_level(FATAL, ..., namespace = namespace, .logcall = .logcall, .topcall = .topcall, .topenv = .topenv)
}
#' @export
log_error <- function(...) {
log_level(ERROR, ..., .logcall = sys.call(), .topcall = sys.call(-1), .topenv = parent.frame())
log_error <- function(..., namespace = NA_character_,
.logcall = sys.call(), .topcall = sys.call(-1), .topenv = parent.frame()) {
log_level(ERROR, ..., namespace = namespace, .logcall = .logcall, .topcall = .topcall, .topenv = .topenv)
}
#' @export
log_warn <- function(...) {
log_level(WARN, ..., .logcall = sys.call(), .topcall = sys.call(-1), .topenv = parent.frame())
log_warn <- function(..., namespace = NA_character_,
.logcall = sys.call(), .topcall = sys.call(-1), .topenv = parent.frame()) {
log_level(WARN, ..., namespace = namespace, .logcall = .logcall, .topcall = .topcall, .topenv = .topenv)
}
#' @export
log_success <- function(...) {
log_level(SUCCESS, ..., .logcall = sys.call(), .topcall = sys.call(-1), .topenv = parent.frame())
log_success <- function(..., namespace = NA_character_,
.logcall = sys.call(), .topcall = sys.call(-1), .topenv = parent.frame()) {
log_level(SUCCESS, ..., namespace = namespace, .logcall = .logcall, .topcall = .topcall, .topenv = .topenv)
}
#' @export
log_info <- function(...) {
log_level(INFO, ..., .logcall = sys.call(), .topcall = sys.call(-1), .topenv = parent.frame())
log_info <- function(..., namespace = NA_character_,
.logcall = sys.call(), .topcall = sys.call(-1), .topenv = parent.frame()) {
log_level(INFO, ..., namespace = namespace, .logcall = .logcall, .topcall = .topcall, .topenv = .topenv)
}
#' @export
log_debug <- function(...) {
log_level(DEBUG, ..., .logcall = sys.call(), .topcall = sys.call(-1), .topenv = parent.frame())
log_debug <- function(..., namespace = NA_character_,
.logcall = sys.call(), .topcall = sys.call(-1), .topenv = parent.frame()) {
log_level(DEBUG, ..., namespace = namespace, .logcall = .logcall, .topcall = .topcall, .topenv = .topenv)
}
#' @export
log_trace <- function(...) {
log_level(TRACE, ..., .logcall = sys.call(), .topcall = sys.call(-1), .topenv = parent.frame())
log_trace <- function(..., namespace = NA_character_,
.logcall = sys.call(), .topcall = sys.call(-1), .topenv = parent.frame()) {
log_level(TRACE, ..., namespace = namespace, .logcall = .logcall, .topcall = .topcall, .topenv = .topenv)
}


Expand Down
21 changes: 14 additions & 7 deletions man/log_level.Rd

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

1 change: 1 addition & 0 deletions tests/testthat/test-layout.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ test_that('must throw errors', {

log_layout(layout_logging)
test_that('logging layout', {
expect_output(log_level(INFO, 'foo', namespace = 'bar'), 'INFO:bar:foo')
expect_output(log_info('foobar'), 'INFO')
expect_output(log_info('foo', namespace = 'bar'), 'foo')
expect_output(log_info('foo', namespace = 'bar'), 'bar')
Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/test-logger.R
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ test_that('config setter called from do.call', {
unlink(t)
})

test_that('providing log_level() args to wrappers diretly is OK', {
expect_silent(log_info('{Sepal.Length}', .topenv = iris))
})

## reset settings
log_threshold(threshold)
log_layout(layout)
Expand Down
Loading