{"id":14067644,"url":"https://github.com/sol-eng/logging-best-practices","last_synced_at":"2026-03-11T12:05:43.749Z","repository":{"id":101029016,"uuid":"344146706","full_name":"sol-eng/logging-best-practices","owner":"sol-eng","description":"An introduction to, and best practices for, logging in R","archived":false,"fork":false,"pushed_at":"2021-03-03T14:04:41.000Z","size":4,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-12-04T08:36:09.795Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/sol-eng.png","metadata":{"files":{"readme":"README.md","changelog":null,"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}},"created_at":"2021-03-03T14:04:07.000Z","updated_at":"2023-05-07T06:12:44.000Z","dependencies_parsed_at":null,"dependency_job_id":"cb2b0baf-9f79-4b74-a04a-6c7881303372","html_url":"https://github.com/sol-eng/logging-best-practices","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/sol-eng/logging-best-practices","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sol-eng%2Flogging-best-practices","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sol-eng%2Flogging-best-practices/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sol-eng%2Flogging-best-practices/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sol-eng%2Flogging-best-practices/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sol-eng","download_url":"https://codeload.github.com/sol-eng/logging-best-practices/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sol-eng%2Flogging-best-practices/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267798625,"owners_count":24145727,"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","status":"online","status_checked_at":"2025-07-30T02:00:09.044Z","response_time":70,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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:05:42.340Z","updated_at":"2026-03-11T12:05:43.705Z","avatar_url":"https://github.com/sol-eng.png","language":"R","funding_links":[],"categories":["R"],"sub_categories":[],"readme":"\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n# Logging best practices for R\n\nThe goal of logging in any language is to provide those who oversee the\nrunning of your code with some insight into what it’s doing and when.\nThis will help them understand what actions your code is performing and\ncan help them diagnose any issues they might encounter.\n\n## Repo contents\n\n* `shiny-app` contains an interactive logging demo app\n\n## What should I log?\n\nThere’s an argument to be made that *everything* should be logged or at\nleast made optionally log-able in a production application. Since\n“production” is loaded word, we define that here as something that is\nrelied on by the business. It could be running in a multi-million dollar\ndata centre, or it could be running on an old desktop computer under\nyour desk, but if your organisation relies on that system, then it’s a\nproduction system.\n\nThe other common factor with most production systems is that the code is\ngenerally run unattended. This is in contrast to a large proportion of\ndata science work, where code is run interactively by the developer and\nthis means that ideas like logging can seem alien at first.\n\nImagine you’ve written a script in R. That script reads in some\nconfiguration data, connects to a database, extracts some data,\ntransforms the data, loads the transformed data into a database, trains\na model against the transformed data and then publishes the new model.\nIf you (the developer of this script) run it and it errors out half way\nthrough because it can’t connect to the database, you’ll be able to\nquickly determine what went wrong. This is because you’re intimately\naware of what the script does and how, and you were probably watching\nit’s progress when it broke.\n\nNow, imagine you’ve given that script to someone to run on a schedule,\nevery night at 3am and the script must have run to completion before the\nbusiness day starts. Imagine the same error happens to this person. They\ndon’t know your code, they may not even know or care what it does, all\nthey care about is that it’s 3am and the thing that’s supposed to be\nworking isn’t. Their next call will likely be to you.\n\nNext, imagine that it’s *you* that’s been given some code to run at 3am\nevery day, in a language you don’t really understand. Imagine it’s very\nimportant that this code is run before the working day starts, but it’s\nbroken and you don’t know why. That’s not a great position to be in.\n\nThis is why we log.\n\nLogging is about empathy for other people who may come into contact with\nour code as well as our future selves. Log messages are often the first\npoint of contact with your code for people working in ops or support.\nThey may not know the langauge your code is written in, but it shouldn’t\nmatter. Log messages should provide a clear indication of the intent of\nyour application and wherever possible a clear indication of any error\nstates.\n\nIt’s essential that we communicate to others the intent of our\nproduction applications so that they might be able to fix them in our\nabsence. I certainly don’t enjoy being woken up at 3am because an\napplication I wrote is having a trivial error but nobody can figure out\nwhat’s going on. Log messages are your breadcrumb trail out of that\nforest.\n\n## First steps with logging\n\nPeople will often put section headers in comments in their code. Things\nlike:\n\n``` bash\n# Load data from DB\n```\n\nIf you replace these comments with INFO level log messages, you’ll have\nmade a great start.\n\nUsing the rlog package for R, that would look like this:\n\n``` r\nrlog::log_info(\"Load data from DB\")\n#\u003e 2021-03-03 13:48:35 [INFO] Load data from DB\n```\n\n## Log levels\n\nThe most common log levels, in priority order, are as follows:\n\n-   FATAL\n-   ERROR\n-   WARN\n-   INFO\n-   DEBUG\n-   TRACE\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsol-eng%2Flogging-best-practices","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsol-eng%2Flogging-best-practices","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsol-eng%2Flogging-best-practices/lists"}