Skip to content

loggit() messaging to console suppressed during R markdown rendering due to use of cat() #17

@hlau-mdsol

Description

@hlau-mdsol

In the current loggit.R, echoing of log message is handled by write_ndjson()

write_ndjson(log_df, echo = echo)

write_ndjson(log_df, echo = echo)

which in turn calls cat() if echo = T.
if (echo) cat(logdata, sep = "\n")

loggit/R/json.R

Line 102 in 5399852

if (echo) cat(logdata, sep = "\n")

Previously, in version 1.1.1 (https://cran.r-project.org/src/contrib/Archive/loggit/loggit_1.1.1.tar.gz), if echo = T, the base message function is called in loggit.R.
if (echo) base::message(paste(c(log_lvl, log_msg), collapse = ": "))

Switching to from message() to cat() causes loggit output to console to be suppressed during R markdown rendering as knitr::knit_hooks has options to handle message() output but nothing to handle cat() output (https://bookdown.org/yihui/rmarkdown-cookbook/output-hooks.html).

Here is an example code snippet (I replaced the markdown backticks with a single quote because I can't figure out a way not to confused the code blocking):

'''{r setup, include=FALSE}
library(loggit)
'''
'''{r test message, echo=F,message=F, warning=F}
loggit("INFO", "loggit message", echo = T)
message('base message\n')
'''

Only "base message" will be printed to console during rendering.

I suggest switching back from cat() to message() when echo = T.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions