LiteLogger
A lightweight logging utility for Dart & Flutter with colored output, log filtering, and custom formatting.
Installation
dart pub add lite_logger
Features
- Log level filtering (
error,warning,success,info,step,debug) - ANSI colors and emoji indicators
- Lazy message evaluation
- Custom format templates
- Callback support (file, cloud, analytics)
- Global enable/disable switch
Getting Started
final logger = LiteLogger(
name: 'MyApp',
minLevel: LogLevel.debug,
);
logger.info('Application started');
logger.step('Loading configuration...');
logger.debug(() => 'Debug timestamp: ${DateTime.now().millisecondsSinceEpoch}');
logger.success('Configuration loaded');
logger.warning('Low disk space');
logger.error('Unable to access database');
Advanced Configuration
final logger = LiteLogger(
name: 'MyService',
minLevel: LogLevel.debug,
timestamp: (dt) => '[${dt.toIso8601String()}]',
format: '@{color}@{timestamp} @{icon} [@{level}] @{message}',
// output: LogOutput.auto (default) | LogOutput.print | LogOutput.developerLog
callback: (raw, colored, level) {
// Save logs to file or send to a remote endpoint
},
);
Format Tokens
| Token | Description |
|---|---|
@{color} |
ANSI color escape |
@{timestamp} |
Formatted timestamp |
@{icon} |
Emoji per LogLevel |
@{level} |
Short log label |
@{message} |
Content of the log |
Log Filtering
const logger = LiteLogger(minLevel: LogLevel.warning);
logger.log('This is info', LogLevel.info); // skipped
logger.log('This is warning', LogLevel.warning); // logged
logger.log('This is error', LogLevel.error); // logged
Callback
const logger = LiteLogger(
callback: (raw, colored, level) {
sendToServer({'level': level.name, 'message': raw});
},
);
Logger Naming
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');
Output:
[API] [12:34:56] 💡 [INFO] Fetching user data
[Database] [12:34:56] 🧠 [DBUG] Executing query...
[Auth] [12:34:57] ⚠️ [WARN] Token expiring soon
Output Methods
The output parameter (LogOutput) selects the output method:
LogOutput.auto(default):developer.log()in debug (keeps ANSI colors),print()in release. Needs a debugger/DevTools attached; for plaindart runterminals useLogOutput.print.LogOutput.print: Alwaysprint(). Most compatible; on Flutter mobile ANSI colors are stripped becauselogcatescapes them.LogOutput.developerLog: Alwaysdeveloper.log().
final logger1 = LiteLogger(name: 'App');
final logger2 = LiteLogger(name: 'App', output: LogOutput.print);
final logger3 = LiteLogger(name: 'App', output: LogOutput.developerLog);
usePrintis deprecated in favor ofoutputbut still works:truemaps toLogOutput.print,falsetoLogOutput.developerLog. An explicitusePrinttakes precedence overoutput.
License
MIT License — see LICENSE.