Mojo struct
Logger
struct Logger[level: Level = DEFAULT_LEVEL]
A logger that outputs messages at or above a specified severity level.
Parameters
- level (
Level): The minimum severity level for messages to be logged.
Implemented traits
AnyType,
Copyable,
ImplicitlyCopyable,
ImplicitlyDestructible,
Movable
comptime members
__copyinit__is_trivial
comptime __copyinit__is_trivial = False
__del__is_trivial
comptime __del__is_trivial = False
__moveinit__is_trivial
comptime __moveinit__is_trivial = False
Methods
__init__
__init__(out self, fd: FileDescriptor = stdout, *, prefix: String = "", source_location: Bool = False)
Initializes a new Logger.
Args:
- fd (
FileDescriptor): The file descriptor to write log messages to (defaults to stdout). - prefix (
String): The prefix to prepend to each log message (defaults to an empty string). - source_location (
Bool): Whether to include the source location in the log message (defaults to False).
trace
trace[*Ts: Writable](self, *values: *Ts, *, sep: StringSlice[StaticConstantOrigin] = " ", end: StringSlice[StaticConstantOrigin] = "\n", location: Optional[SourceLocation] = None)
Logs a trace message.
Parameters:
- *Ts (
Writable): The types of values to log.
Args:
- *values (
*Ts): The values to log. - sep (
StringSlice): The separator to use between values (defaults to a space). - end (
StringSlice): The string to append to the end of the message (defaults to a newline). - location (
Optional): The location of the error (defaults tocall_location).
debug
debug[*Ts: Writable](self, *values: *Ts, *, sep: StringSlice[StaticConstantOrigin] = " ", end: StringSlice[StaticConstantOrigin] = "\n", location: Optional[SourceLocation] = None)
Logs a debug message.
Parameters:
- *Ts (
Writable): The types of values to log.
Args:
- *values (
*Ts): The values to log. - sep (
StringSlice): The separator to use between values (defaults to a space). - end (
StringSlice): The string to append to the end of the message (defaults to a newline). - location (
Optional): The location of the error (defaults tocall_location).
info
info[*Ts: Writable](self, *values: *Ts, *, sep: StringSlice[StaticConstantOrigin] = " ", end: StringSlice[StaticConstantOrigin] = "\n", location: Optional[SourceLocation] = None)
Logs an info message.
Parameters:
- *Ts (
Writable): The types of values to log.
Args:
- *values (
*Ts): The values to log. - sep (
StringSlice): The separator to use between values (defaults to a space). - end (
StringSlice): The string to append to the end of the message (defaults to a newline). - location (
Optional): The location of the error (defaults tocall_location).
warning
warning[*Ts: Writable](self, *values: *Ts, *, sep: StringSlice[StaticConstantOrigin] = " ", end: StringSlice[StaticConstantOrigin] = "\n", location: Optional[SourceLocation] = None)
Logs a warning message.
Parameters:
- *Ts (
Writable): The types of values to log.
Args:
- *values (
*Ts): The values to log. - sep (
StringSlice): The separator to use between values (defaults to a space). - end (
StringSlice): The string to append to the end of the message (defaults to a newline). - location (
Optional): The location of the error (defaults tocall_location).
error
error[*Ts: Writable](self, *values: *Ts, *, sep: StringSlice[StaticConstantOrigin] = " ", end: StringSlice[StaticConstantOrigin] = "\n", location: Optional[SourceLocation] = None)
Logs an error message.
Parameters:
- *Ts (
Writable): The types of values to log.
Args:
- *values (
*Ts): The values to log. - sep (
StringSlice): The separator to use between values (defaults to a space). - end (
StringSlice): The string to append to the end of the message (defaults to a newline). - location (
Optional): The location of the error (defaults tocall_location).
critical
critical[*Ts: Writable](self, *values: *Ts, *, sep: StringSlice[StaticConstantOrigin] = " ", end: StringSlice[StaticConstantOrigin] = "\n", location: Optional[SourceLocation] = None)
Logs a critical message and aborts execution.
Parameters:
- *Ts (
Writable): The types of values to log.
Args:
- *values (
*Ts): The values to log. - sep (
StringSlice): The separator to use between values (defaults to a space). - end (
StringSlice): The string to append to the end of the message (defaults to a newline). - location (
Optional): The location of the error (defaults tocall_location).
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!