lite_logger 0.1.2
lite_logger: ^0.1.2 copied to clipboard
A fast, lightweight, and customizable logging utility for Dart & Flutter — with colored output, emoji icons, log filtering, and powerful formatting.
example/lite_logger_example.dart
import 'package:lite_logger/lite_logger.dart';
void main() {
print('=== Basic Usage ===');
const LiteLogger(
name: 'App',
minLevel: LogLevel.debug,
)
..info('Application started')
..step('Loading configuration...')
..debug(() => 'Debug timestamp: ${DateTime.now().millisecondsSinceEpoch}')
..success('Configuration loaded')
..warning('Low disk space')
..error('Unable to access database');
print('\n=== Multiple Named Loggers ===');
final apiLogger = LiteLogger(name: 'API');
final dbLogger = LiteLogger(name: 'Database');
final authLogger = LiteLogger(name: 'Auth');
apiLogger.info('Fetching user data');
dbLogger.debug('Executing query...');
authLogger.warning('Token expiring soon');
print('\n=== Using Callback ===');
LiteLogger(
name: 'Service',
minLevel: LogLevel.debug,
callback: (raw, colored, level) {
// Example: You could send to a file or remote service here
// ignore: avoid_print
print('Callback - Raw: $raw, Level: ${level.name}');
},
)
..info('Application started')
..step('Loading configuration...')
..debug(() => 'Debug timestamp: ${DateTime.now().millisecondsSinceEpoch}')
..success('Configuration loaded')
..warning('Low disk space')
..error('Unable to access database');
print('\n=== Using developer.log() instead of print() ===');
LiteLogger(
name: 'DevLogger',
usePrint: false, // Use developer.log() for cleaner output
minLevel: LogLevel.debug,
)
..info('This uses developer.log()')
..warning('Less platform noise')
..error('Better for development tools');
print('\n=== Custom Format with Named Logger ===');
LiteLogger(
name: 'Custom',
format: '@{icon} @{level}: @{message}',
)
..info('Custom format example')
..success('With logger name prefix');
print('\n=== Lazy Evaluation Example ===');
final logger = LiteLogger(name: 'Lazy');
var expensiveCallCount = 0;
logger.debug(() {
expensiveCallCount++;
// This function is only called if debug level is enabled
return 'Expensive computation result: ${DateTime.now().millisecondsSinceEpoch}';
});
// ignore: avoid_print
print('Expensive function was called $expensiveCallCount time(s)');
// With minLevel above debug, the function won't be called
const LiteLogger(minLevel: LogLevel.warning).debug(() {
// This will never execute
return 'This is expensive and will not run';
});
}