{"id":17718530,"url":"https://github.com/r-lib/log4r","last_synced_at":"2025-12-12T01:02:36.817Z","repository":{"id":1032249,"uuid":"860567","full_name":"r-lib/log4r","owner":"r-lib","description":"A fast \u0026 lightweight approach to logging in R based on the widely-emulated Apache Log4j project.","archived":false,"fork":false,"pushed_at":"2024-10-18T17:08:28.000Z","size":1510,"stargazers_count":95,"open_issues_count":11,"forks_count":22,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-03-31T15:25:36.787Z","etag":null,"topics":["logging","r"],"latest_commit_sha":null,"homepage":"https://log4r.r-lib.org","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/r-lib.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS.md","contributing":null,"funding":null,"license":null,"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":"2010-08-25T01:56:42.000Z","updated_at":"2025-03-05T00:54:05.000Z","dependencies_parsed_at":"2024-08-13T07:14:17.153Z","dependency_job_id":"ad5da7d5-cc14-4cb4-bb17-39a7d4e74c74","html_url":"https://github.com/r-lib/log4r","commit_stats":{"total_commits":161,"total_committers":6,"mean_commits":"26.833333333333332","dds":0.5465838509316769,"last_synced_commit":"b9f4881cd5f21540ffe5b9dae33eb5bea884f680"},"previous_names":["johnmyleswhite/log4r"],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r-lib%2Flog4r","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r-lib%2Flog4r/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r-lib%2Flog4r/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r-lib%2Flog4r/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/r-lib","download_url":"https://codeload.github.com/r-lib/log4r/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247393569,"owners_count":20931812,"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":["logging","r"],"created_at":"2024-10-25T14:53:10.131Z","updated_at":"2025-12-12T01:02:30.752Z","avatar_url":"https://github.com/r-lib.png","language":"R","readme":"---\noutput: github_document\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file. --\u003e\n\n```{r setup, include = FALSE, warning = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\",\n  out.width = \"100%\"\n)\n\nlibrary(log4r)\n```\n\n# log4r\n\n\u003c!-- badges: start --\u003e\n[![CRAN status](https://www.r-pkg.org/badges/version/log4r)](https://cran.r-project.org/package=log4r)\n[![R-CMD-check](https://github.com/johnmyleswhite/log4r/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/johnmyleswhite/log4r/actions/workflows/R-CMD-check.yaml)\n\u003c!-- badges: end --\u003e\n\n**log4r** is a fast, lightweight, object-oriented approach to logging in R based\non the widely-emulated [Apache Log4j](https://logging.apache.org/log4j/) project.\n\n**log4r** differs from other R logging packages in its focus on performance and\nsimplicity. As such, it has fewer features -- although it is still quite\nextensible, as seen below -- but is much faster. See\n`vignette(\"performance\", package = \"log4r\")` for details.\n\nUnlike other R logging packages, **log4r** also has first-class support for\nstructured logging. See `vignette(\"structured-logging\", package = \"log4r\")` for\ndetails.\n\n## Installation\n\nThe package is available from CRAN:\n\n```r\ninstall.packages(\"log4r\")\n```\n\nIf you want to use the development version, you can install the package from\nGitHub as follows:\n\n```r\n# install.packages(\"remotes\")\nremotes::install_github(\"johnmyleswhite/log4r\")\n```\n\n## Usage\n\nLogging is configured by passing around `logger` objects created by `logger()`.\nBy default, this will log to the console and suppress messages below the\n`\"INFO\"` level:\n\n```{r basic-example}\nlogger \u003c- logger()\n\nlog_info(logger, \"Located nearest gas station.\")\nlog_warn(logger, \"Ez-Gas sensor network is not available.\")\nlog_debug(logger, \"Debug messages are suppressed by default.\")\n```\n\nLogging destinations are controlled by **Appenders**, a few of which are\nprovided by the package. For instance, if we want to debug-level messages to a\nfile:\n\n```{r file-example, echo = 1:7}\nlog_file \u003c- tempfile()\nlogger \u003c- logger(\"DEBUG\", appenders = file_appender(log_file))\n\nlog_info(logger, \"Messages are now written to the file instead.\")\nlog_debug(logger, \"Debug messages are now visible.\")\n\nreadLines(log_file)\nunlink(log_file)\n```\n\nThe `appenders` parameter takes a list, so you can log to multiple destinations\ntransparently.\n\nFor local development or simple batch R scripts run manually, writing log\nmessages to a file for later inspection is convenient. However, for deployed R\napplications or automated scripts it is more likely you will need to send logs\nto a central location; see\n`vignette(\"logging-beyond-local-files\", package = \"log4r\")`.\n\nTo control the format of the messages you can change the **Layout** used by\neach appender. Layouts are functions; you can write your own quite easily:\n\n```{r layout-example}\nmy_layout \u003c- function(level, ...) {\n  paste0(format(Sys.time()), \" [\", level, \"] \", ..., collapse = \"\")\n}\n\nlogger \u003c- logger(appenders = console_appender(my_layout))\nlog_info(logger, \"Messages should now look a little different.\")\n```\n\nWith an appropriate layout, you can also use *structured logging*, enriching log\nmessages with contextual fields:\n\n```{r sl-example}\nlogger \u003c- logger(appenders = console_appender(logfmt_log_layout()))\nlog_info(\n  logger, message = \"processed entries\", file = \"catpics_01.csv\",\n  entries = 4124, elapsed = 2.311\n)\n```\n\n## Older APIs\n\nThe 0.2 API is still supported, but will issue deprecation warnings when used:\n\n```{r old-api, echo = 1:12}\nlogger \u003c- create.logger()\n\nlogfile(logger) \u003c- log_file\nlevel(logger) \u003c- \"INFO\"\n\ndebug(logger, 'A Debugging Message')\ninfo(logger, 'An Info Message')\nwarn(logger, 'A Warning Message')\nerror(logger, 'An Error Message')\nfatal(logger, 'A Fatal Error Message')\n\nreadLines(log_file)\nunlink(log_file)\n```\n\n## License\n\nThe package is available under the terms of the Artistic License 2.0.\n","funding_links":[],"categories":["R"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fr-lib%2Flog4r","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fr-lib%2Flog4r","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fr-lib%2Flog4r/lists"}