{"id":14067546,"url":"https://github.com/sellorm/rlog","last_synced_at":"2025-06-15T12:39:22.362Z","repository":{"id":49460292,"uuid":"340914103","full_name":"sellorm/rlog","owner":"sellorm","description":"opinionated, lightweight logging for R","archived":false,"fork":false,"pushed_at":"2021-09-30T17:45:08.000Z","size":47,"stargazers_count":19,"open_issues_count":2,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-10T03:07:59.799Z","etag":null,"topics":["logging","r","rstats","rstats-package"],"latest_commit_sha":null,"homepage":"https://rlog.sellorm.com","language":"R","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/sellorm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-02-21T13:57:33.000Z","updated_at":"2025-01-02T10:43:22.000Z","dependencies_parsed_at":"2022-08-31T05:51:36.261Z","dependency_job_id":null,"html_url":"https://github.com/sellorm/rlog","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/sellorm/rlog","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sellorm%2Frlog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sellorm%2Frlog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sellorm%2Frlog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sellorm%2Frlog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sellorm","download_url":"https://codeload.github.com/sellorm/rlog/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sellorm%2Frlog/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259977667,"owners_count":22941115,"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","rstats","rstats-package"],"created_at":"2024-08-13T07:05:39.347Z","updated_at":"2025-06-15T12:39:22.337Z","avatar_url":"https://github.com/sellorm.png","language":"R","funding_links":[],"categories":["R"],"sub_categories":[],"readme":"# rlog\n\n\u003c!-- badges: start --\u003e\n[![R-CMD-check](https://github.com/sellorm/rlog/workflows/R-CMD-check/badge.svg)](https://github.com/sellorm/rlog/actions)\n\u003c!-- badges: end --\u003e\n\nrlog is an opinionated, lightweight logging package for R.\n\nIt relies on long standing Unix traditions, to write simple log messages in a flexible way.\n\nLog message output looks like this:\n\n```\n2021-02-21 17:19:06 [INFO] This is my log message\n```\n\n## Installation\n\nInstall rlog from GitHub with the following:\n\n``` r\ndevtools::install_github(\"sellorm/rlog\")\n```\n\n## Does R _really_ need another logging package?\n\nWe think so, yes!\n\nThere are already loads of logging packages for R. Many are no longer maintained and of the remaining selection some are overly complex, making them less approachable for beginners.\n\nSince logging should be an essential part of any production application or pipeline I think it's important that as many people as possible are introduced to good logging practice.\n\nIf rlog doesn't have enough features for you, I'd recommend the excellent \"[logger](https://cran.r-project.org/package=logger)\" instead.\n\n## rlog philosophy\n\nThe rlog philosophy is the [Unix philosophy](https://en.wikipedia.org/wiki/Unix_philosophy) and as such, we expect applications using rlog to be able to integrate with other enterprise software quickly and efficiently.\n\nrlog is simple by design and it relies on existing Unix/Linux norms to get the job done.\n\n* Log message format is intentionally not configurable\n* the log level can only be controlled by an environment variable\n* log messages are written to standard output and standard error\n\n## Usage\n\nThe best way to use rlog is to call the functions directly from within your applications.\n\nThere is one function per log message level:\n\n``` r\nrlog::log_fatal(\"my fatal message\")\nrlog::log_error(\"my error message\")\nrlog::log_warn(\"my warn message\")\nrlog::log_info(\"my info message\")\nrlog::log_debug(\"my debug message\")\nrlog::log_trace(\"my trace message\")\n```\n\nIf you run this code as-is without setting a custom `LOG_LEVEL` with the environment variable, you'll get output like this:\n\n```\n2021-02-21 17:19:06 [FATAL] fatal\n2021-02-21 17:19:06 [ERROR] error\n2021-02-21 17:19:06 [WARN] warn\n2021-02-21 17:19:06 [INFO] info\n```\n\nThe \"DEBUG\" and \"TRACE\" message won't be printed, since the default `LOG_LEVEL` is \"INFO\" and those message have lower priority.\n\nPlay around with setting the `LOG_LEVEL` directly in R and seeing what messages are emitted:\n\n``` r\nSys.setenv(\"LOG_LEVEL\" = \"ERROR\")\nrlog::log_fatal(\"my fatal message\")\nrlog::log_error(\"my error message\")\nrlog::log_warn(\"my warn message\")\nrlog::log_info(\"my info message\")\nrlog::log_debug(\"my debug message\")\nrlog::log_trace(\"my trace message\")\n```\n\nGives us this output:\n\n```\n2021-02-21 17:19:06 [FATAL] fatal\n2021-02-21 17:19:06 [ERROR] error\n```\n\nRemember though, the best way to set the environment variable is outside of the app. That way it's easier to change at run-time.\n\nSo in your terminal you can do something like this before you run your script:\n\n``` sh\n$ export LOG_LEVEL=TRACE\n$ ./my_script.R\n```\n\nOr you can even call your script with the appropriate value at run-time:\n\n``` sh\n$ LOG_LEVEL=ERROR ./my_script.R\n```\n\nIf you're using RStudio Connect users can set an environment variable called `LOG_LEVEL` in the \"Vars\" tab of their apps control panel.\n\n## Setting the log level\n\nrlog relies on an environment variable called `LOG_LEVEL` to control which log messages are emitted.\n\nIf it's not set, it will default to \"INFO\".\n\nThe available levels -- in decreasing order of severity -- are as follows:\n\n* fatal\n* error\n* warn\n* info\n* debug\n* trace\n\nWhen the `LOG_LEVEL` environment variable is set to \"INFO\", only messages at that level and above will be emitted.\n\nAnother example:\n\n* fatal\n* error\n* warn \n* info\n* debug \u003c= If we set the log level here only messages of debug and above will be emitted.\n* trace\n\nThis is a really powerful way of only including the messages you want to see in the log files at any given time. For example, you may choose to set the `LOG_LEVEL` to \"TRACE\" while developing your application or if it runs into a problem in production, but you might choose to run the application with a `LOG_LEVEL` of \"ERROR\" under normal circumstances.\n\n\n## I want to write to a log file, not the console\n\nrlog outputs it log messages into the console in the same way that most Unix/Linux tools do. Ordinary messages go to \"standard output\" ([stdout](https://en.wikipedia.org/wiki/Standard_streams#Standard_output_(stdout))) and errors go to \"standard error\" ([stderr](https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr))).\n\nThis means they can be captured in the standard Unix/Linux way:\n\n```\n./my_script.R \u003e /path/to/file.log 2\u003e\u00261\n```\n\nThis command redirects stderr to stdout and drops it all into the `/path/to/file.log` file.\n\nYou can also keep the \"normal\" and error outputs separate:\n\n```\n./my_script.R \u003e /path/to/file.log 2\u003e /path/to/errors.log\n```\n\nMany enterprise software products, such as RStudio Connect will capture this output automatically and save it for you.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsellorm%2Frlog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsellorm%2Frlog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsellorm%2Frlog/lists"}