Skip to content
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

Feature Request: Capture output from other function as log messages #129

Open
pwwang opened this issue Nov 18, 2023 · 4 comments
Open

Feature Request: Capture output from other function as log messages #129

pwwang opened this issue Nov 18, 2023 · 4 comments
Labels
help wanted Extra attention is needed

Comments

@pwwang
Copy link

pwwang commented Nov 18, 2023

func <- function() {
  print("stdout")
}

log_capture(INFO, { func() })

# INFO [2023-11-17 23:34:41] stdout
func <- function() {
  write("stdout", stdout())
  write("stderr", stderr())
}

log_capture(INFO, ERROR, { func() })

# INFO [2023-11-17 23:34:41] stdout
# ERROR [2023-11-17 23:34:41] stderr
@daroczig
Copy link
Owner

Hm, interesting idea. Just to make sure I understand this: you are looking for a wrapper function that uses sink or similar to capture either/both stdout/stderr and log with provided log level?

Not sure how to avoid the infinite recursion when logging to the console, but otherwise should be doable.

@pwwang
Copy link
Author

pwwang commented Nov 18, 2023

Yes, that's what I wanted.

Just a naive thought about the recursion: how about using a sentinel variable?

@pwwang
Copy link
Author

pwwang commented Nov 27, 2023

Or we could check if the inner message follows the logging format?

@daroczig
Copy link
Owner

Thanks for the feature request! As I am busy with other things, I don't think I have the time to work in this in the coming months, so I would highly appreciate if someone can come up with a PR -- so thus I'm now setting the related "Help wanted" label.

@daroczig daroczig added the help wanted Extra attention is needed label Feb 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants