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

Intercept stdout of plugins to add a timestamp to each line #6

Open
1 task
subatiq opened this issue Dec 20, 2022 · 5 comments
Open
1 task

Intercept stdout of plugins to add a timestamp to each line #6

subatiq opened this issue Dec 20, 2022 · 5 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@subatiq
Copy link
Owner

subatiq commented Dec 20, 2022

Expected plugins output:

[12-12-2023T12:12:12] dropper   > Doing some stuff... 
[12-12-2023T12:12:12] deathloop > Deathlooping like crazy
@subatiq subatiq added help wanted Extra attention is needed enhancement New feature or request labels Dec 20, 2022
@subatiq subatiq added this to the Increased usability milestone Feb 11, 2023
@subatiq subatiq assigned subatiq and unassigned subatiq Feb 16, 2023
@subatiq
Copy link
Owner Author

subatiq commented Feb 21, 2023

@ilya-siluyanov let's collect every option for the solution here.

It must be platform-independent and compatible with any type of plugin.

Also, plugins themselves (the model) should be decoupled from the output formatter

@subatiq
Copy link
Owner Author

subatiq commented Feb 21, 2023

There is no way to do this in the standard library1. The gag crate allows redirecting stderr or stdout either to a file or to nothing, but it only works on *nix systems.

In a different view of the problem, I'd encourage you to not use stdout or stderr directly at all. Instead, use dependency injection to pass down values that can be written to. Instead of using println, use writeln.

https://stackoverflow.com/questions/54429389/how-to-redirect-stderr-from-inside-the-process-in-rust

@subatiq
Copy link
Owner Author

subatiq commented Feb 21, 2023

We can add logging implementation for every type of plugin

PyO3/pyo3#1918 (comment)

@ilya-siluyanov
Copy link

ilya-siluyanov commented Feb 21, 2023

Seems like an old thread - https://doc.rust-lang.org/std/process/struct.Command.html#method.stderr
I don't see any problems to use stderr in a similar manner as here

It must be platform-independent

That seems legit, my solution doesn't use any method marked as *nix only

Compatible with any type of plugin

If I print a symbol without \n, should I assign it a timestamp? what if I will get another symbol then? I need to rewrite the previous timestamp? I think there should be an agreement like "assign a timestamp only to a line", because supporting some features might be too costly

@subatiq
Copy link
Owner Author

subatiq commented Feb 21, 2023

Also, there are methods for styling the output in stdout_styling.rs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants