Create a new default logger instance with default log level
Creates a new logger instance with the specified scope.
The scope is a string that will be prefixed to all log messages from this Logger instance, allowing for easier identification of the source of log messages The scope can also be set or changed later using the Logger.setScope method.
Sets the scope for this Logger instance, which will be prefixed to all log messages. If an empty string is provided, no scope will be used.
This constructor cannot be used to name the scope with the same name as a log level (e.g. info, warn, error) to avoid confusion with log level configuration.
If such a name is used, it will be treated as a log level configuration instead of a scope, and the scope will default to an empty string.
Logger.setScope for details on how scope is determined and configured.
Creates a new logger instance with the specified log level.
If a string is provided, it will be processed according to the rules defined in the getLogLevel function
If a Partial<LogLevel> object is provided, it will override the corresponding log levels while keeping the others at their default values.
the log level to set for this Logger instance. This can be a string representing the desired log level or a PartialgetLogLevel function, which also considers environment variables for configuration. If a Partial
getLogLevel for details on how log levels are determined and configured.
Create a new logger instance with the specified scope and log level.
The scope is a string that will be prefixed to all log messages from this Logger instance, allowing for easier identification of the source of log messages. The scope can also be set or changed later using the Logger.setScope method.
If a string is provided, it will be processed according to the rules defined in the getLogLevel function
If a Partial<LogLevel> object is provided, it will override the corresponding log levels while keeping the others at their default values.
Scope name
The logLevel for this Logger instance
Logger.setScope for details on how scope is determined and configured.
Assert the condition and log the data if assertion fails.
If condition is true no message will be logged
Log level: errors
The condition to assert
The data to print if assertion fails
Increments the counter for the given label and logs it to the console.
Log level: info
The label for counter, default is default
The counter will not increment if log level is set to a level that does not include info (e.g. warn, error, none).
If the counter for the given label does not exist, it will be initialized to 0 before being incremented.
The log message will always automatically include the scope of the logger
Resets the counter for the given label.
Log level: info
The label for the counter, default is default
Print a debug message
Log level: verbose
The data to print
This will print a given object using console.dir
Prints JSON data of an object
Log level: info
The object to print
Optionaloptions: { colors?: boolean; depth?: boolean; showHidden?: boolean }Options to pass to console.dir
This will print a given object using console.dirxml
Print XML data of an object
Log level: info
The object to print
Print an error message
Log level: errors
The data to print
Gets the current scope for this Logger instance.
Scope name
Start a new group
Log level: info
Optionallabel: stringThe group label
Start a new collapsed group
Collapsed groups don't include indentation for their content
Log level: info
Optionallabel: stringThe group label
End the current group
Log level: info
Print an info message
Log level: info
The data to be printed
Log a message
Log level: info
The data to be printed
ExperimentalStart profiling with a given label
You can end profiling using the Logger.profileEnd method
Log level: info
The label for profiling, default is default
ExperimentalEnd profiling with a given label and log the duration
You can start profiling using the Logger.profile method
Log level: info
The label for profiling, default is default
The label will always automatically include the scope of the logger
The profile will not end if log level is set to a level that does not include info (e.g. warn, error, none).
If no active profile with the given label is found, a warning message will be logged instead
This method uses performance.now() and not console.profileEnd as the latter isn't currently implemented.
Sets the log level for this Logger instance
The log level to set
getLogLevel for details on how log levels are determined and configured.
Sets the scope for this Logger instance, which will be prefixed to all log messages.
If an empty string is provided, no scope will be used.
Scope name
Print a table to the console
Log level: info
The data for table
Optionalcolumns: string[]The columns to include in the table, if not provided all columns will be included
Print a table to the console
Log level: info
The data to be printed
Start a timer with the given label
The timer can be ended using the Logger.timeEnd method. The Logger.timeLog method can be used to log the current duration without ending the timer.
Log level: info
Label for measuring time, default is default
End a timer with the given label
If there is no active timer with the given label, this method will have no effect. The timer can be started using the Logger.time method, and the current duration can be logged without ending the timer using the Logger.timeLog method.
Log level: info
The label for measuring time, default is default
Log current duration of a timer with the given label without ending the timer
If there is no active timer with the given label, this method will have no effect. The timer can be started using the Logger.time method, and it can be ended using the Logger.timeEnd method.
Log level: info
The label for measuring time, default is default
Print a warning message
Log level: warnings
The data to be printed
A custom Logger class that provides enhanced logging capabilities with log levels, scoping, and formatting.
It wraps around the native console methods and adds features like colored output, timestamps, and grouping. The log level can be configured globally or per instance, allowing for flexible logging based on the environment or specific needs.
See
getLogLevel for details on how log levels are determined and configured.
Example usage: