File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed
Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -882,6 +882,27 @@ events will get redirected to the root Logger (see [Inheritance](#hierarchy)).
882882see 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 )
You can’t perform that action at this time.
0 commit comments