From 4cea7d63f1b0c717c27b54c7f51e26cce365fca2 Mon Sep 17 00:00:00 2001 From: Dereck Mezquita <44912288+dereckmezquita@users.noreply.github.com> Date: Thu, 16 Jan 2025 16:38:05 -0500 Subject: [PATCH] DT-20: active get log level (#5) * DT-20: only rebuild docs on merge to master. * DT-20: active field for getting log level. --- .github/workflows/pkgdown.yml | 5 ++++- DESCRIPTION | 2 +- NEWS.md | 20 ++++++++++++++++++++ R/Stenographer.R | 16 ++++++++++++++++ man/Stenographer.Rd | 14 ++++++++++++++ man/valid_log_level.Rd | 17 +++++++++++++++++ tests/testthat/test-Stenographer.R | 30 ++++++++++++++---------------- 7 files changed, 86 insertions(+), 18 deletions(-) create mode 100644 man/valid_log_level.Rd diff --git a/.github/workflows/pkgdown.yml b/.github/workflows/pkgdown.yml index 5416ba2..8437afe 100644 --- a/.github/workflows/pkgdown.yml +++ b/.github/workflows/pkgdown.yml @@ -1,5 +1,8 @@ name: pkgdown -on: push +on: + push: + branches: + - master permissions: contents: write jobs: diff --git a/DESCRIPTION b/DESCRIPTION index 75a744c..0651489 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: stenographer Type: Package Title: Flexible and Customisable Logging System -Version: 1.0.0 +Version: 1.0.1 URL: https://github.com/dereckmezquita/stenographer BugReports: https://github.com/dereckmezquita/stenographer/issues Authors@R: diff --git a/NEWS.md b/NEWS.md index 19d16c5..6b21df1 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,23 @@ +# stenographer [v1.1.0](https://github.com/dereckmezquita/stenographer/milestone/2) + +## BREAKING CHANGES + +- **N/A** + +## NEW FEATURES + +1. **Access set LogLevel:** Use `Stenographer$get_level` to read the current logging level; active field. + +## IMPROVEMENTS + +1. **Stenographer$set_level method checks value:** The `set_level` method now validates the input value to ensure it is a valid logging level. + +## DOCUMENTATION + +## DEVELOPMENT + +## NOTES + # stenographer [v1.0.0](https://github.com/dereckmezquita/stenographer/milestone/1) (12 January 2025) ## BREAKING CHANGES diff --git a/R/Stenographer.R b/R/Stenographer.R index 53cdaf9..705859c 100644 --- a/R/Stenographer.R +++ b/R/Stenographer.R @@ -28,6 +28,13 @@ LogLevel <- list( INFO = 2L ) +#' @title Check if an object is a valid log level +#' @param x Object to check +#' @return Logical +valid_log_level <- function(x) { + return(is.integer(x) && (x %in% c(-1L, 0L, 1L, 2L))) +} + #' @title R6 Class for Advanced Logging Functionality #' #' @description @@ -41,6 +48,7 @@ LogLevel <- list( #' * Contextual data attachment #' * Coloured console output #' +#' @importFrom rlang abort #' @importFrom R6 R6Class #' @importFrom fs path_dir dir_exists dir_create file_exists file_create #' @importFrom DBI dbExistsTable dbExecute dbWriteTable @@ -79,6 +87,11 @@ LogLevel <- list( #' @export Stenographer <- R6Class( "Stenographer", + active = list( + #' @field Get log level (read-only) + get_level = function() return(private$level) + ), + public = list( #' @description #' Create a new Stenographer instance @@ -121,6 +134,9 @@ Stenographer <- R6Class( #' Update the minimum logging level #' @param level New log level (see `LogLevel`) set_level = function(level) { + if (!valid_log_level(level)) { + abort("Invalid log level") + } private$level <- level }, diff --git a/man/Stenographer.Rd b/man/Stenographer.Rd index daea05c..62f2210 100644 --- a/man/Stenographer.Rd +++ b/man/Stenographer.Rd @@ -43,6 +43,20 @@ custom_steno$set_level(LogLevel$INFO) custom_steno$update_context(list(user = "John")) custom_steno$info("Now this will be logged with a custom prefix and context") +} +\section{Public fields}{ +\if{html}{\out{