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 built-in logging classes / capabilities #27958

Closed
smedelyan opened this issue Apr 12, 2019 · 9 comments
Closed

Add built-in logging classes / capabilities #27958

smedelyan opened this issue Apr 12, 2019 · 9 comments

Comments

@smedelyan
Copy link

smedelyan commented Apr 12, 2019

Godot version: 3.1

Issue description:
I do use logging a lot to track things in the game and investigate bugs. But I don't believe that I do that in an efficient way (or that there's such way at all for GDScript). I believe this is a very basic feature, but I've failed to find something related to that.

What I expect from logger
This is a class that allows and supports:

  • customizing logging format. Say, similar to printf special characters, for example:
    • %t would mean current time like 2012-01-30T10:20:30Z or whatever
    • %n would mean name of the logger
    • %t would mean name of thread this logger is triggered from
    • etc
  • log levels. The most important are:
    • ERROR
    • WARN
    • INFO
    • DEBUG
    • TRACE
  • logging destinations:
    • console
    • file
    • what else?
  • remove logging-related pieces of code if the game is not in "debug" mode. It would be fine to have it implemented like directives in C, say:
##ifdef DEBUG
logger.info("some interesting stuff here")
##endif
  • log files rotation policy (optional, I don't believe that there would be developers with need in this)

Currently, I'm doing this with my own Logger class written in GDScript and handling all that levels. But even so, when I need to dig into an issue and set logging level to TRACE (i.e. I see LOTS of logs with every little detail happening in my game) I get irritating message:

output overflow, print less text

But, hell, I do need to print lots of text!

@Calinou
Copy link
Member

Calinou commented Apr 12, 2019

You can use the global scope methods push_error() and push_warning() to print messages that will appear in the Errors tab when running the project from the editor. These messages can also be double-clicked to reach the code that emitted them.

Formatting can be achieved using the % formatting operator or the .format() String method, as explained in GDScript format strings.

@groud
Copy link
Member

groud commented Apr 12, 2019

Related #22202

@smedelyan
Copy link
Author

smedelyan commented Apr 12, 2019

@Calinou still, we lack more detailed levels like INFO, DEBUG and TRACE. What if I want to log some tracking stuff so that I can use that info later when investigating bugs? I don't think that's a good idea to log everything with push_error() / push_warning(). So my proposal is still valid.

P. S. Thanks for those methods, I didn't know that=)

EDIT:
Formatting with .format() is not what I meant. The point is to set up "log template string" (like "%time %name %message") once and then use only logger.debug(message) method. I do not want to provide time, logger name, etc each time I need to log a message

@mitchcurtis
Copy link
Contributor

+1. I'm using a fork of this:

https://github.com/hedin-hiervard/godot-logger

I quite like Qt's way of doing it:

https://doc.qt.io/qt-5/qloggingcategory.html

There you can also use a conf file (INI) to enable/disable warnings.

@smedelyan
Copy link
Author

@mitchcurtis thanks a lot, I'll take a look at that

@chrisgraf
Copy link

+1. We also currently use the above mentioned godot-logger but it is quite limited currently. Also I think this is an important basic functionality which should be provided out of the box. An integrated logging mechanism also would make it possible to dynamically change the loglevel or logging scope in the editor during runtime and thus provide an additional benefit...

@pwab
Copy link

pwab commented May 27, 2020

As this is a proposal and the related PR was closed - could this issue be moved to godotengine/godot-proposals in some way?

@smedelyan
Copy link
Author

@pwab feel free to copy-paste it there, I don't mind :)

@KoBeWi
Copy link
Member

KoBeWi commented May 27, 2020

Since this was moved to proposals, it can be closed.

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.

7 participants