Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
05aff40
Enhance set_call_options: add argument validation and warning for une…
MEO265 May 29, 2025
ece5fcd
Fix lintr comments
MEO265 May 29, 2025
c444425
Add tests for setup_call_options function
MEO265 May 29, 2025
ee728b6
Fix lintr comments
MEO265 May 29, 2025
f879d79
Add tests to warn on use of reserved fields in loggit function
MEO265 May 29, 2025
b559f9a
Add tests for loggit function to verify call options handling
MEO265 May 29, 2025
4c4b1e9
Add tests for loggit function to verify call options handling II (FIX)
MEO265 May 29, 2025
d38398d
`get_package_name` can handle primitives
MEO265 May 29, 2025
907e6d6
Add tests for `get_package_name` and `get_file_loc`
MEO265 May 29, 2025
36d3520
Enhance `call_2_string` function to support default cutoff for call s…
MEO265 May 29, 2025
87d87b8
Add test for call_2_string to verify handling of external calls in fu…
MEO265 May 29, 2025
303d456
Enhance `call_2_string` to include default cutoff parameter for call …
MEO265 May 29, 2025
4334c6b
Fix lintr comments
MEO265 May 29, 2025
1c0082f
Refactor lintr configuration and update test for call_2_string to use…
MEO265 May 29, 2025
fd9af3a
Fix test for call_2_string to use integer literals in external call
MEO265 May 29, 2025
75fa4cc
Add test for call_2_string to verify behavior with condition handler
MEO265 Jun 1, 2025
f59f635
Add debuginfo log handler and update documentation
MEO265 Jun 1, 2025
1de601d
Merge branch 'main' of https://github.com/MEO265/loggit2 into tests/s…
MEO265 Jun 1, 2025
65756c6
Enhance documentation for logging functions by adding parameter `.log…
MEO265 Jun 1, 2025
a746fa8
Add non-base log handlers section to pkgdown documentation
MEO265 Jun 1, 2025
0f2683c
Remove unnecessary blank line in handlers_non_base.R
MEO265 Jun 1, 2025
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
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Generated by roxygen2: do not edit by hand

export(convert_to_csv)
export(debuginfo)
export(get_call_options)
export(get_echo)
export(get_log_level)
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## New Features
* `set_call_options()` offers new option to log condition calls or even the full call stack. `get_call_options()` returns the current settings.
* All condition log handlers e.g. `warning()` and `with_loggit()` now support call logging.
* Added `debuginfo()` as an additional log handler for debugging purposes.

## Minor Changes
* `loggit()` now checks the `...` arguments for use of reserved names, currently `log_call` and `timestamp`.
Expand Down
32 changes: 32 additions & 0 deletions R/handlers_non_base.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#' Debug Log Handler
#'
#' This function works like base R's [`warning`][base::warning] ,
#' but is silent, includes logging of the exception message via `loggit()` and does not allow conditions as input.
#'
#' @inherit base::warning params
#' @inherit message params
#' @inheritParams loggit
#'
#' @return No return value.
#'
#' @family handlers
#'
#' @examples
#' \dontrun{
#' debuginfo("This is a completely false condition")
#'
#' debuginfo("This is a completely false condition", echo = FALSE)
#' }
#'
#' @details This function is more than just a wrapper around `loggit()` with a log level of "DEBUG".
#' It has the ability to track the call stack and log it if `call.` is set to `TRUE` and to automatically
#' translate the input into a message using `.makeMessage()`, like `warning()` does.
#'
#' @export
debuginfo <- function(..., call. = TRUE, .loggit = NA, echo = get_echo()) {
# The call of the error must be set manually for loggit_internal
call <- if (call.) find_call()
if (isTRUE(.loggit) || (!isFALSE(.loggit) && get_log_level() >= 4L)) {
loggit_internal(log_lvl = "DEBUG", log_msg = .makeMessage(..., domain = NULL), log_call = call, echo = echo)
}
}
4 changes: 2 additions & 2 deletions man/call_2_string.Rd

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

49 changes: 49 additions & 0 deletions man/debuginfo.Rd

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

1 change: 1 addition & 0 deletions man/message.Rd

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

1 change: 1 addition & 0 deletions man/stop.Rd

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

1 change: 1 addition & 0 deletions man/stopifnot.Rd

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

1 change: 1 addition & 0 deletions man/warning.Rd

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

3 changes: 3 additions & 0 deletions pkgdown/_pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ reference:
- "warning"
- "stop"
- "stopifnot"
- title: Non-base log handlers
- contents:
- "debuginfo"
- title: Log functions
- contents:
- "loggit"
Expand Down
47 changes: 47 additions & 0 deletions tests/testthat/test-handlers_non_base.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
test_that("debuginfo echos", {
expect_output(debuginfo("This is a debug test", echo = TRUE), "This is a debug test")
})
cleanup()

test_that("debuginfo logs message at DEBUG level", {
# silent output
expect_silent(debuginfo("This is a debug test", echo = FALSE))

logdata <- read_logs()
logdata <- logdata[nrow(logdata),]

expect_identical(logdata[["log_lvl"]], "DEBUG")
expect_identical(logdata[["log_msg"]], "This is a debug test")
})
cleanup()

test_that("debuginfo concatenates multiple arguments", {
expect_silent(debuginfo("This ", "is ", "a debug test", echo = FALSE))

logdata <- read_logs()
logdata <- logdata[nrow(logdata),]

expect_identical(logdata[["log_lvl"]], "DEBUG")
expect_identical(logdata[["log_msg"]], "This is a debug test")
})
cleanup()

test_that("debuginfo respects call. argument without error", {
# call. = TRUE should not error
f <- function() debuginfo("call test", call. = TRUE, echo = FALSE)
expect_silent(f())

# call. = FALSE should not error and still log
expect_silent(debuginfo("no call", call. = FALSE, echo = FALSE))
logdata <- read_logs()
expect_identical(logdata[["log_lvl"]], c("DEBUG", "DEBUG"))
expect_identical(logdata[["log_msg"]], c("call test", "no call"))
})
cleanup()

test_that("debuginfo does not log on log level below DEBUG", {
old_level <- set_log_level(3L, confirm = FALSE)
expect_silent(debuginfo("This should not log"))
expect_error(read_logs(), "Log file does not exist", fixed = TRUE)
set_log_level(old_level, confirm = FALSE)
})
11 changes: 11 additions & 0 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,14 @@ test_that("call_2_string (full_stack=TRUE) handels call not in current context",
endsWith(call_2_string(ext_call, full_stack = TRUE), "Original Call: some_function(1L, 2L)")
)
})

test_that("test call_2_string (cut off) via condition handler", {
old <- set_call_options(log_call = TRUE, full_stack = TRUE, confirm = FALSE)
# Function is needed to create a predictable call stack and a call to cut off
f <- function() warning("This is a warning", echo = FALSE)
expect_warning(f(), "This is a warning")
logdata <- read_logs()
expect_true(grepl(logdata[["log_call"]], pattern = "f()"))
set_call_options(.arg_list = old, confirm = FALSE)
})
cleanup()