talker_logger

Talker - Advanced exception handling and logging for dart/flutter applications 🚀

Core talker package
The package is designed to to make simple and extended logs
Can be used separately from the main parent package
In order to use all the functionality - go to the main page

codecov Pub Pub License: MIT talker talker_flutter talker_logger

Get Started

Follow these steps to use this package

Add dependency

dependencies:
  talker_logger: ^2.1.0

Easy to use

Create TalkerLogger instance and call prepared methods

// Create instance
final logger = TalkerLogger();
// Log messages
logger.debug('debug');
logger.info('info');
logger.critical('critical');
logger.error('error');
logger.fine('fine');
logger.good('good');
logger.warning('warning');
logger.verbose('verbose');
logger.log('log with level info', level: LogLevel.info);
logger.log('custom pen log', pen: AnsiPen()..xterm(49));

Result

More examples you can get there or in docs

Customization

This logger has simple settings that can change output

1. Filtering

  final logger = TalkerLogger(
    settings: const TalkerLoggerSettings(
      // Set current logging level
      level: LogLevel.critical,
    ),
  );

  // Works as before
  logger.critical('critical');
  // Does not work
  logger.info('info');

Result

2. Formating

Create your own LoggerFormatter implementation For example - ColoredLoggerFormatter that makes messages only with colors

class ColoredLoggerFormatter implements LoggerFormatter {
  @override
  String fmt(LogDetails details, TalkerLoggerSettings settings) {
    final msg = details.message?.toString() ?? '';
    final coloredMsg =
        msg.split('\n').map((e) => details.pen.write(e)).toList().join('\n');
    return coloredMsg;
  }
}

And add formatter for TalkerLogger constructor

  final logger = TalkerLogger(
    formatter: ColoredLoggerFormatter(),
  );

  logger.debug('debug');
  logger.info('info');
  logger.warning('warning');
  logger.error('error');

Result

Or you can make simple customization with default formatters

  final logger = TalkerLogger(
    settings: TalkerLoggerSettings(
      colors: {
        LogLevel.critical: AnsiPen()..yellow(),
        LogLevel.error: AnsiPen()..yellow(),
        LogLevel.info: AnsiPen()..yellow(),
        LogLevel.fine: AnsiPen()..yellow(),
      },
      maxLineWidth: 20,
      lineSymbol: '#',
      enableColors: true,
    ),
  );

  logger.info('info');
  logger.critical('critical');
  logger.error('error');
  logger.fine('fine');

Result

Coverage

More examples you can get here

Libraries

talker_logger