Logger class
The main logger class. Provides methods for logging messages of different levels.
one_logger
is a simple yet powerful logging package that outputs logs in
a single line format [date level module msg]
. With ANSI support, it enhances
the readability of logs in your console.
Features
- Single line logging: Each log is output in a single line, with a timestamp, log level, module, and message.
- ANSI support: Logs are colored based on their log level, making them easier to distinguish in the console.
- Customizable: Various options allow you to customize the logging behavior to suit your needs.
- Loki Support: Push logs to Loki.
Constructors
- Logger({String? service, String? defaultModule, LokiOptions? lokiOptions, LoggerOptions options = defaultLevelOptions, LoggerFilter? filter, dynamic onLog(OnLogParams)?, PrinterFn printerFn = defaultLoggerPrinter})
-
Creates a new Logger instance.
const
Properties
- defaultModule → String?
-
The default module name for the logger.
final
- filter → LoggerFilter?
-
A filter that determines whether a log of a particular level should be printed or pushed.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- lokiEnabled → bool
-
Checks if Loki is enabled for the logger.
no setter
- lokiOptions → LokiOptions?
-
Configuration options for Loki.
final
- onLog → dynamic Function(OnLogParams)?
-
A callback function that is called when a log message is created.
final
- options → LoggerOptions
-
Options for configuring the logger, including styles for each log level and whether to enable ANSI.
final
- printerFn → PrinterFn
-
A function to print the log messages.
final
-
props
→ List<
Object?> -
The list of properties that will be used to determine whether
two instances are equal.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- service → String?
-
The name of the service using the logger.
final
- stringify → bool?
-
If set to
true
, the toString method will be overridden to output this instance's props.no setter
Methods
-
copyWith(
{String? service, String? defaultModule, LoggerOptions? options, LokiOptions? lokiOptions, LoggerFilter? filter}) → Logger - Creates a copy of the current logger with the given parameters.
-
debug(
dynamic msg, {String? module, LokiLabel? labels}) → void - Logs a debug message.
-
disposeLoki(
) → void - Disposes Loki by sending an 'exit' message.
-
error(
dynamic msg, {StackTrace? stackTrace, String? module, LokiLabel? labels}) → void - Logs an error message.
-
info(
dynamic msg, {String? module, LokiLabel? labels}) → void - Logs an info message.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
startLoki(
) → Future< void> - Starts Loki for pushing logs.
-
toString(
) → String -
A string representation of this object.
inherited
-
trace(
dynamic msg, {String? module, LokiLabel? labels}) → void - Logs a trace message.
-
warn(
dynamic msg, {String? module, LokiLabel? labels}) → void - Logs a warning message.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited