Skip to content

Commit 8fe0c76

Browse files
committed
add this.path filter tutorial to vignette
1 parent 9d77785 commit 8fe0c76

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

vignettes/lgr.Rmd

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,27 @@ events will get redirected to the root Logger (see [Inheritance](#hierarchy)).
882882
see https://github.com/s-fleck/lgr/issues/29
883883

884884

885+
## Adding the source file / R-script to the log event
886+
887+
Getting the source file is sadly non-trivial in R, otherwise it would have
888+
been included in the core logging functions. Luckily, this is easy to add
889+
with filters and the awesome [this.path](https://CRAN.R-project.org/package=this.path)
890+
package. This solution works in most scenarions, but not in all
891+
(for example, building this vignette).
892+
893+
```{r, eval = FALSE}
894+
# install.packages("this.path")
895+
896+
lg <- get_logger("srcfile")
897+
lg$add_filter(function(event){
898+
tryCatch({
899+
event$srcfile <- this.path::this.path()
900+
}, error = function(e) NULL)
901+
TRUE
902+
})
903+
```
904+
905+
885906
# References
886907

887908
[Python Logging](https://docs.python.org/3/library/logging.html)

0 commit comments

Comments
 (0)