godot server no stdout when run non-interactively

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Ian Colwell

I am running godot server using the following command:

./godot-server --main-pack game.pck

which displays output like this:

Godot Engine v3.2.1.stable.official - https://godotengine.org

ERROR: get_language_code: Condition "p_locale.length() < 2" is true. Returned: p_locale
   At: core/translation.cpp:945.
ERROR: set_locale: Unsupported locale 'C', falling back to 'en'.
   At: core/translation.cpp:969.
Starting game

When I try to capture this output into a log file like this:

./godot-server --main-pack game.pck &> /tmp/test.log

I end up with only the stderr in the log file, and not the stdout:

ERROR: get_language_code: Condition "p_locale.length() < 2" is true. Returned: p_locale
   At: core/translation.cpp:945.
ERROR: set_locale: Unsupported locale 'C', falling back to 'en'.
   At: core/translation.cpp:969.

I actually first noticed this when trying to run the server from a systemd service, the stdout is not being captured by journalctl.

Any thoughts? possible bug? buffers not being flushed or something?

:bust_in_silhouette: Reply From: Calinou

Any thoughts? possible bug? buffers not being flushed or something?

That’s correct. In the interest of performance, Godot will only flush the buffer when it exits.

This should probably be changed for server builds at least, as this is problematic for logging using systemd.

Thanks a lot for the response! Glad my hunch was confirmed and I wasn’t doing something silly :smiley:

Should I open a Godot Improvement Proposal regarding this?

In the short term, is there any way to flush it from within the software?

Ian Colwell | 2020-07-18 17:57

Hey @ian! Did you end up logging this item? I’m running into the same issue and can’t seem to get a systemd run godot headless server to log anywhere.

broknecho | 2020-11-29 20:06

Hi @broknecho,

I didn’t solve this issue, but I worked around it by always using printerr() instead of print(). Nasty solution but my server code is very light, so it wasn’t a big deal for me.
I created an issue here about it, if you wish to track it:
Add a project setting to flush standard output on every printed line · Issue #1912 · godotengine/godot-proposals · GitHub

Ian Colwell | 2020-12-01 01:35

Hi @Ian!

Thanks for posting the issue. It was super weird as I didn’t see any logging in my testing but I finally ran a pretty big load test against the running Godot service and journalctl did finally start showing some output. I wonder if the buffer size was getting too big and flushed itself before a restart.

The other option I was thinking about was to use the mono build and bring in some serilog sinks to do some logging.

Thanks again for posting this and I thumbed it up to watch it.

broknecho | 2020-12-01 05:56

So what is the short term work around for this?

PoisnFang | 2021-02-23 17:41