simplest_logger 0.0.3
simplest_logger: ^0.0.3 copied to clipboard
A lightweight, opinionated, colorful logging utility for Dart applications. Minimal configuration necessary.
simplest_logger #
A lightweight, opinionated, colorful logging utility for Dart applications that provides an easy-to-use interface for console logging with minimal configuration.
- Colored console output (info: green, warning: yellow, debug: blue, error: red)
- Automatic timestamps for all log messages
- Automatic class name labeling
- Simple mixin for quick integration
- Runtime-configurable logging levels (both globally and per-instance)
- Global configuration support
- Zero dependencies
Usage #
The most basic usage is to use the SimplestLogger
class directly:
final logger = SimplestLogger('MyClass', LogLevel.all);
logger.info('Application started'); // Green output
logger.warning('Cache miss'); // Yellow output
logger.debug('Processing request'); // Blue output
logger.error('Connection failed'); // Red output
For a more integrated approach, you can use the SimplestLoggerMixin
mixin:
class MyService with SimplestLoggerMixin {
void doSomething() {
logger.info('Operation started');
}
}
Controlling log levels #
You have three ways to control logging behavior:
- Globally using
SimplestLoggerConfig
:
// Turn off all logging across the app
SimplestLoggerConfig.globalLogLevel = LogLevel.off;
// Make loggers ignore global settings (use their individual settings)
SimplestLoggerConfig.respectGlobalLogLevel = false;
- Per instance when creating a
SimplestLogger
:
final logger = SimplestLogger('MyClass', LogLevel.off);
- Per mixin by setting the
logLevel
property:
class ProductionService with SimplestLoggerMixin {
ProductionService() {
// Disable logging for this service
logLevel = LogLevel.off;
}
}
By default:
- Global logging is enabled (
LogLevel.all
) - Global settings are respected (
respectGlobalLogLevel = true
) - Individual loggers can override the global setting if
respectGlobalLogLevel
is set tofalse
License #
This project is licensed under the MIT License - see the LICENSE file for details.