Description
Changelog
Reviews (0)

Picking the variant

Use the no-log-compat if this is your only rust gdextension OR none of your gdextensions use the "log" crate. You can use the log-compat variant if you are not sure about the above or if one of your rust gdextensions uses the "log" crate.

How to use

These examples below have been tested in Godot and should work.

var SCRIPT_PATH := Log.get_script_path(self)

func _ready() -> void:
    const fname := "_ready"

    Log.trace("This is a trace message :3", SCRIPT_PATH, fname)
    Log.debug("Debugging ducks...", SCRIPT_PATH, fname)
    Log.info("Scene changed to 'res://test.tscn'", SCRIPT_PATH, fname)
    Log.warn("this thingy was wrong, so i corrected it from float to int", SCRIPT_PATH, fname)
    Log.error("file at path 'user://data.json' doesn't exist, falling back to default >:3", SCRIPT_PATH, fname)
    Log.fatal(2, "Something very wrong happened and can't fix it, quitting...", SCRIPT_PATH, fname)  # This will quit synchronously

    # you can also do this for a fatal or any log level:
    #Log.log("log message", SCRIPT_PATH,  Level.FATAL) # replace 'FATAL' with other log levels

Or if you want less writing:

func _ready() -> void:
    var s := Span.span(self, "_ready")

    s.trace("This is a trace message :3")
    s.debug("Debugging ducks...")
    s.info("Scene changed to 'res://test.tscn'")
    s.warn("this thingy was wrong, so i corrected it from float to int")
    s.error("file at path 'user://data.json' doesn't exist, falling back to default >:3")
    s.fatal(2, "Something very wrong happened and can't fix it, quitting...") # This will quit synchronously

    # you can also do this for a fatal or any log level:
    #s.log("log message", Level.FATAL) # or other log levels

Example log output from examples above:

Initializing NovaLogger :3
0:00:00:674:179us Debug rust:nova_logger:src/fatal_handler_singleton.rs:42 Updating addons/nova_logger/quit_function_name property info
0:00:00:701:656us Trace godot:res://example.gd:_ready This is a trace message :3
0:00:00:701:801us Debug godot:res://example.gd:_ready Debugging ducks...
0:00:00:701:860us Info  godot:res://example.gd:_ready Scene changed to 'res://test.tscn'
0:00:00:701:967us Warn  godot:res://example.gd:_ready this thingy was wrong, so i corrected it from float to int
0:00:00:702:107us Error godot:res://example.gd:_ready file at path 'user://data.json' doesn't exist, falling back to default >:3
0:00:00:702:243us Fatal godot:res://example.gd:_ready Something very wrong happened and can't fix it, quitting...
0:00:00:702:392us Info  rust:nova_logger:src/fatal_handler_singleton.rs:110 Calling 'quit' in main loop 'SceneTree' to fatal quit

Colored Godot output: Godot colored output

INFO ABOUT USING THE FATAL VERSION

If you use a MainLoop different than SceneTree you will probably need to change addons/nova_logger/quit_function_name to match the quit function of your main loop. If you don't know what a MainLoop is in Godot and use the normal Godot scenes and nodes you probably don't need to change this. :3

Other features

Easy script path getting:

  • Log.get_script_path(object) - gets the script path from the given object, if object has no path, then returns "<unknown>"

Max log level setting:

  • Log.set_max_log_level(Level.LEVEL) - setting this to Level.INFO will only make the logger print Info and above, used for changing the log level at runtime
  • addons/nova_logger/max_log_level - Setting for doing the above, but in ProjectSettings, recommended to use this as the base and changing using Log.set_max_log_level() on runtime (if needed)

Issues

If you find any issues, please report them on the source code repository with the needed minimal code to reproduce.

Changelog for version v0.3.1-log-compat

No changelog provided for this version.

Reviews

NovaLogger has no reviews yet.

Login to write a review.

Consider supporting the creators!

If you enjoyed this asset consider supporting its creator. Follow the link below.