https://github.com/s-fleck/joblog
Log job statuses with lgr
https://github.com/s-fleck/joblog
Last synced: 23 days ago
JSON representation
Log job statuses with lgr
- Host: GitHub
- URL: https://github.com/s-fleck/joblog
- Owner: s-fleck
- License: other
- Created: 2019-12-15T16:43:30.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-01-10T07:53:56.000Z (about 5 years ago)
- Last Synced: 2025-01-29T21:59:49.382Z (23 days ago)
- Language: R
- Size: 41 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE
Awesome Lists containing this project
- jimsghstars - s-fleck/joblog - Log job statuses with lgr (R)
README
---
output: github_document
editor_options:
chunk_output_type: console
---```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
options(crayon.enabled = TRUE, width = 1024)
fansi::set_knit_hooks(knitr::knit_hooks)```
# joblog
[](https://www.tidyverse.org/lifecycle/#experimental)
joblog proposes a format for logging the start and completion of jobs via
[lgr](https://github.com/s-fleck/lgr) (such as cron jobs or automatically
triggered etl operations) and provides utility functions to analyse such logs.
It is desinged to showcase the flexibility of lgr, and not useful on its own.## Installation
``` r
remotes::install_github("s-fleck/joblog")
```## Example
```{r example, width = 1000}
library(joblog)# setup logging
lf <- paste0(tempfile(), ".jsonl")
lg <- lgr::get_logger("jobs")$set_propagate(FALSE) # prevent logging to the console
lg$add_appender(lgr::AppenderJson$new(file = lf), name = "json")lg$list_log(job_start("example")) # log the job start
# ... do stuff ...
lg$list_log(job_finished()) # log the job end# run the same job again
lg$list_log(job_start("example"))
lg$list_log(job_failed("something went wrong"))# log other stuff unrelated to the job
lg$info("today is tuesday")
lg$warn("only true every 7 days")
```Using the setup above we have logged to a json lines file that looks like this:
```{r}
lg$appenders$json$show()
```joblog provides `scrape_joblog()` for extracting the jobs from logfile and
consolidating all info about the job from the relevant log entries, based
on the auto-generated job-id.```{r}
scrape_joblog(lf)
``````
#cleanup
unlink(lf)```