Skip to content

Commit 4308a05

Browse files
committed
Merge branch 'master' of https://github.com/s-fleck/lgr
2 parents be57bea + c72783d commit 4308a05

35 files changed

+314
-271
lines changed

DESCRIPTION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Suggests:
4040
rotor (>= 0.2.2),
4141
RPostgres,
4242
rprojroot,
43+
RPushbullet,
4344
RSQLite,
4445
sendmailR,
4546
testthat,

NEWS.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
## new features
44
* added `logger_tree()` which provides an overview of all registered loggers
55
* added `print()` and `format()` methods for Appenders
6-
* `AppenderMemory`: added `data` and `dt` active fields
6+
* `AppenderMemory`: added `data` and `dt` active fields (which return the
7+
log as a data.frame or data.table)
78

89
## API changes
910
* Removed deprecated functions `FATAL()`, `ERROR()`. Use `lgr$fatal()`,

R/Appender.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,8 @@ AppenderJson <- R6::R6Class(
419419
layout = LayoutJson$new(),
420420
filters = NULL
421421
){
422+
assert_namespace("jsonlite")
423+
422424
self$set_file(file)
423425
self$set_threshold(threshold)
424426
self$set_layout(layout)
@@ -655,6 +657,7 @@ AppenderDt <- R6::R6Class(
655657
buffer_size = 1e5,
656658
filters = NULL
657659
){
660+
assert_namespace("data.table")
658661
assert(is_scalar_integerish(buffer_size))
659662
assert(
660663
data.table::is.data.table(prototype) && is.integer(prototype$.id),
@@ -1948,6 +1951,8 @@ AppenderPushbullet <- R6::R6Class(
19481951
apikey = NULL,
19491952
filters = NULL
19501953
){
1954+
assert_namespace("RPushbullet")
1955+
19511956
private$initialize_buffer(buffer_size)
19521957
self$set_flush_on_rotate(FALSE)
19531958
self$set_flush_on_exit(FALSE)

R/logger_tree.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ format.logger_tree <- function(
148148
label <- ifelse(
149149
x$n_appenders == 0,
150150
label,
151-
paste0(label, " -> ", x$n_appenders, " appenders")
151+
paste0(label, " -> ", x$n_appenders, " appender", ifelse(x$n_appenders > 1, "s", ""))
152152
)
153153
label <- ifelse(
154154
x$propagate,

README.Rmd

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ package
117117
[documentation](https://s-fleck.github.io/lgr/)
118118

119119

120-
## See lgr in Action
120+
## See lgr in action
121121

122122
lgr is used to govern console output in my shiny based csv editor
123123
[shed](https://github.com/s-fleck/shed)
@@ -144,7 +144,7 @@ file.remove(logfile)
144144
```
145145

146146

147-
## Development Status
147+
## Development status
148148

149149
The api of lgr is stable and safe for use. The internal implementation of
150150
the database logging features still needs some refinement, and if you are
@@ -158,27 +158,27 @@ lgr is currently very actively developed, and feature requests are encouraged.
158158
## Dependencies
159159

160160
[R6](https://github.com/r-lib/R6): The R6 class system provides the framework
161-
on which lgr is built and the **only Package lgr will ever depend on**.
161+
on which lgr is built and the **only Package lgr will ever depend on**. If you
162+
are a **package developer** and want to add logging to your package, this is the
163+
only transitive dependency you have to worry about, as configuring of the
164+
loggers should be left to the user of your package.
162165

163-
### Optional Dependencies
164166

165-
lgr comes with a long list of optional dependencies that make a wide range of
166-
appenders possible. You only need the dependencies for the appenders you
167-
actually want to use. If you are a developer and want to use lgr in one of your
168-
packages, you do not have to worry about these dependencies (configuring loggers
169-
should be left to the user of your package).
167+
### Optional dependencies
170168

171-
Care was taken to choose packages that are slim, stable, have minimal
172-
dependencies, and are well maintained :
169+
lgr comes with a long list of optional dependencies that make a wide range of
170+
appenders possible. You only need the dependencies for the Appenders you
171+
actually want to use. Care was taken to choose packages that are slim, stable,
172+
have minimal dependencies, and are well maintained :
173173

174-
- [crayon](https://github.com/r-lib/crayon) for colored console output.
175-
- [glue](https://glue.tidyverse.org/) for a more flexible formatting syntax
176-
via LoggerGlue and LayoutGlue.
177-
- [data.table](https://github.com/Rdatatable/) for fast in-memory
178-
logging with `AppenderDt`, and also by all database / DBI Appenders.
174+
175+
Extra appenders (and layouts):
176+
179177
- [jsonlite](https://github.com/jeroen/jsonlite) for JSON logging via
180178
`LayoutJson`. JSON is a popular plaintext based file format that is easy to
181179
read for humans and machines alike.
180+
- [rotor](https://github.com/s-fleck/rotor) for log rotation via
181+
AppenderFileRotating and co.
182182
- [DBI](https://github.com/r-dbi/DBI) for logging to databases. lgr is
183183
confirmed to work with the following backends:
184184
- [RSQLite](https://github.com/r-dbi/RSQLite),
@@ -190,24 +190,35 @@ dependencies, and are well maintained :
190190
In theory all DBI compliant database packages should work. If you
191191
are using lgr with a database backend, please report your (positive and
192192
negative) experiences, as database support is still somewhat experimental.
193+
- [data.table](https://github.com/Rdatatable/) for fast in-memory
194+
logging with `AppenderDt`, and also by all database / DBI Appenders.
193195
- [gmailr](https://cran.r-project.org/package=gmailr) or
194196
[sendmailR](https://cran.r-project.org/package=sendmailR) for email
195197
notifications.
196198
- [RPushbullet](https://github.com/eddelbuettel/rpushbullet) for push
197199
notifications.
200+
- [glue](https://glue.tidyverse.org/) for a more flexible formatting syntax
201+
via LoggerGlue and LayoutGlue.
202+
203+
204+
Other extra features:
205+
206+
- [yaml](https://CRAN.R-project.org/package=yaml) for configuring loggers
207+
via YAML files
208+
- [crayon](https://github.com/r-lib/crayon) for colored console output.
198209
- [whoami](https://github.com/r-lib/whoami/blob/master/DESCRIPTION) for
199210
guessing the user name from various sources. You can also set the user name
200211
manually if you want to use it for logging.
201212
- [desc](https://CRAN.R-project.org/package=desc) for the package development
202213
convenience function `use_logger()`
203-
- [yaml](https://CRAN.R-project.org/package=yaml) for configuring loggers
204-
via YAML files
205-
- [rotor](https://github.com/s-fleck/rotor) for log rotation via
206-
AppenderFileRotating and co.
214+
- [cli](https://CRAN.R-project.org/package=cli) for printing the tree
215+
structure of registered loggers with `logger_tree()`
207216

208-
Other optional dependencies (future, future.apply) do not provide any extra
209-
functionality but had to be included as Suggests for some of the automated
210-
unit tests run by lgr.
217+
Other `Suggests`
218+
([future](https://CRAN.R-project.org/package=future),
219+
[future.apply](https://CRAN.R-project.org/package=future.apply)) do not
220+
provide extra functionality but had to be included for some of
221+
the automated unit tests run by lgr.
211222

212223

213224
## Installation

README.md

Lines changed: 50 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,19 @@ Appenders.
3939
can write to the console, a logfile, a database, etc… .
4040
- Allow for *custom fields* in log events. As opposed to many other
4141
logging packages for R a log event is not just a message with a
42-
timestamp, but can contain arbitrary data fields. This is very
43-
helpful if you want to produce logs that are machine readable and
44-
easy to analyze.
42+
timestamp, but an object that can contain arbitrary data fields.
43+
This is useful for producing machine readable logs.
4544
- *Vectorized* logging (so `lgr$fatal(capture.output(iris))` works)
46-
- Lightning fast *in-memory log* based in `data.table` included for
47-
interactive use.
48-
- Comes with a *wide range of appenders*, for example for:
49-
- Appending to Databases (buffered or directly)
50-
- Sending notifications via email or pushbullet
51-
- writing JSON with arbitrary data fields
52-
- In memory buffers
53-
- colored console output
45+
- Lightning fast *in-memory logs* for interactive use.
46+
- Appenders that write logs to a wide range of destinations:
47+
- databases (buffered or directly)
48+
- email or pushbullet
49+
- plaintext files (with a powerful formatting syntax)
50+
- JSON files with arbitrary data fields
51+
- Rotating files that are reset and backed-up after they reach a
52+
certain file size or age
53+
- memory buffers
54+
- (colored) console output
5455
- Optional support to use [glue](https://glue.tidyverse.org/) instead
5556
of `sprintf()` for composing log messages.
5657

@@ -64,13 +65,13 @@ vignette.
6465

6566
``` r
6667
lgr$fatal("A critical error")
67-
#> FATAL [06:42:54.110] A critical error
68+
#> FATAL [08:25:07.182] A critical error
6869
lgr$error("A less severe error")
69-
#> ERROR [06:42:54.139] A less severe error
70+
#> ERROR [08:25:07.211] A less severe error
7071
lgr$warn("A potentially bad situation")
71-
#> WARN [06:42:54.150] A potentially bad situation
72+
#> WARN [08:25:07.221] A potentially bad situation
7273
lgr$info("iris has %s rows", nrow(iris))
73-
#> INFO [06:42:54.152] iris has 150 rows
74+
#> INFO [08:25:07.223] iris has 150 rows
7475

7576
# the following log levels are hidden by default
7677
lgr$debug("A debug message")
@@ -84,9 +85,9 @@ appender to log to a file with little effort.
8485
tf <- tempfile()
8586
lgr$add_appender(AppenderFile$new(tf, layout = LayoutJson$new()))
8687
lgr$info("cars has %s rows", nrow(cars))
87-
#> INFO [06:42:54.168] cars has 50 rows
88+
#> INFO [08:25:07.239] cars has 50 rows
8889
cat(readLines(tf))
89-
#> {"level":400,"timestamp":"2019-05-23 06:42:54","logger":"root","caller":"eval","msg":"cars has 50 rows"}
90+
#> {"level":400,"timestamp":"2019-06-11 08:25:07","logger":"root","caller":"eval","msg":"cars has 50 rows"}
9091
```
9192

9293
By passing a named argument to `info()`, `warn()`, and co you can log
@@ -96,17 +97,17 @@ logfiles that are machine as well as (somewhat) human readable.
9697

9798
``` r
9899
lgr$info("loading cars", "cars", rows = nrow(cars), cols = ncol(cars))
99-
#> INFO [06:42:54.191] loading cars {rows: 50, cols: 2}
100+
#> INFO [08:25:07.258] loading cars {rows: 50, cols: 2}
100101
cat(readLines(tf), sep = "\n")
101-
#> {"level":400,"timestamp":"2019-05-23 06:42:54","logger":"root","caller":"eval","msg":"cars has 50 rows"}
102-
#> {"level":400,"timestamp":"2019-05-23 06:42:54","logger":"root","caller":"eval","msg":"loading cars","rows":50,"cols":2}
102+
#> {"level":400,"timestamp":"2019-06-11 08:25:07","logger":"root","caller":"eval","msg":"cars has 50 rows"}
103+
#> {"level":400,"timestamp":"2019-06-11 08:25:07","logger":"root","caller":"eval","msg":"loading cars","rows":50,"cols":2}
103104
```
104105

105106
For more examples please see the package
106107
[vignette](https://s-fleck.github.io/lgr/articles/lgr.html) and
107108
[documentation](https://s-fleck.github.io/lgr/)
108109

109-
## See lgr in Action
110+
## See lgr in action
110111

111112
lgr is used to govern console output in my shiny based csv editor
112113
[shed](https://github.com/s-fleck/shed)
@@ -132,7 +133,7 @@ readLines(logfile)
132133
file.remove(logfile)
133134
```
134135

135-
## Development Status
136+
## Development status
136137

137138
The api of lgr is stable and safe for use. The internal implementation
138139
of the database logging features still needs some refinement, and if you
@@ -146,29 +147,26 @@ encouraged.
146147

147148
[R6](https://github.com/r-lib/R6): The R6 class system provides the
148149
framework on which lgr is built and the **only Package lgr will ever
149-
depend on**.
150+
depend on**. If you are a **package developer** and want to add logging
151+
to your package, this is the only transitive dependency you have to
152+
worry about, as configuring of the loggers should be left to the user of
153+
your package.
150154

151-
### Optional Dependencies
155+
### Optional dependencies
152156

153157
lgr comes with a long list of optional dependencies that make a wide
154158
range of appenders possible. You only need the dependencies for the
155-
appenders you actually want to use. If you are a developer and want to
156-
use lgr in one of your packages, you do not have to worry about these
157-
dependencies (configuring loggers should be left to the user of your
158-
package).
159+
Appenders you actually want to use. Care was taken to choose packages
160+
that are slim, stable, have minimal dependencies, and are well
161+
maintained :
159162

160-
Care was taken to choose packages that are slim, stable, have minimal
161-
dependencies, and are well maintained :
163+
Extra appenders (and layouts):
162164

163-
- [crayon](https://github.com/r-lib/crayon) for colored console
164-
output.
165-
- [glue](https://glue.tidyverse.org/) for a more flexible formatting
166-
syntax via LoggerGlue and LayoutGlue.
167-
- [data.table](https://github.com/Rdatatable/) for fast in-memory
168-
logging with `AppenderDt`, and also by all database / DBI Appenders.
169165
- [jsonlite](https://github.com/jeroen/jsonlite) for JSON logging via
170166
`LayoutJson`. JSON is a popular plaintext based file format that is
171167
easy to read for humans and machines alike.
168+
- [rotor](https://github.com/s-fleck/rotor) for log rotation via
169+
AppenderFileRotating and co.
172170
- [DBI](https://github.com/r-dbi/DBI) for logging to databases. lgr is
173171
confirmed to work with the following backends:
174172
- [RSQLite](https://github.com/r-dbi/RSQLite),
@@ -181,23 +179,33 @@ dependencies, and are well maintained :
181179
are using lgr with a database backend, please report your (positive
182180
and negative) experiences, as database support is still somewhat
183181
experimental.
182+
- [data.table](https://github.com/Rdatatable/) for fast in-memory
183+
logging with `AppenderDt`, and also by all database / DBI Appenders.
184184
- [gmailr](https://cran.r-project.org/package=gmailr) or
185185
[sendmailR](https://cran.r-project.org/package=sendmailR) for email
186186
notifications.
187187
- [RPushbullet](https://github.com/eddelbuettel/rpushbullet) for push
188188
notifications.
189+
- [glue](https://glue.tidyverse.org/) for a more flexible formatting
190+
syntax via LoggerGlue and LayoutGlue.
191+
192+
Other extra features:
193+
194+
- [yaml](https://CRAN.R-project.org/package=yaml) for configuring
195+
loggers via YAML files
196+
- [crayon](https://github.com/r-lib/crayon) for colored console
197+
output.
189198
- [whoami](https://github.com/r-lib/whoami/blob/master/DESCRIPTION)
190199
for guessing the user name from various sources. You can also set
191200
the user name manually if you want to use it for logging.
192201
- [desc](https://CRAN.R-project.org/package=desc) for the package
193202
development convenience function `use_logger()`
194-
- [yaml](https://CRAN.R-project.org/package=yaml) for configuring
195-
loggers via YAML files
196-
- [rotor](https://github.com/s-fleck/rotor) for log rotation via
197-
AppenderFileRotating and co.
203+
- [cli](https://CRAN.R-project.org/package=cli) for printing the tree
204+
structure of registered loggers with `logger_tree()`
198205

199-
Other optional dependencies (future, future.apply) do not provide any
200-
extra functionality but had to be included as Suggests for some of the
206+
Other `Suggests` ([future](https://CRAN.R-project.org/package=future),
207+
[future.apply](https://CRAN.R-project.org/package=future.apply)) do not
208+
provide extra functionality but had to be included for some of the
201209
automated unit tests run by lgr.
202210

203211
## Installation

0 commit comments

Comments
 (0)