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 INFO_PRINT() and push_info() for important but "expected" messages #1378

Open
Calinou opened this issue Aug 16, 2020 · 5 comments
Open

Comments

@Calinou
Copy link
Member

Calinou commented Aug 16, 2020

See also #919.

Describe the project you are working on:

The Godot editor 🙂

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

We currently have ERR_PRINT() and WARN_PRINT() macros to print error and warning messages respectively. (These are available as push_error() and push_warning() in GDScript.)

However, we don't have an equivalent for informational prints that are not errors or warnings. We can use print(), but this is typically used for debugging instead.

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

Add an info logging category for messages that are more important than others, but aren't considered errors or warnings.

This will also be helpful once we implement filtering messages by category in the editor's Output panel.

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

Add a INFO_PRINT() macro in C++ and expose a push_info() global scope method in GDScript (and by extension, C#).

Unlike the warning and error print handlers, the info print handler should not print a stack trace to the terminal since the user doesn't need to know the message's origin. The message should also not appear in the editor's Errors panel.

In the terminal, we can use the \e[1m (bold) ANSI escape code for coloring the message. This makes it easier to dinstinguish from standard print()s.

image

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

It can be implemented by a script, but it's not ideal as we'd prefer to have a standard way of reporting informational messages.

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

See above.

@Xrayez
Copy link
Contributor

Xrayez commented Aug 16, 2020

Yeah, see example use case where existing warning messages could be converted to informational messages as seen in godotengine/godot#39396. Having ability to control the severity/verbosity of those type of messages would also be nice to have. The existence of dedicated informational prints may also remove the need for using print_line() in some cases, but might be a bit far fetched.

@jonbonazza
Copy link

Holy crap, i didnt know push_error and push_warn existed!

@Error7Studios
Copy link

I created a quick version of this in a singleton because I wanted to be able to disable all of the printed 'notes' and warnings with just a boolean toggle when I was done testing something and wanted to see my other print statements without the console being so cluttered.
(And also so I could tell which print statements I meant to keep "permanently" vs only temporarily)

Would be nice to have a toggle in the Project Settings for globally disabling either push_warning() and push_info() instead of having to remove/comment out those calls one at a time.
(We may only want to disable them for a short time, not completely remove them or have to un-comment them again)

Here's what I did:

var is_alerting_notes := true
var is_alerting_warnings := true


const Note := {
	Rejected_Simulated_BTN_Event = "Rejected_Simulated_BTN_Event",
	Rejected_Non_Simulated_BTN_Event = "Rejected_Non_Simulated_BTN_Event",
}

const Warning := {
	Menu_Row_Empty = "Menu_Row_Empty",
}

const Error := {
	Menu_Pos_Already_Taken = "Menu_Pos_Already_Taken",
	No_Assigned_Menu_Controlling_Scene = "No_Assigned_Menu_Controlling_Scene",
}


func send_note(__note: String, __details: String = ""):
	assert(Note.values().has(__note))
	if is_alerting_notes:
		if !__details.empty():
			print_debug("\n", __note, "\n", __details)
		else:
			print_debug("\n", __note)

func send_warning(__warning: String, __details: String = ""):
	assert(Warning.values().has(__warning))
	if is_alerting_warnings:
		if !__details.empty():
			push_warning(str(__warning, " - ", __details))
		else:
			push_warning(__warning)

func send_error(__error: String, __details: String = ""):
	assert(Error.values().has(__error))
	push_error("Critical error. See print statement.")
	if !__details.empty():
		print("\n", __error, "\n", __details)
	else:
		print("\n", __error)
	assert(false)

@Calinou
Copy link
Member Author

Calinou commented Aug 20, 2020

@Error7Studios This pull request will address the need for filtering: godotengine/godot#41321

@Calinou
Copy link
Member Author

Calinou commented Oct 26, 2020

I started working on this, but I can't get it to display in the editor Output log when push_info() isn't called from a tool script: https://github.com/Calinou/godot/tree/add-push-info

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

No branches or pull requests

4 participants