Skip to content

ClassLogger

It's a Logger with the class already supplied.

Description

This is a ClassLogger that logs with a standardised prefix in the form of:

[hh:mm:ss] [LEVEL] [Mod Name] [ModClass:<optional line number>]: message
A ClassLogger already has 'ModClass' supplied through being created using for_class. It's also possible to provide a unique prefix formatter using set_formatter or with_formatter

Methods

void debug ( int line, String message, Array args )
void error ( int line, String message, Array args )
void fatal ( int line, String message, Array args )
ClassLogger for_class ( clazz )
void info ( int line, String message, Array args )
void set_formatter ( FuncRef prefix_formatter = PREFIX_FORMATTER )
void warn ( int line, String message, Array args )
ClassLogger with_formatter ( FuncRef prefix_formatter = PREFIX_FORMATTER )

Enumerations

enum LogLevel:

  • OFF = 0
  • FATAL = 1
  • ERROR = 2
  • WARN = 3
  • INFO = 4
  • DEBUG = 5
Denotes the log level.

Constants

FuncRef MILLIS_PREFIX_FORMATTER funcref(self, "build_prefix_millis")
FuncRef PREFIX_FORMATTER funcref(self, "build_prefix")

Method Descriptions

ClassLogger for_class ( clazz ):
Creates a ClassLogger which pre-supplies the clazz for the logging methods. clazz may be either a String containing the class name or a relevant instance of the class/ the GDScript itself with a CLASS_NAME constant providing the name as a String.

void debug ( int line, String message, Array args ):
Logs a message at debug level. line denotes the line number and args is the parameters the message will be formatted with. line and args may each be omitted.

void info ( int line, String message, Array args ):
Logs a message at info level. line denotes the line number and args is the parameters the message will be formatted with. line and args may each be omitted.

void warn ( int line, String message, Array args ):
Logs a message at warn level. line denotes the line number and args is the parameters the message will be formatted with. line and args may each be omitted.

void error ( int line, String message, Array args ):
Logs a message at error level. line denotes the line number and args is the parameters the message will be formatted with. line and args may each be omitted.

void fatal ( int line, String message, Array args ):
Logs a message at fatal level. line denotes the line number and args is the parameters the message will be formatted with. line and args may each be omitted.

void set_formatter ( FuncRef prefix_formatter = PREFIX_FORMATTER ):
Sets prefix_formatter as this loggers prefix formatter. The prefix formatter is a FuncRef to any method with signature:

func format_prefix(level: int, mod_name: String, clazz = null, line: int = -1)
Should clazz or line be equal to their default value, then this signifies that they are missing, so they should be omitted when formatting the log prefix.

ClassLogger with_formatter ( FuncRef prefix_formatter = PREFIX_FORMATTER ):
Creates and returns a new ClassLogger with prefix_formatter as the loggers prefix formatter. The prefix formatter is a FuncRef to any method with signature:

func format_prefix(level: int, mod_name: String, clazz = null, line: int = -1)
Should clazz or line be equal to their default value, then this signifies that they are missing, so they should be omitted when formatting the log prefix.