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

Add a way to access stdout and stderr's contents from the engine #536

Closed
EIREXE opened this issue Feb 29, 2020 · 13 comments
Closed

Add a way to access stdout and stderr's contents from the engine #536

EIREXE opened this issue Feb 29, 2020 · 13 comments

Comments

@EIREXE
Copy link

EIREXE commented Feb 29, 2020

Describe the project you are working on:

A Rhythm Videogame

Describe the problem or limitation you are having in your project:

I would like to redirect standard outputs to my game so that I can log it myself and use it with steam logging services.

Describe the feature / enhancement and how it helps to overcome the problem or limitation:

Some sort of mechanism to redirect stderr and stdout, this would not only include print() calls but anything the engine has printed too.

Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams:

Could be a global singleton (or an existing one) that has a signal that is fired when a line is printed by the engine.

If this enhancement will not be used often, can it be worked around with a few lines of script?:

You could continuously read the log files, but I am not sure how well that would work.

Is there a reason why this should be core and not an add-on in the asset library?:
It needs to be core because the only way you could solve it is with an engine module, and I am not entirely sure if it could even be done without changing the engine's code.

@groud
Copy link
Member

groud commented Feb 29, 2020

I don't really get it, redirecting stderr and stdout is a feature your OS is supposed to have.
At least on linux it's pretty easy to do.

@EIREXE
Copy link
Author

EIREXE commented Mar 1, 2020

I don't really get it, redirecting stderr and stdout is a feature your OS is supposed to have.
At least on linux it's pretty easy to do.

The point is to redirect STDERR and STDOUT to the game itself, exposing an API for it, unless there's a different way to do this already.

I think I may have worded it wrong, I want a way to access all engine logs at runtime, this includes whatever the engine prints.

@Calinou Calinou changed the title STDERR/STDOUT redirect Add a way to access stdout and stderr's contents from the engine Mar 2, 2020
@linkpy
Copy link

linkpy commented Mar 4, 2020

and use it with steam logging services.

You can't do that by piping the STDERR/OUT of Godot's process. It could also be useful for multiple loggers working at the same time (writing to a file, to the console, etc at the same time), which would print everything, even the message from the engine itself.

@willnationsdev
Copy link
Contributor

willnationsdev commented Mar 4, 2020

So you want a built-in Log singleton that wraps all of the print statements made by the engine and enables you to override/redirect/reprogram the logging behavior? I fully support that idea. Would be very useful.

@EIREXE
Copy link
Author

EIREXE commented Mar 4, 2020

So you want a built-in Log singleton that wraps all of the print statements made by the engine and enables you to override/redirect/reprogram the logging behavior? I fully support that idea. Would be very useful.

Yes, this is exactly what I mean.

@Calinou
Copy link
Member

Calinou commented Apr 30, 2020

What would be the most logical singleton for exposing this? I'm thinking about Engine::get_stdout() and Engine::get_stderr(). That said, I wonder if performance and memory usage would become an issue if stdout/stderr gets large after several hours (or days) of process uptime.

@EIREXE
Copy link
Author

EIREXE commented Apr 30, 2020

What would be the most logical singleton for exposing this? I'm thinking about Engine::get_stdout() and Engine::get_stderr(). That said, I wonder if performance and memory usage would become an issue if stdout/stderr gets large after several hours (or days) of process uptime.

Could add a boolean to enable monitoring of stderr and stdout (maybe a ProjectSettings option) and making get_stdout and get_stderr clean the buffer.

@CRHough
Copy link

CRHough commented Aug 21, 2020

Maybe versions of functions which print to stdout or stderr which return strings?

@Calinou
Copy link
Member

Calinou commented Aug 21, 2020

@CRHough That requires modifying the code so you can get stdout/stderr, which is a no-go if you want to get output from C++ code (the engine itself) or add-ons you'd prefer not to modify.

@Parmeisan
Copy link

I'm new here and not sure if the proper way to do this is just to comment, but I'd like to second this proposal.

I'm working on an adventure game engine built within Godot (an engine within an engine), which in the end would work entirely off of spreadsheets. You set up your characters.csv, scenes.csv, scripts.csv etc and run Godot, and it finds the files and plays the game. For developers there is a Debug Mode. All of my errors/logging goes to a log which can be viewed/filtered/etc while in this mode. However, certain error messages do not seem to be accessible from within Godot. For example, if you're editting a spreadsheet with Windows (even an Open Office one), it "helpfully" replaces dashes with emdashes and double quotes with whatever-they-are. This throws an error when converting get_csv_line (PoolStringArray) to a string: "Unicode error: invalid skip". I know what this error is, when it happens, and how to fix it. But if my engine-within-an-engine is going to work, then errors like these need to be caught somehow and routed to the debug log.

Of course if there's another way to do this, feel free to enlighten me. :)

Thanks!

@Parmeisan
Copy link

Note: I have discovered I was slightly off about which line threw the error (simply calling get_csv_line, which is expecting but not receiving UTF-8) and have solved this for myself by checking for a pool array result which consists of a single empty item. However, being able to access stdout would still be preferable, as there may be other miscellaneous errors which are sent to stdout rather than being thrown to Godot. (Alternately, in my own case, moving these errors to somewhere accessible by Godot - in the same way that's done with file reading, regex, etc - would also solve the problem).

@reduz
Copy link
Member

reduz commented Aug 23, 2021

Is there a reason why this should be core and not an add-on in the asset library?:
It needs to be core because the only way you could solve it is with an engine module, and I am not entirely sure if it could even be done without changing the engine's code.

With the new extension system, exposing this to be made an extension is now possible, so IMO I think the proposal should be changed to exposing a way to make a custom logger.

@Calinou
Copy link
Member

Calinou commented Aug 23, 2021

Closing, as this proposal needs to be rewritten to handle the creation of custom loggers instead (#536 (comment)).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants