-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathREADME.Rmd
More file actions
101 lines (75 loc) · 3.38 KB
/
README.Rmd
File metadata and controls
101 lines (75 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
---
title: "README"
output:
md_document:
variant: gfm
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
old <- options(width = 150)
```
Easy-to-use, dependencyless Logger for R
==================================
<!-- badges: start -->
[](https://cran.r-project.org/package=loggit2)
[](https://github.com/MEO265/loggit2/actions/workflows/R-CMD-check.yaml)
[](https://codecov.io/gh/MEO265/loggit2)
------------------------------------------------------------------------
<!-- badges: end -->
`loggit2` is an easy-to-use [`ndJSON`](https://github.com/ndjson/ndjson-spec) logging library for R,
with _zero_ external dependencies.
Please see below for some quick examples, and read the
[vignettes](https://cran.r-project.org/web/packages/loggit2/vignettes/) for more.
Why use `loggit2`?
-----------------
`loggit2` takes a minimalistic but powerful approach to logging in R:
- Easy integration, even into existing code
- Flexible logs with automatic field creation
- Logs immediately available as `data.frame` object, ndJSON and CSV file
- Simple external logging (e.g., in containers) via ndJSON echo to stdout
- _Zero_ external dependencies
Additionally, the boilerplate to get going with `loggit2` is minimal at worst.
Usage
--------------
`loggit2` provides, among other functions, a set of wrappings for base R’s `message()`, `warning()`, `stop()` and
`stopifnot()` functions that maintain identical functionality, except the additional logging.
Thus, it is sufficient to import the `loggit2` namespace, for example by using `library("loggit2")`,
or by prefixing `loggit2::` at the desired locations.
```{r, error = TRUE}
base::message("This is another message")
loggit2::message("This is a message")
base::warning("This is another warning")
loggit2::warning("This is a warning")
base::stop("This is another error")
loggit2::stop("This is an error")
base::stopifnot("This is another condition" = FALSE)
loggit2::stopifnot("This is another condition" = FALSE)
```
You can suppress the additional console output by using `echo = FALSE` and
you won't notice any difference to the base functions (except that the log
will be filled in the background).
You can also directly use the logging function `loggit()` to compose much more custom logs, e.g.
to include custom fields or to prevent throwing actual conditions.
```{r loggit2}
loggit2::loggit("ERROR", "This will log an error", anything_else = "you want to include")
# Read log file into data frame to implement logic based on entries
loggit2::read_logs()
```
No further configurations are necessary for this:
just throw nearly whatever you want at it, and it'll become a structured log.
Check out the [vignettes](https://cran.r-project.org/web/packages/loggit2/vignettes/) for more details and features.
Installation
------------
You can install the latest CRAN release of `loggit2` via
install.packages("loggit2")
or, get the latest development version from GitHub via
devtools::install_github("MEO265/loggit2")
Acknowledgments
-----------
This package is based on the ["loggit" package by Ryan Price](https://github.com/ryapric/loggit), specifically version 2.1.1.
```{r, include = FALSE}
options(old)
```