Skip to content

Allow setting "application/run/disable_stdout" at runtime #9564

Closed
godotengine/godot
#90955
@CsloudX

Description

@CsloudX

Describe the project you are working on

NoGame-APP

Describe the problem or limitation you are having in your project

I'm create a console server app, and client can connect.
in my project, I have many code for debug use prints function.
when i export project, i don't want console print this info, so i set disable_std_out in ProjectSettings.
but for some info, like client connect server, client request info etc, i want print this info.

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

For now, the application/run/disable_stdout can't take effect on runtime:
image

Maybe can implement a method for this:

static func prints_smart(text, always:=false):
	if OS.has_feature("editor") or always:
		prints(text)

but there was 2 problems:

  1. in my project, there was so much prints codes need update.
  2. need to implement much methods like print_debug, printerr etc.
  3. some info can't take effect like:
    image

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

My code like this:

var disable_stdout = false

func _ready():
	if if OS.has_feature("editor"):
		disable_stdout = false
	else:
		disable_stdout = true
	ProjectSettings.set_setting("application/run/disable_stdout",disable_stdout)
	
	prints("App Start")

func print_always(text):
	if disable_stdout:
		ProjectSettings.set_setting("application/run/disable_stdout",false)
		prints(text)
		ProjectSettings.set_setting("application/run/disable_stdout",true)
	else:
		prints(text)
	

func _on_client_connect():
	print_always("client connect")

func _on_client_req_info(info):
	print_always("client req info:%s"%info)
	req_info(info)


func req_info(info):
	prints(info.id)
	prints(info.name)
	prints(info.many_info)


func quit():
	prints("quit")

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

In the Editor, it should prints:

>App Start
>client connect
>client req info: aaa
>info.id = 564564563165
>info.name = "asfafdasdfasf"
>info.many_info = asdfasfasdf
sadfdsaf
saf
as
f
safd
>quit

For exported app, it should prints:

>App Start
>client connect
>client req info: aaa

Other a simple example:

func _ready():
	test(true)
	test(false)
	test(true)
	test(false)

func test(disable:bool):
	ProjectSettings.set_setting("application/run/disable_stdout",disable)
	if disable:
		prints("Disable, This line can't print")
	else:
		prints("Enable, This line should print")

I wish output was:

>Enable, This line should print
>Enable, This line should print

Is there a reason why this should be core and not an add-on in the asset library?

No, it should be core

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions