logging_colorful 1.3.0
logging_colorful: ^1.3.0 copied to clipboard
Logging package with colors, no external dependencies.
example/logging_colorful_example.dart
import 'dart:io';
import 'package:logging_colorful/logging_colorful.dart';
void main() {
// Define your Logger configuration
Logger.root.level = Level.ALL;
Logger.root.onRecord.listen((record) {
final (:String error, :String trace) = record.stringifyErrorAndTrace();
print(
'${record.loggerName} - ${record.level.name}: ${record.message} | error: $error | trace: $trace');
});
// Example of using sanitize method for TSV (Tab-Separated Values) output
final tsvLogger = LoggerColorful('TSVLogger');
Logger('TSVLogger').onRecord.listen((record) {
final sanitizedMessage = tsvLogger.sanitize(record.message.toString());
final tsvLine =
'${record.time}\t${record.level.name}\t${record.loggerName}\t$sanitizedMessage';
print('TSV: $tsvLine');
});
// Initialize a LoggerColorful that will make your logger colorized
// You can disable colors
// May be useful for iOS users, since iOS doesn't render ANSI Colors (escaped)
final log = LoggerColorful('MyLogger', disabledColors: Platform.isIOS);
log.shout('shout');
log.severe('severe');
log.warning('warning');
log.info('info');
log.config('config');
log.fine('fine');
log.finer('finer');
log.finest(
'finest', Error.safeToString('error'), StackTrace.fromString('trace'));
// Demonstrate TSV logger with colorful messages that get sanitized
tsvLogger.info('This message has\ttabs and\nnewlines');
tsvLogger.warning('Colorful message that will be cleaned for TSV');
// Change the Color for a Level
log.colorLevel[Level.FINEST] = AnsiColor.rainbow;
log.finest('finest with rainbow of color');
}