-
Notifications
You must be signed in to change notification settings - Fork 129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Option to redirect informal console messages to a file #401
Conversation
I like your paste @wlandau 👍 😊. So is that approach catching communication issued via |
Codecov Report
@@ Coverage Diff @@
## master #401 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 65 65
Lines 5170 5191 +21
=====================================
+ Hits 5170 5191 +21
Continue to review full report at Codecov.
|
@lorenzwalthert, I am not sure I know what you mean. In |
|
Thanks. Maybe I was not specific enough, so here's the reprex: library(drake)
futile.logger::flog.appender(futile.logger::appender.file("futile-logger"),
name = "default")
#> NULL
options(crayon.enabled = FALSE)
just_some_random_communication <- function(a) {
cat("cat")
print("print")
warning("warning")
message("message")
as.integer("L")
futile.logger::flog.error("This is an error", name = "default")
}
plan <- drake_plan(random = just_some_random_communication(4))
clean()
unlink(c("drake-logger", "futile-logger"))
make(plan, seed = 200, console = "drake-logger")
#> cat[1] "print"
#> Warning in just_some_random_communication(4): warning
#> message
#> Warning in just_some_random_communication(4): NAs introduced by coercion
#> Warning: target random warnings:
#> warning
#> NAs introduced by coercion
#> Target random messages:
#> message
readLines("drake-logger")
#> [1] "target random"
readLines("futile-logger")
#> [1] "ERROR [2018-05-31 23:26:27] This is an error" I think in principle it would be nice to have the warnings and messages created inside the functions inside the drake plan sent to the logging file too instead of the console. But as I said, it does not seem to be a super pressing issue. I tried to play around a bit with |
I suppose we could write other messages to the log too, plus warnings and errors. For what it's worth, the log does tell you if a target failed. |
Update: from 2b0fff2, the log file should now catch errors, warnings, and messages from running the user-supplied commands to build targets. Regular output from Also, if you specify a file with |
And from 7f603e7, library(drake)
futile.logger::flog.appender(futile.logger::appender.file("futile-logger"),
name = "default")
#> NULL
options(crayon.enabled = FALSE)
just_some_random_communication <- function(a) {
cat("cat")
print("print")
warning("warning")
message("message")
as.integer("L")
futile.logger::flog.error("This is an error", name = "default")
}
plan <- drake_plan(random = just_some_random_communication(4))
clean()
unlink(c("drake-logger", "futile-logger"))
make(plan, seed = 200, console = "drake-logger")
#> Warning in just_some_random_communication(4): warning
#> message
#> Warning in just_some_random_communication(4): NAs introduced by coercion
#> Warning: target random warnings:
#> warning
#> NAs introduced by coercion
cat(readLines("drake-logger"), sep = "\n")
#> target random
#> Warning: target random warnings:
#> warning
#> NAs introduced by coercion
#> Target random messages:
#> message
#> Target random console output:
#> cat[1] "print"
cat(readLines("futile-logger"), sep = "\n")
#> ERROR [2018-06-01 12:49:27] This is an error |
On second thought, I do not think it is a good idea to capture |
Thanks so much @wlandau 😊. I just tried quickly and it works as expected. I can even use the same log file for Obviously I can't foresee all use-cases, but it seems to make sense to reserve |
Update: in 1a77aae, I changed the |
Summary
If
verbose
is> 0
,make()
outputs progressmessage()
s to the console.In this PR,
make(console = "log.txt")
appends these messages to the file"log.txt"
. That way, users can just inspect a log file instead of pollingprogress()
, and we avoid the issues described in futureverse/future#171 (comment).Note: if you want to suppress color coding characters, you will need to call
options(crayon.enabled = FALSE)
in your session and possiblymake(prework = "options(crayon.enabled = FALSE)")
.cc @lorenzwalthert
Related GitHub issues
Checklist
drake
's code of conduct, and I agree to follow its rules.testthat
unit tests totests/testthat
to confirm that any new features or functionality work correctly.devtools::check()