diff --git a/.Rbuildignore b/.Rbuildignore new file mode 100644 index 0000000..c503c4f --- /dev/null +++ b/.Rbuildignore @@ -0,0 +1 @@ +^\.github$ diff --git a/.github/.gitignore b/.github/.gitignore new file mode 100644 index 0000000..2d19fc7 --- /dev/null +++ b/.github/.gitignore @@ -0,0 +1 @@ +*.html diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml new file mode 100644 index 0000000..1c207c7 --- /dev/null +++ b/.github/workflows/R-CMD-check.yaml @@ -0,0 +1,49 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. +# +# See https://github.com/r-lib/actions/tree/master/examples#readme for +# additional example workflows available for the R community. + +name: R-CMD-check +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] +permissions: + contents: read +jobs: + build: + runs-on: ${{ matrix.os }} + strategy: + matrix: + include: + - os: ubuntu-latest + r-version: oldrel + - os: ubuntu-latest + r-version: release + - os: ubuntu-latest + r-version: devel + - os: macos-latest + r-version: release + - os: windows-latest + r-version: release + steps: + - uses: actions/checkout@v4 + - name: Install system dependencies + if: runner.os == 'Linux' + run: sudo apt-get install -y libcurl4-openssl-dev + - uses: r-lib/actions/setup-r@v2 + with: + r-version: ${{ matrix.r-version }} + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + working-directory: pkg + extra-packages: any::rcmdcheck + - uses: r-lib/actions/check-r-package@v2 + with: + working-directory: pkg + args: 'c("--as-cran", "--no-manual")' + error-on: '"error"' diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml new file mode 100644 index 0000000..cb36d35 --- /dev/null +++ b/.github/workflows/test-coverage.yaml @@ -0,0 +1,52 @@ +name: test-coverage +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +permissions: read-all + +jobs: + test-coverage: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v6 + + - name: Install system dependencies + run: sudo apt-get install -y libcurl4-openssl-dev + + - uses: r-lib/actions/setup-r@v2 + with: + r-version: release + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + working-directory: pkg + extra-packages: any::covr, any::xml2 + needs: coverage + + - name: Generate coverage report (Cobertura) + run: | + cov <- covr::package_coverage(path = "pkg", quiet = FALSE) + print(cov) + covr::to_cobertura(cov, filename = "cobertura.xml") + shell: Rscript {0} + + - name: Upload coverage to Coveralls + uses: coverallsapp/github-action@v2 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + file: cobertura.xml + format: cobertura + base-path: pkg + env: + COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }} + + - name: Show testthat output + if: always() + run: | + ## -------------------------------------------------------------------- + find "${{ runner.temp }}/package" -name "testthat.Rout*" -exec cat "{}" \; || true + shell: bash diff --git a/.gitignore b/.gitignore index f7267d5..83255b1 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,6 @@ pkg.Rcheck .Rproj.user report.xml +/logging.Rcheck/ +/logging_*.tar.gz +/pkg/tests/testthat/_problems/ diff --git a/README.md b/README.md index acd858e..3021808 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -| Travis | Total downloads | Downloads | CRAN version | -| :----------------: | :----------------: | :----------------: | :----------------: | -| [![Travis build status](https://travis-ci.com/WLOGSolutions/r-logging.svg?branch=master)](https://travis-ci.com/WLOGSolutions/r-logging) | [![CRAN total downloads](http://cranlogs.r-pkg.org/badges/grand-total/logging)](http://cranlogs.r-pkg.org/badges/grand-total/logging)| [![CRAN downloads](https://cranlogs.r-pkg.org/badges/logging)](https://cranlogs.r-pkg.org/badges/logging)| [![CRAN version](http://www.r-pkg.org/badges/version/logging)](http://www.r-pkg.org/badges/version/logging)| +| R-CMD-check | Total downloads | Downloads | CRAN version | Coverage | +| :----------------: | :----------------: | :----------------: | :----------------: | :------------: | +| [![R-CMD-check](https://github.com/mfrasca/r-logging/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/mfrasca/r-logging/actions/workflows/R-CMD-check.yaml) | [![CRAN total downloads](http://cranlogs.r-pkg.org/badges/grand-total/logging)](http://cranlogs.r-pkg.org/badges/grand-total/logging)| [![CRAN downloads](https://cranlogs.r-pkg.org/badges/logging)](https://cranlogs.r-pkg.org/badges/logging)| [![CRAN version](http://www.r-pkg.org/badges/version/logging)](http://www.r-pkg.org/badges/version/logging)|[![Coverage Status](https://coveralls.io/repos/github/mfrasca/r-logging/badge.svg?branch=master)](https://coveralls.io/github/mfrasca/r-logging?branch=master)| r-logging ========= @@ -28,7 +28,20 @@ on [r-forge] (http://r-forge.r-project.org/). installation ============ -Simply call +For the last released package: ``` -devtools::install_github("WLOGSolutions/r-logging/pkg") +install.packages("logging") ``` + +if you want the latest from github, you could do: +``` +devtools::install_github("mfrasca/r-logging/pkg") +``` + +if you have cloned the github repository while your working directory +was `BASE`, you may want to use your local, possibly altered copy: +``` +devtools::install_local("BASE/r-logging/pkg") +``` + + diff --git a/pkg/DESCRIPTION b/pkg/DESCRIPTION index 0667e0c..63ba21f 100644 --- a/pkg/DESCRIPTION +++ b/pkg/DESCRIPTION @@ -1,14 +1,14 @@ Package: logging -Version: 0.10-108 +Version: 1.0-0 Title: R Logging Package Authors@R: c( - person("Mario", "Frasca", email = "mariotomo@gmail.com", role = c("aut")), - person("Walerian", "Sokolowski", email = "r-logging@wlogsolutions.com", role = c("cre")) + person("Mario", "Frasca", email = "mariotomo@gmail.com", role = c("aut", "cre")), + person("Walerian", "Sokolowski", email = "r-logging@wlogsolutions.com", role = c("aut")) ) Description: Pure R implementation of the ubiquitous log4j package. It offers hierarchic loggers, multiple handlers per logger, level based filtering, space handling in messages and custom formatting. -URL: https://github.com/WLOGSolutions/r-logging +URL: https://github.com/mfrasca/r-logging BugReports: https://github.com/WLOGSolutions/r-logging/issues License: GPL-3 Encoding: UTF-8 diff --git a/pkg/NEWS.md b/pkg/NEWS.md index 06f08df..fce1f2b 100644 --- a/pkg/NEWS.md +++ b/pkg/NEWS.md @@ -1,3 +1,14 @@ +# logging 1.0-0 (2026-05-25) + - Version 1.0 marks the package as stable; versioning henceforth follows + major.minor-patch where patch is for administrative/documentation fixes + and minor for bug fixes and new features + - Added GitHub Actions workflows for continuous integration. + - Published test coverage on coveralls.io + +# logging 0.10-111 (2026-05-21) + - Resumed maintainership (original author Mario Frasca) + - Fixed bug: non-character messages (e.g. Date) now log correctly + # logging 0.10-108 (2019-07-14) * issue #4: logged do not raise exception if formatting message contains %F markers and not formatting arguments passed @@ -27,4 +38,4 @@ logReset. # logging 0.8-104 (2018-11-29) - * Maintener changed to Walerian Sokolowski + * Maintainer changed to Walerian Sokolowski diff --git a/pkg/R/logger.R b/pkg/R/logger.R index 49ad5e3..29fe81c 100644 --- a/pkg/R/logger.R +++ b/pkg/R/logger.R @@ -115,7 +115,7 @@ levellog <- function(level, msg, ..., logger = "") { #' Set defaults and get the named logger. #' #' Make sure a logger with a specific name exists and return it as a -#' \var{Logger} S4 object. if not yet present, the logger will be created and +#' \var{Logger} object. If not yet present, the logger will be created and #' given the values specified in the \dots arguments. #' #' @param name The name of the logger diff --git a/pkg/R/utils.R b/pkg/R/utils.R index ba5ddb0..b4ec308 100644 --- a/pkg/R/utils.R +++ b/pkg/R/utils.R @@ -186,6 +186,6 @@ defaultMsgCompose <- function(msg, ...) { !(matched_call_names %in% c(setdiff(formal_names, "..."))) label <- lapply(matched_call[is_output_param], deparse) - msg <- sprintf("%s: %s", label, c(msg, optargs)) + msg <- sprintf("%s: %s", label, c(as.character(msg), optargs)) return(msg) } diff --git a/pkg/man/logging-package.Rd b/pkg/man/logging-package.Rd index 5cb6eee..d585fa6 100644 --- a/pkg/man/logging-package.Rd +++ b/pkg/man/logging-package.Rd @@ -46,7 +46,7 @@ The web pages for this package on r-forge are kept decently up to date and contain a usable tutorial. Check the references. } \references{ -the python logging module: \url{http://docs.python.org/library/logging.html}\cr +the python logging module: \url{https://docs.python.org/3/library/logging.html}\cr this package at github: \url{https://github.com/WLOGSolutions/r-logging/} } \keyword{package} diff --git a/pkg/tests/testthat/test.handlers.R b/pkg/tests/testthat/test.handlers.R index 66c4ac2..4475d2b 100644 --- a/pkg/tests/testthat/test.handlers.R +++ b/pkg/tests/testthat/test.handlers.R @@ -165,10 +165,13 @@ test_that("loggingToConsole", { logReset() basicConfig() - logdebug("test %d", 2) - loginfo("test %d", 2) + output <- capture.output({ + logdebug("test %d", 2) + loginfo("test %d", 2) + }) - succeed() + expect_true(any(grepl("test 2", output))) + expect_false(any(grepl("DEBUG", output))) }) test_that("loggingToFile", { @@ -211,3 +214,29 @@ test_that("loggingToFile.oo", { succeed() }) + +test_that("writeToConsole initializes color_msg as identity when color_output=FALSE", { + logReset() + basicConfig() + addHandler(writeToConsole, color_output = FALSE) + handler <- getHandler("writeToConsole") + expect_equal(handler$color_msg("test", "INFO"), "test") + expect_equal(handler$color_msg("test", "ERROR"), "test") +}) + +test_that("writeToConsole initializes color_msg with level-dependent coloring by default", { + skip_if_not_installed("crayon") + withr::with_options(list(crayon.enabled = TRUE), { + logReset() + basicConfig() + addHandler(writeToConsole) + handler <- getHandler("writeToConsole") + info_msg <- handler$color_msg("test", "INFO") + error_msg <- handler$color_msg("test", "ERROR") + expect_true(grepl("test", info_msg)) + expect_true(grepl("test", error_msg)) + expect_true(grepl("\033[", info_msg, fixed = TRUE)) + expect_true(grepl("\033[", error_msg, fixed = TRUE)) + expect_false(identical(info_msg, error_msg)) + }) +}) diff --git a/pkg/tests/testthat/test.msg-composer.R b/pkg/tests/testthat/test.msg-composer.R index a038568..bbffaf8 100644 --- a/pkg/tests/testthat/test.msg-composer.R +++ b/pkg/tests/testthat/test.msg-composer.R @@ -80,3 +80,6 @@ test_that("msgcomposer/composer_signature_validation_directly", { }) }) +test_that("loginfo handles Date objects without error", { + expect_no_error(loginfo(as.Date("2022-01-01"))) +})