Skip to content

Feature request: turn off log_messages temporarily #235

@metanoid

Description

@metanoid

I am using the {logger} together with the {progress} package.
It's very helpful to have log_messages() at the top of my script.
However, when my script gets to the long-running for-loop, I'd like to be able to print the progress bar to the terminal without having the progress bar updates print to the log.

I'm asking to be able to do something like this:

# top of script
library(progress)
library(logger)
log_messages(TRUE)

# lots of code goes here
message("I'm a little teapot") # this line should appear in the logs

# long-running for loop
pb = progress::progress_bar$new(total = 100)
log_info("Starting long loop now")
log_messages(FALSE)
for (i in 1:100) {
    pb$tick()  # should print to terminal, but not appear in logs
    # complex code goes here
    Sys.sleep(0.1)
}
log_info("Finished long looop")
# turn message logging back on
log_messages(TRUE)

# rest of script continues
message("Tada")  # this line should appear in logs

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions