:github_url: hide .. DO NOT EDIT THIS FILE!!! .. Generated automatically from Godot engine sources. .. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py. .. XML source: https://github.com/godotengine/godot/tree/master/stag-toolkit/sphinx/gen/gdscript/StagLogger.xml. .. _class_StagLogger: StagLogger ========== **Inherits:** ``Logger`` Simple ``Logger`` wrapper that allows for script error detection. .. rst-class:: classref-introduction-group Description ----------- Allows logging with log levels, and can optionally include Engine logs and error detection. The logger supports additional customization, such as console colors and log levels :ref:`log_level_console`. If the logger is registered with the engine via :ref:`OS.add_logger()`, pushed errors and warnings will automatically be written to the buffer (if one exists). :: var logger := StagLogger.new() # Customize logger as desired... logger.log_level_console = StagLogger.LogLevel.LLDebug logger.log_level_buffer = StagLogger.LogLevel.LLInfo logger.color_warn = Color.YELLOW logger.flush_interval = 50 # ... logger.create_buffer(false) # Optionally create a temp file for writing to OS.add_logger(logger) # Optionally register logger with Engine for error catching # Do some logging. logger.debug("debug message") logger.info("info message") logger.warn("warning message") logger.error("error message") # Clean up the logger. logger.close() OS.remove_logger(logger) # Unregister logger from engine .. rst-class:: classref-reftable-group Properties ---------- .. table:: :widths: auto +-------------------------------------------+-------------------------------------------------------------------------------+-------------------------------------------------------------------------------------+ | ``Color`` | :ref:`color_debug` | ``Color(0.74509805, 0.74509805, 0.74509805, 1)`` | +-------------------------------------------+-------------------------------------------------------------------------------+-------------------------------------------------------------------------------------+ | ``Color`` | :ref:`color_info` | ``Color(1, 1, 1, 1)`` | +-------------------------------------------+-------------------------------------------------------------------------------+-------------------------------------------------------------------------------------+ | ``Color`` | :ref:`color_warn` | ``Color(1, 0.64705884, 0, 1)`` | +-------------------------------------------+-------------------------------------------------------------------------------+-------------------------------------------------------------------------------------+ | ``Color`` | :ref:`color_error` | ``Color(1, 0, 0, 1)`` | +-------------------------------------------+-------------------------------------------------------------------------------+-------------------------------------------------------------------------------------+ | ``String`` | :ref:`error_string` | ``"{file}@{line} (type {error_type}) -> {function}: {code}{rationale}{backtrace}"`` | +-------------------------------------------+-------------------------------------------------------------------------------+-------------------------------------------------------------------------------------+ | ``bool`` | :ref:`error_backtraces` | ``true`` | +-------------------------------------------+-------------------------------------------------------------------------------+-------------------------------------------------------------------------------------+ | :ref:`LogLevel` | :ref:`log_level_buffer` | ``0`` | +-------------------------------------------+-------------------------------------------------------------------------------+-------------------------------------------------------------------------------------+ | :ref:`LogLevel` | :ref:`log_level_console` | ``0`` | +-------------------------------------------+-------------------------------------------------------------------------------+-------------------------------------------------------------------------------------+ | ``FileAccess`` | :ref:`buffer` | | +-------------------------------------------+-------------------------------------------------------------------------------+-------------------------------------------------------------------------------------+ | ``int`` | :ref:`flush_interval` | ``50`` | +-------------------------------------------+-------------------------------------------------------------------------------+-------------------------------------------------------------------------------------+ | ``bool`` | :ref:`flush_after_error` | ``true`` | +-------------------------------------------+-------------------------------------------------------------------------------+-------------------------------------------------------------------------------------+ | ``int`` | :ref:`_messages_until_flush` | ``0`` | +-------------------------------------------+-------------------------------------------------------------------------------+-------------------------------------------------------------------------------------+ .. rst-class:: classref-reftable-group Methods ------- .. table:: :widths: auto +--------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`_log_error`\ (\ function\: ``String``, file\: ``String``, line\: ``int``, code\: ``String``, rationale\: ``String``, editor_notify\: ``bool``, error_type\: ``int``, script_backtraces\: :ref:`Array`\[``ScriptBacktrace``\]\ ) | +--------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`_log_message`\ (\ message\: ``String``, is_error\: ``bool``\ ) | +--------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`debug`\ (\ message\: ``String``\ ) | +--------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`info`\ (\ message\: ``String``\ ) | +--------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`warn`\ (\ message\: ``String``, use_push\: ``bool`` = false\ ) | +--------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`error`\ (\ message\: ``String``, use_push\: ``bool`` = false\ ) | +--------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`_write_console`\ (\ message\: ``String``, color\: ``Color``\ ) | +--------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`_write_buffer`\ (\ message\: ``String``, is_error\: ``bool`` = false\ ) | +--------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Error | :ref:`create_buffer`\ (\ keep\: ``bool`` = false, prefix\: ``String`` = "log"\ ) | +--------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`set_buffer`\ (\ new_buffer\: ``FileAccess``\ ) | +--------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`flush`\ (\ ) | +--------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`close`\ (\ ) | +--------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ .. rst-class:: classref-section-separator ---- .. rst-class:: classref-descriptions-group Signals ------- .. _class_StagLogger_signal_event_warning: .. rst-class:: classref-signal **event_warning**\ (\ message\: ``String``\ ) :ref:`🔗` Emitted when Godot Engine passes a warning. .. rst-class:: classref-item-separator ---- .. _class_StagLogger_signal_event_error: .. rst-class:: classref-signal **event_error**\ (\ message\: ``String``\ ) :ref:`🔗` Emitted when Godot Engine passes an error. .. rst-class:: classref-item-separator ---- .. _class_StagLogger_signal_event_error_script: .. rst-class:: classref-signal **event_error_script**\ (\ message\: ``String``\ ) :ref:`🔗` Emitted when Godot Engine passes a script error. .. rst-class:: classref-item-separator ---- .. _class_StagLogger_signal_event_error_shader: .. rst-class:: classref-signal **event_error_shader**\ (\ message\: ``String``\ ) :ref:`🔗` Emitted when Godot Engine passes a shader error. .. rst-class:: classref-section-separator ---- .. rst-class:: classref-descriptions-group Enumerations ------------ .. _enum_StagLogger_LogLevel: .. rst-class:: classref-enumeration enum **LogLevel**: :ref:`🔗` .. _class_StagLogger_constant_LLDebug: .. rst-class:: classref-enumeration-constant :ref:`LogLevel` **LLDebug** = ``0`` Show all messages. .. _class_StagLogger_constant_LLInfo: .. rst-class:: classref-enumeration-constant :ref:`LogLevel` **LLInfo** = ``1`` Show informational messages, warnings, and errors. .. _class_StagLogger_constant_LLWarn: .. rst-class:: classref-enumeration-constant :ref:`LogLevel` **LLWarn** = ``2`` Only show warnings and errors. .. _class_StagLogger_constant_LLError: .. rst-class:: classref-enumeration-constant :ref:`LogLevel` **LLError** = ``3`` Only show errors. .. rst-class:: classref-section-separator ---- .. rst-class:: classref-descriptions-group Property Descriptions --------------------- .. _class_StagLogger_property_color_debug: .. rst-class:: classref-property ``Color`` **color_debug** = ``Color(0.74509805, 0.74509805, 0.74509805, 1)`` :ref:`🔗` Console coloration for debug logs. .. rst-class:: classref-item-separator ---- .. _class_StagLogger_property_color_info: .. rst-class:: classref-property ``Color`` **color_info** = ``Color(1, 1, 1, 1)`` :ref:`🔗` Console coloration for information logs. .. rst-class:: classref-item-separator ---- .. _class_StagLogger_property_color_warn: .. rst-class:: classref-property ``Color`` **color_warn** = ``Color(1, 0.64705884, 0, 1)`` :ref:`🔗` Console coloration for warning logs. .. rst-class:: classref-item-separator ---- .. _class_StagLogger_property_color_error: .. rst-class:: classref-property ``Color`` **color_error** = ``Color(1, 0, 0, 1)`` :ref:`🔗` Console coloration for error logs. .. rst-class:: classref-item-separator ---- .. _class_StagLogger_property_error_string: .. rst-class:: classref-property ``String`` **error_string** = ``"{file}@{line} (type {error_type}) -> {function}: {code}{rationale}{backtrace}"`` :ref:`🔗` Error string for automatic error logging (i.e. script or shader errors). .. rst-class:: classref-item-separator ---- .. _class_StagLogger_property_error_backtraces: .. rst-class:: classref-property ``bool`` **error_backtraces** = ``true`` :ref:`🔗` Whether to include backtraces in automatic error logs. .. rst-class:: classref-item-separator ---- .. _class_StagLogger_property_log_level_buffer: .. rst-class:: classref-property :ref:`LogLevel` **log_level_buffer** = ``0`` :ref:`🔗` What logs are actually written to the buffer. .. rst-class:: classref-item-separator ---- .. _class_StagLogger_property_log_level_console: .. rst-class:: classref-property :ref:`LogLevel` **log_level_console** = ``0`` :ref:`🔗` What logs are actually written to the console. .. rst-class:: classref-item-separator ---- .. _class_StagLogger_property_buffer: .. rst-class:: classref-property ``FileAccess`` **buffer** :ref:`🔗` Temporary log file where buffer writes are written to. I would do this as a memory file, but it's `not yet implemented `__. .. rst-class:: classref-item-separator ---- .. _class_StagLogger_property_flush_interval: .. rst-class:: classref-property ``int`` **flush_interval** = ``50`` :ref:`🔗` How many messages can be passed before a flush occurs automatically. Flushes write buffer data to the logfile, which can be expensive if done frequently. However, if data is not flushed, it may be missing from the file if the engine crashes. In normal conditions, the file should be flushed automatically when dereferencing the logger, or if you call :ref:`close()`. .. rst-class:: classref-item-separator ---- .. _class_StagLogger_property_flush_after_error: .. rst-class:: classref-property ``bool`` **flush_after_error** = ``true`` :ref:`🔗` Immediately flush after writing an error, regardless of how many lines were written. .. rst-class:: classref-item-separator ---- .. _class_StagLogger_property__messages_until_flush: .. rst-class:: classref-property ``int`` **_messages_until_flush** = ``0`` :ref:`🔗` .. container:: contribute There is currently no description for this property. Please help us by `contributing one `__! .. rst-class:: classref-section-separator ---- .. rst-class:: classref-descriptions-group Method Descriptions ------------------- .. _class_StagLogger_private_method__log_error: .. rst-class:: classref-method |void| **_log_error**\ (\ function\: ``String``, file\: ``String``, line\: ``int``, code\: ``String``, rationale\: ``String``, editor_notify\: ``bool``, error_type\: ``int``, script_backtraces\: :ref:`Array`\[``ScriptBacktrace``\]\ ) :ref:`🔗` .. container:: contribute There is currently no description for this method. Please help us by `contributing one `__! .. rst-class:: classref-item-separator ---- .. _class_StagLogger_private_method__log_message: .. rst-class:: classref-method |void| **_log_message**\ (\ message\: ``String``, is_error\: ``bool``\ ) :ref:`🔗` .. container:: contribute There is currently no description for this method. Please help us by `contributing one `__! .. rst-class:: classref-item-separator ---- .. _class_StagLogger_method_debug: .. rst-class:: classref-method |void| **debug**\ (\ message\: ``String``\ ) :ref:`🔗` Logs a message with the "debug" log level. .. rst-class:: classref-item-separator ---- .. _class_StagLogger_method_info: .. rst-class:: classref-method |void| **info**\ (\ message\: ``String``\ ) :ref:`🔗` Logs a message with the "info" log level. .. rst-class:: classref-item-separator ---- .. _class_StagLogger_method_warn: .. rst-class:: classref-method |void| **warn**\ (\ message\: ``String``, use_push\: ``bool`` = false\ ) :ref:`🔗` Logs a message with the "warn" log level. If ``use_push`` is true, it will use :ref:`@GlobalScope.push_warning()` instead. This will be logged to the buffer with a stacktrace if the logger is registered with the Engine. .. rst-class:: classref-item-separator ---- .. _class_StagLogger_method_error: .. rst-class:: classref-method |void| **error**\ (\ message\: ``String``, use_push\: ``bool`` = false\ ) :ref:`🔗` Logs a message with the "error" log level. If ``use_push`` is true, it will use :ref:`@GlobalScope.push_error()` instead. This will be logged to the buffer with a stacktrace if the logger is registered with the Engine. .. rst-class:: classref-item-separator ---- .. _class_StagLogger_private_method__write_console: .. rst-class:: classref-method |void| **_write_console**\ (\ message\: ``String``, color\: ``Color``\ ) :ref:`🔗` .. container:: contribute There is currently no description for this method. Please help us by `contributing one `__! .. rst-class:: classref-item-separator ---- .. _class_StagLogger_private_method__write_buffer: .. rst-class:: classref-method |void| **_write_buffer**\ (\ message\: ``String``, is_error\: ``bool`` = false\ ) :ref:`🔗` .. container:: contribute There is currently no description for this method. Please help us by `contributing one `__! .. rst-class:: classref-item-separator ---- .. _class_StagLogger_method_create_buffer: .. rst-class:: classref-method Error **create_buffer**\ (\ keep\: ``bool`` = false, prefix\: ``String`` = "log"\ ) :ref:`🔗` Initializes a temporary file for writing to. Closes the existing buffer if there is one. You can choose to provide your own file with :ref:`set_buffer()`. \ ``keep`` sets whether cause the file persists in your temp directory after closing. ``prefix`` sets the prefix of the file for organizational purposes. Returns ``OK`` if the buffer was successfully opened, or a filesystem Error otherwise. .. rst-class:: classref-item-separator ---- .. _class_StagLogger_method_set_buffer: .. rst-class:: classref-method |void| **set_buffer**\ (\ new_buffer\: ``FileAccess``\ ) :ref:`🔗` Sets the file for writing to. Closes the existing buffer if there is one. .. rst-class:: classref-item-separator ---- .. _class_StagLogger_method_flush: .. rst-class:: classref-method |void| **flush**\ (\ ) :ref:`🔗` Flushes the buffer, writing directly to the logfile. .. rst-class:: classref-item-separator ---- .. _class_StagLogger_method_close: .. rst-class:: classref-method |void| **close**\ (\ ) :ref:`🔗` Flushes and closes the logfile. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)` .. |required| replace:: :abbr:`required (This method is required to be overridden when extending its base class.)` .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)` .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)` .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)` .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)` .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)` .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)` .. |void| replace:: :abbr:`void (No return value.)`