From 2512a14ec140796aa0c7211ab7a5631c1a77a931 Mon Sep 17 00:00:00 2001 From: Jonathan Carroll Date: Wed, 29 Oct 2025 21:13:00 +1030 Subject: [PATCH 1/5] add ntfy appender --- DESCRIPTION | 9 ++++++--- NAMESPACE | 1 + R/appenders.R | 28 ++++++++++++++++++++++++++++ man/appender_async.Rd | 1 + man/appender_console.Rd | 1 + man/appender_file.Rd | 1 + man/appender_kinesis.Rd | 1 + man/appender_ntfy.Rd | 36 ++++++++++++++++++++++++++++++++++++ man/appender_pushbullet.Rd | 1 + man/appender_slack.Rd | 1 + man/appender_stdout.Rd | 1 + man/appender_syslog.Rd | 3 ++- man/appender_tee.Rd | 1 + man/appender_telegram.Rd | 1 + man/colorize_by_log_level.Rd | 2 +- man/layout_glue_colors.Rd | 2 +- man/logger-package.Rd | 1 + 17 files changed, 85 insertions(+), 6 deletions(-) create mode 100644 man/appender_ntfy.Rd diff --git a/DESCRIPTION b/DESCRIPTION index c140eaf2..d9644cf7 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,13 +1,15 @@ Type: Package Package: logger Title: A Lightweight, Modern and Flexible Logging Utility -Version: 0.4.1.9000 -Date: 2025-09-09 +Version: 0.4.1.9001 +Date: 2025-10-29 Authors@R: c( person("Gergely", "Daróczi", , "daroczig@rapporter.net", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-3149-8537")), person("Hadley", "Wickham", , "hadley@posit.co", role = "aut", comment = c(ORCID = "0000-0003-4757-117X")), + person("Jonathan", "Carroll", , "rpkg@jcarroll.com.au", role = "ctb", + comment = c(ORCID = "0000-0002-1404-5264")), person("Spare Cores", role = "fnd"), person("System1", role = "fnd") ) @@ -31,6 +33,7 @@ Suggests: jsonlite, knitr, mirai (>= 1.3.0), + ntfy, pander, parallel, R.utils, @@ -54,4 +57,4 @@ Config/testthat/edition: 3 Config/testthat/parallel: TRUE Encoding: UTF-8 Roxygen: list(markdown = TRUE) -RoxygenNote: 7.3.2 +RoxygenNote: 7.3.3 diff --git a/NAMESPACE b/NAMESPACE index 58311624..baad7eeb 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -18,6 +18,7 @@ export(appender_async) export(appender_console) export(appender_file) export(appender_kinesis) +export(appender_ntfy) export(appender_pushbullet) export(appender_slack) export(appender_stderr) diff --git a/R/appenders.R b/R/appenders.R index 86e1de51..1ab4c9b0 100644 --- a/R/appenders.R +++ b/R/appenders.R @@ -232,6 +232,34 @@ appender_pushbullet <- function(...) { } +#' Send log messages to ntfy +#' @param ... parameters passed to [ntfy::ntfy_send], such as `title` +#' or `tags`. +#' +#' @details Configure server and topic via environment variables. See +#' [ntfy::ntfy_topic()] for details. +#' +#' @export +#' @note This functionality depends on the \pkg{ntfy} package. +#' @family log_appenders +#' @export +appender_ntfy <- function(title = "{logger}", + tags = c("memo"), + ...) { + fail_on_missing_package("ntfy") + force(title) + force(tags) + + structure( + function(lines) { + ntfy::ntfy_send(title = title, tags = tags, message = paste(lines, sep = "\n"), ...) + }, + generator = deparse(match.call()) + ) +} + + + #' Send log messages to a Telegram chat #' @param chat_id Unique identifier for the target chat or username of #' the target channel (in the format @channelusername) diff --git a/man/appender_async.Rd b/man/appender_async.Rd index 821e17ce..ed6dd38f 100644 --- a/man/appender_async.Rd +++ b/man/appender_async.Rd @@ -68,6 +68,7 @@ Other log_appenders: \code{\link{appender_console}()}, \code{\link{appender_file}()}, \code{\link{appender_kinesis}()}, +\code{\link{appender_ntfy}()}, \code{\link{appender_pushbullet}()}, \code{\link{appender_slack}()}, \code{\link{appender_stdout}()}, diff --git a/man/appender_console.Rd b/man/appender_console.Rd index eca4d83a..68eb2871 100644 --- a/man/appender_console.Rd +++ b/man/appender_console.Rd @@ -20,6 +20,7 @@ Other log_appenders: \code{\link{appender_async}()}, \code{\link{appender_file}()}, \code{\link{appender_kinesis}()}, +\code{\link{appender_ntfy}()}, \code{\link{appender_pushbullet}()}, \code{\link{appender_slack}()}, \code{\link{appender_stdout}()}, diff --git a/man/appender_file.Rd b/man/appender_file.Rd index 554815e3..e4daa283 100644 --- a/man/appender_file.Rd +++ b/man/appender_file.Rd @@ -78,6 +78,7 @@ Other log_appenders: \code{\link{appender_async}()}, \code{\link{appender_console}()}, \code{\link{appender_kinesis}()}, +\code{\link{appender_ntfy}()}, \code{\link{appender_pushbullet}()}, \code{\link{appender_slack}()}, \code{\link{appender_stdout}()}, diff --git a/man/appender_kinesis.Rd b/man/appender_kinesis.Rd index 6215efb6..253e6511 100644 --- a/man/appender_kinesis.Rd +++ b/man/appender_kinesis.Rd @@ -24,6 +24,7 @@ Other log_appenders: \code{\link{appender_async}()}, \code{\link{appender_console}()}, \code{\link{appender_file}()}, +\code{\link{appender_ntfy}()}, \code{\link{appender_pushbullet}()}, \code{\link{appender_slack}()}, \code{\link{appender_stdout}()}, diff --git a/man/appender_ntfy.Rd b/man/appender_ntfy.Rd new file mode 100644 index 00000000..5d0cbba8 --- /dev/null +++ b/man/appender_ntfy.Rd @@ -0,0 +1,36 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/appenders.R +\name{appender_ntfy} +\alias{appender_ntfy} +\title{Send log messages to ntfy} +\usage{ +appender_ntfy(title = "{logger}", tags = c("memo"), ...) +} +\arguments{ +\item{...}{parameters passed to \link[ntfy:ntfy_send]{ntfy::ntfy_send}, such as \code{title} +or \code{tags}.} +} +\description{ +Send log messages to ntfy +} +\details{ +Configure server and topic via environment variables. See +\code{\link[ntfy:ntfy_topic]{ntfy::ntfy_topic()}} for details. +} +\note{ +This functionality depends on the \pkg{ntfy} package. +} +\seealso{ +Other log_appenders: +\code{\link{appender_async}()}, +\code{\link{appender_console}()}, +\code{\link{appender_file}()}, +\code{\link{appender_kinesis}()}, +\code{\link{appender_pushbullet}()}, +\code{\link{appender_slack}()}, +\code{\link{appender_stdout}()}, +\code{\link{appender_syslog}()}, +\code{\link{appender_tee}()}, +\code{\link{appender_telegram}()} +} +\concept{log_appenders} diff --git a/man/appender_pushbullet.Rd b/man/appender_pushbullet.Rd index cd201128..2888f5e8 100644 --- a/man/appender_pushbullet.Rd +++ b/man/appender_pushbullet.Rd @@ -24,6 +24,7 @@ Other log_appenders: \code{\link{appender_console}()}, \code{\link{appender_file}()}, \code{\link{appender_kinesis}()}, +\code{\link{appender_ntfy}()}, \code{\link{appender_slack}()}, \code{\link{appender_stdout}()}, \code{\link{appender_syslog}()}, diff --git a/man/appender_slack.Rd b/man/appender_slack.Rd index 81f283b4..3b9f4634 100644 --- a/man/appender_slack.Rd +++ b/man/appender_slack.Rd @@ -39,6 +39,7 @@ Other log_appenders: \code{\link{appender_console}()}, \code{\link{appender_file}()}, \code{\link{appender_kinesis}()}, +\code{\link{appender_ntfy}()}, \code{\link{appender_pushbullet}()}, \code{\link{appender_stdout}()}, \code{\link{appender_syslog}()}, diff --git a/man/appender_stdout.Rd b/man/appender_stdout.Rd index 6f4dcdd4..59c3bd21 100644 --- a/man/appender_stdout.Rd +++ b/man/appender_stdout.Rd @@ -18,6 +18,7 @@ Other log_appenders: \code{\link{appender_console}()}, \code{\link{appender_file}()}, \code{\link{appender_kinesis}()}, +\code{\link{appender_ntfy}()}, \code{\link{appender_pushbullet}()}, \code{\link{appender_slack}()}, \code{\link{appender_syslog}()}, diff --git a/man/appender_syslog.Rd b/man/appender_syslog.Rd index d8f697be..080fac84 100644 --- a/man/appender_syslog.Rd +++ b/man/appender_syslog.Rd @@ -9,7 +9,7 @@ appender_syslog(identifier, ...) \arguments{ \item{identifier}{A string identifying the process.} -\item{...}{Further arguments passed on to \code{\link[rsyslog:syslog]{rsyslog::open_syslog()}}.} +\item{...}{Further arguments passed on to \code{\link[rsyslog:open_syslog]{rsyslog::open_syslog()}}.} } \value{ function taking \code{lines} argument @@ -34,6 +34,7 @@ Other log_appenders: \code{\link{appender_console}()}, \code{\link{appender_file}()}, \code{\link{appender_kinesis}()}, +\code{\link{appender_ntfy}()}, \code{\link{appender_pushbullet}()}, \code{\link{appender_slack}()}, \code{\link{appender_stdout}()}, diff --git a/man/appender_tee.Rd b/man/appender_tee.Rd index f074ae52..e29d3ec1 100644 --- a/man/appender_tee.Rd +++ b/man/appender_tee.Rd @@ -41,6 +41,7 @@ Other log_appenders: \code{\link{appender_console}()}, \code{\link{appender_file}()}, \code{\link{appender_kinesis}()}, +\code{\link{appender_ntfy}()}, \code{\link{appender_pushbullet}()}, \code{\link{appender_slack}()}, \code{\link{appender_stdout}()}, diff --git a/man/appender_telegram.Rd b/man/appender_telegram.Rd index 789ac0b5..61e8242e 100644 --- a/man/appender_telegram.Rd +++ b/man/appender_telegram.Rd @@ -34,6 +34,7 @@ Other log_appenders: \code{\link{appender_console}()}, \code{\link{appender_file}()}, \code{\link{appender_kinesis}()}, +\code{\link{appender_ntfy}()}, \code{\link{appender_pushbullet}()}, \code{\link{appender_slack}()}, \code{\link{appender_stdout}()}, diff --git a/man/colorize_by_log_level.Rd b/man/colorize_by_log_level.Rd index 54322ac0..fc0f6081 100644 --- a/man/colorize_by_log_level.Rd +++ b/man/colorize_by_log_level.Rd @@ -23,7 +23,7 @@ or grayscale color scheme. The greyscale theme assumes a dark background on the terminal. } \examples{ -\dontshow{if (requireNamespace("crayon")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (requireNamespace("crayon")) withAutoprint(\{ # examplesIf} cat(colorize_by_log_level("foobar", FATAL), "\n") cat(colorize_by_log_level("foobar", ERROR), "\n") cat(colorize_by_log_level("foobar", WARN), "\n") diff --git a/man/layout_glue_colors.Rd b/man/layout_glue_colors.Rd index f26e1026..4ae3bf44 100644 --- a/man/layout_glue_colors.Rd +++ b/man/layout_glue_colors.Rd @@ -52,7 +52,7 @@ with \code{\link[=colorize_by_log_level]{colorize_by_log_level()}} and the messa This functionality depends on the \pkg{crayon} package. } \examples{ -\dontshow{if (requireNamespace("crayon")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (requireNamespace("crayon")) withAutoprint(\{ # examplesIf} log_layout(layout_glue_colors) log_threshold(TRACE) log_info("Starting the script...") diff --git a/man/logger-package.Rd b/man/logger-package.Rd index e2054b7b..79ea0a29 100644 --- a/man/logger-package.Rd +++ b/man/logger-package.Rd @@ -27,6 +27,7 @@ Authors: Other contributors: \itemize{ + \item Jonathan Carroll \email{rpkg@jcarroll.com.au} (\href{https://orcid.org/0000-0002-1404-5264}{ORCID}) [contributor] \item Spare Cores [funder] \item System1 [funder] } From 51e04bfd7e01d9c2d4c056c8e914032bc9c0e0bd Mon Sep 17 00:00:00 2001 From: Jonathan Carroll Date: Thu, 30 Oct 2025 08:51:42 +1030 Subject: [PATCH 2/5] document title and tags --- R/appenders.R | 2 ++ man/appender_ntfy.Rd | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/R/appenders.R b/R/appenders.R index 1ab4c9b0..168f62de 100644 --- a/R/appenders.R +++ b/R/appenders.R @@ -233,6 +233,8 @@ appender_pushbullet <- function(...) { #' Send log messages to ntfy +#' @param title notification title +#' @param tags emoji (or general tag) for notification. See [ntfy::emoji] #' @param ... parameters passed to [ntfy::ntfy_send], such as `title` #' or `tags`. #' diff --git a/man/appender_ntfy.Rd b/man/appender_ntfy.Rd index 5d0cbba8..d8dbe19e 100644 --- a/man/appender_ntfy.Rd +++ b/man/appender_ntfy.Rd @@ -7,6 +7,10 @@ appender_ntfy(title = "{logger}", tags = c("memo"), ...) } \arguments{ +\item{title}{notification title} + +\item{tags}{emoji (or general tag) for notification. See \link[ntfy:emoji]{ntfy::emoji}} + \item{...}{parameters passed to \link[ntfy:ntfy_send]{ntfy::ntfy_send}, such as \code{title} or \code{tags}.} } From 70ade15f0c9b81466b7c4d0378d51f677e453bf1 Mon Sep 17 00:00:00 2001 From: Jonathan Carroll Date: Thu, 30 Oct 2025 08:52:01 +1030 Subject: [PATCH 3/5] add NEWS entry for ntfy --- NEWS.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/NEWS.md b/NEWS.md index 107c94a2..36194a1c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,9 @@ # logger 0.4.1.9000 (development version) +New features and quality of life improvements: + +* Added `appender_ntfy()` to use {ntfy} as an appender (#240, @jonocarroll) + # logger 0.4.1 (2025-09-08) New features and quality of life improvements: From ff09af4d4fe8a567074e7c842ab227a9bf25a89b Mon Sep 17 00:00:00 2001 From: Jonathan Carroll Date: Thu, 30 Oct 2025 08:57:02 +1030 Subject: [PATCH 4/5] refined documentation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Gergely Daróczi --- R/appenders.R | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/R/appenders.R b/R/appenders.R index 168f62de..4662a136 100644 --- a/R/appenders.R +++ b/R/appenders.R @@ -235,8 +235,7 @@ appender_pushbullet <- function(...) { #' Send log messages to ntfy #' @param title notification title #' @param tags emoji (or general tag) for notification. See [ntfy::emoji] -#' @param ... parameters passed to [ntfy::ntfy_send], such as `title` -#' or `tags`. +#' @param ... extra parameters passed to [ntfy::ntfy_send] #' #' @details Configure server and topic via environment variables. See #' [ntfy::ntfy_topic()] for details. From 24c7c7f72080d5132bec0a795c5624de5b3cc311 Mon Sep 17 00:00:00 2001 From: Jonathan Carroll Date: Thu, 30 Oct 2025 09:06:52 +1030 Subject: [PATCH 5/5] satisfy linter --- R/appenders.R | 13 ++++++------- man/appender_ntfy.Rd | 6 +++--- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/R/appenders.R b/R/appenders.R index 4662a136..3e5d8a69 100644 --- a/R/appenders.R +++ b/R/appenders.R @@ -235,22 +235,21 @@ appender_pushbullet <- function(...) { #' Send log messages to ntfy #' @param title notification title #' @param tags emoji (or general tag) for notification. See [ntfy::emoji] -#' @param ... extra parameters passed to [ntfy::ntfy_send] -#' -#' @details Configure server and topic via environment variables. See -#' [ntfy::ntfy_topic()] for details. -#' +#' @param ... extra parameters passed to [ntfy::ntfy_send] such as +#' `priority`, `topic`, etc. +#' @details Configure server and topic via environment variables. See +#' [ntfy::ntfy_topic()] for details #' @export #' @note This functionality depends on the \pkg{ntfy} package. #' @family log_appenders #' @export -appender_ntfy <- function(title = "{logger}", +appender_ntfy <- function(title = "{logger}", tags = c("memo"), ...) { fail_on_missing_package("ntfy") force(title) force(tags) - + structure( function(lines) { ntfy::ntfy_send(title = title, tags = tags, message = paste(lines, sep = "\n"), ...) diff --git a/man/appender_ntfy.Rd b/man/appender_ntfy.Rd index d8dbe19e..0aa49d88 100644 --- a/man/appender_ntfy.Rd +++ b/man/appender_ntfy.Rd @@ -11,15 +11,15 @@ appender_ntfy(title = "{logger}", tags = c("memo"), ...) \item{tags}{emoji (or general tag) for notification. See \link[ntfy:emoji]{ntfy::emoji}} -\item{...}{parameters passed to \link[ntfy:ntfy_send]{ntfy::ntfy_send}, such as \code{title} -or \code{tags}.} +\item{...}{extra parameters passed to \link[ntfy:ntfy_send]{ntfy::ntfy_send} such as +\code{priority}, \code{topic}, etc.} } \description{ Send log messages to ntfy } \details{ Configure server and topic via environment variables. See -\code{\link[ntfy:ntfy_topic]{ntfy::ntfy_topic()}} for details. +\code{\link[ntfy:ntfy_topic]{ntfy::ntfy_topic()}} for details } \note{ This functionality depends on the \pkg{ntfy} package.