Godot: print() to log text, does not appear from exported app, until after it is closed.

Created on 2 Nov 2019  路  9Comments  路  Source: godotengine/godot

Godot version:
Any

OS/device including version:
Any

Issue description:
print() to log file will not show the output until after the app is closed. This only happens when the executable is exported with Export With Debug flag unchecked.

Steps to reproduce:
Put this code in _ready() of a node script.

extends Node

func _ready():
    for i in range(100):
        print("i=%d" % i)

Make sure you have enabled logging in Project Settings.
image

  • Export Project but uncheck Export With Debug flag before Save To File dialog.
  • Run the exported app.
  • View the log.txt in Project Data Folder while the app main window is still open/running. Path can be found using the following menu option:
    image
  • Notice, no print output is written.
  • Now close app.
  • View log again.
  • This time, the print output result is written.

Somehow it is not flushing output while app is running. This is not good if you are monitoring log output of an app.

discussion core

Most helpful comment

No it does not make sense. If you are printing to logs then it should show up in the logs. The programmer decides if he wants it or not.

All 9 comments

Flushing causes overhead, so it makes sense that it happens only once if you disable debug, no?

No it does not make sense. If you are printing to logs then it should show up in the logs. The programmer decides if he wants it or not.

I wonder if this is related to #33255 somehow. See also https://github.com/godotengine/godot/issues/2233#issuecomment-168401696. While those issues are about printraw(), I suppose the underlying issue is similar.

I wonder if this is related to #33255 somehow. See also #2233 (comment). While those issues are about printraw(), I suppose the underlying issue is similar.

printerr() works fine but also flushes out print() output if it comes after. So in some respects it can be a workaround for flush.

I deployed a server using Godot, which crashes due to an unknown event. Because there is nothing written to the log files, there is no chance to fix anything. I'm not sure if this is the same issue as discussed here. I tick "Enable File Logging" just as explained in the original post. The logs/log.txt file stays empty (0 Byte). I tried:

  • 3 different linux machines
  • debug and release versions
  • rename log.txt to server.log
  • delete all logs and let them re-create
  • run in godot editor and headless-server

The log files stay empty. I have no idea how to fix that.

^
That sounds like a different issue.

See if this article adds anything to help https://medium.com/@silocoder/using-log-files-to-debug-godot-game-engine-apps-14c191df6580

Also I am wondering if reading a log file will force it to be flushed.

Also I am wondering if reading a log file will force it to be flushed.

Probably not; Godot handles when it should flush the standard output/error stream.

@wyattbiker I read this before, no luck.

I ended up using a pipe to write the printed output to a file...

Was this page helpful?
0 / 5 - 0 ratings