{"id":14062769,"url":"https://github.com/daroczig/logger","last_synced_at":"2025-05-14T19:02:58.233Z","repository":{"id":33547786,"uuid":"157297209","full_name":"daroczig/logger","owner":"daroczig","description":"A lightweight, modern and flexible, log4j and futile.logger inspired logging utility for R","archived":false,"fork":false,"pushed_at":"2025-04-03T14:31:28.000Z","size":5379,"stargazers_count":304,"open_issues_count":22,"forks_count":46,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-12T09:17:21.612Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://daroczig.github.io/logger","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/daroczig.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-11-13T00:39:35.000Z","updated_at":"2025-04-11T03:54:46.000Z","dependencies_parsed_at":"2024-06-17T21:40:40.110Z","dependency_job_id":"2a9f622b-eaeb-43fd-96d8-cf7ad8994dea","html_url":"https://github.com/daroczig/logger","commit_stats":{"total_commits":431,"total_committers":18,"mean_commits":"23.944444444444443","dds":"0.11600928074245942","last_synced_commit":"cc637e4bab0b03d0e58eb985deb5f98ee1fe1387"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daroczig%2Flogger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daroczig%2Flogger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daroczig%2Flogger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daroczig%2Flogger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/daroczig","download_url":"https://codeload.github.com/daroczig/logger/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248543836,"owners_count":21121838,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-13T07:02:22.112Z","updated_at":"2025-04-12T09:17:30.884Z","avatar_url":"https://github.com/daroczig.png","language":"HTML","funding_links":[],"categories":["HTML"],"sub_categories":[],"readme":"---\noutput: github_document\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r, include = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\",\n  out.width = \"100%\"\n)\n```\n\n# logger \u003ca href=\"https://daroczig.github.io/logger/\"\u003e\u003cimg src=\"man/figures/logo.png\" align=\"right\" height=\"138\" alt=\"logger website\" /\u003e\u003c/a\u003e\n\n\u003c!-- badges: start --\u003e\n[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active) [![CRAN](https://www.r-pkg.org/badges/version/logger)](https://cran.r-project.org/package=logger) [![Build Status](https://github.com/daroczig/logger/workflows/R-CMD-check/badge.svg)](https://github.com/daroczig/logger/actions) [![Code Coverage](https://codecov.io/gh/daroczig/logger/branch/master/graph/badge.svg)](https://app.codecov.io/gh/daroczig/logger) [![A Mikata Project](https://mikata.dev/img/badge.svg)](https://mikata.dev)\n\u003c!-- badges: end --\u003e\n\nA lightweight, modern and flexible logging utility for R -- heavily inspired by the `futile.logger` R package and `logging` Python module.\n\n## Installation\n\n[![CRAN version](https://www.r-pkg.org/badges/version-ago/logger)](https://cran.r-project.org/package=logger)\n\n```{r}\n#| eval: false\ninstall.packages(\"logger\")\n```\n\nThe most recent, development version of `logger` can also be installed from GitHub:\n\n```{r}\n#| eval: false\n# install.packages(\"pak\")\npak::pak(\"daroczig/logger\")\n```\n\n## Quick example\n\nSetting the log level threshold to something low and logging various messages in ad-hoc and programmatic ways:\n\n```{r}\n#| include: false\nlibrary(logger)\nlog_appender(appender_stdout)\n```\n\n```{r}\nlibrary(logger)\nlog_threshold(DEBUG)\nlog_info(\"Script starting up...\")\n\npkgs \u003c- available.packages()\nlog_info(\"There are {nrow(pkgs)} R packages hosted on CRAN!\")\n\nfor (letter in letters) {\n  lpkgs \u003c- sum(grepl(letter, pkgs[, \"Package\"], ignore.case = TRUE))\n  log_level(\n    if (lpkgs \u003c 5000) TRACE else DEBUG,\n    \"{lpkgs} R packages including the {shQuote(letter)} letter\"\n  )\n}\n\nlog_warn(\"There might be many, like {1:2} or more warnings!!!\")\n```\n\nYou can even use a custom log layout to render the log records with colors, as you can see in `layout_glue_colors()`:\n\n\u003cimg src=\"man/figures/colors.png\" alt=\"colored log output\"\u003e\n\nBut you could set up any custom colors and layout, eg using custom colors only for the log levels, make it grayscale, include the calling function or R package namespace with specific colors etc. For more details, see `vignette(\"write_custom_extensions\")`.\n\n## Related work\n\nThere are many other logging packages available on CRAN:\n\n- [`futile.logger`](https://cran.r-project.org/package=futile.logger): probably the most popular `log4j` variant (and I'm a big fan)\n- [`logging`](https://cran.r-project.org/package=logging): just like Python's `logging` package\n- [`lgr`](https://cran.r-project.org/package=lgr): built on top of R6.\n- [`loggit`](https://cran.r-project.org/package=loggit): capture `message`, `warning` and `stop` function messages in a JSON file\n- [`log4r`](https://cran.r-project.org/package=log4r): `log4j`-based, object-oriented logger\n- [`rsyslog`](https://cran.r-project.org/package=rsyslog): logging to `syslog` on 'POSIX'-compatible operating systems\n- [`lumberjack`](https://cran.r-project.org/package=lumberjack): provides a special operator to log changes in data\n\nWhy use logger? I decided to write the `n+1`th extensible `log4j` logger that fits my liking --- and hopefully yours as well --- with the aim to:\n\n- Keep it close to `log4j`.\n- Respect the modern function/variable naming conventions and general R coding style.\n- By default, rely on `glue()` when it comes to formatting / rendering log messages, but keep it flexible if others prefer `sprintf()` (e.g. for performance reasons) or other functions.\n- Support vectorization (eg passing a vector to be logged on multiple lines).\n- Make it easy to extend with new features (e.g. custom layouts, message formats and output).\n- Prepare for writing to various services, streams etc\n- Provide support for namespaces, preferably automatically finding and creating a custom namespace for all R packages writing log messages, each with optionally configurable log level threshold, message and output formats.\n- Allow stacking loggers to implement logger hierarchy -- even within a namespace, so that the very same `log` call can write all the `TRACE` log messages to the console, while only pushing `ERROR`s to DataDog and eg `INFO` messages to CloudWatch.\n- Optionally colorize log message based on the log level.\n- Make logging fun!\n\nWelcome to the [Bazaar](https://en.wikipedia.org/wiki/The_Cathedral_and_the_Bazaar)! If you already use any of the above packages for logging, you might find `vignette(\"migration\")` useful.\n\n## Interested in more details?\n\n::: .pkgdown-hide\n\nCheck out the main documentation site at \u003chttps://daroczig.github.io/logger/\u003e or the vignettes on the below topics:\n\n* [Introduction to logger](https://daroczig.github.io/logger/articles/Intro.html)\n* [The Anatomy of a Log Request](https://daroczig.github.io/logger/articles/anatomy.html)\n* [Customizing the Format and the Destination of a Log Record](https://daroczig.github.io/logger/articles/customize_logger.html)\n* [Writing Custom Logger Extensions](https://daroczig.github.io/logger/articles/write_custom_extensions.html)\n* [Migration Guide from other logging packages](https://daroczig.github.io/logger/articles/migration.html)\n* [Logging from R Packages](https://daroczig.github.io/logger/articles/r_packages.html)\n* [Simple Benchmarks on Performance](https://daroczig.github.io/logger/articles/performance.html)\n\n:::\n\nIf you prefer visual content, you can watch the video recording of the \"Getting things logged\" talk at RStudio::conf(2020):\n\n[![Gergely Daroczi presenting \"Getting things logged\" on using the `logger` R package at the RStudio conference in 2020](https://img.youtube.com/vi/_rUuBbml9dU/0.jpg)](https://www.youtube.com/watch?v=_rUuBbml9dU)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaroczig%2Flogger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdaroczig%2Flogger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaroczig%2Flogger/lists"}