Skip to main content

belatuk_pretty_logging 7.0.0 copy "belatuk_pretty_logging: ^7.0.0" to clipboard
belatuk_pretty_logging: ^7.0.0 copied to clipboard

Standalone helper for colorful logging output, using pkg:io AnsiCode.

Belatuk Pretty Logging #

Pub Version (including pre-releases) Null Safety Gitter License

Standalone helper for colorful logging output, using pkg:io AnsiCode.

Installation #

In your pubspec.yaml:

dependencies:
  belatuk_pretty_logging: ^7.0.0

Usage #

Basic usage is very simple:

myLogger.onRecord.listen(prettyLog);

However, you can conditionally pass logic to omit printing an error, provide colors, or to provide a custom print function:

import 'dart:io';

import 'package:angel3_framework/angel3_framework.dart';
import 'package:belatuk_pretty_logging/belatuk_pretty_logging.dart';
import 'package:io/ansi.dart';
import 'package:logging/logging.dart';

bool isClientError(LogRecord r) {
  var err = r.error;
  return err is AngelHttpException && err.statusCode != 500;
}

void main() {
  var myLogger = Logger('my_app');
  myLogger.onRecord.listen(
    (record) => prettyLog(
      record,
      logColorChooser: (_) => red,
      printFunction: stderr.writeln,
      omitError: isClientError,
      omitStackTrace: isClientError,
    ),
  );
}

omitError hides a record's error and omitStackTrace hides its stack trace; pass both to hide both. Each is only asked when the record has something for it to hide, and the record's message is always printed. A stack trace on a record without an error, added when package:logging's top-level recordStackTraceAtLevel is set, is printed too, so omitStackTrace can hide those in this listener only.

To print only each record's message, hiding every error and stack trace, return true from both:

void quietLog(LogRecord record) =>
    prettyLog(record, omitError: (_) => true, omitStackTrace: (_) => true);

myLogger.onRecord.listen(quietLog);

To drop whole records, such as routine 404s, filter them out before they reach prettyLog:

myLogger.onRecord
    .where((r) {
      var err = r.error;
      return !(err is AngelHttpException && err.statusCode != 500);
    })
    .listen(prettyLog);
0
likes
160
points
529
downloads

Documentation

API reference

Publisher

verified publisherdukefirehawk.com

Weekly Downloads

Standalone helper for colorful logging output, using pkg:io AnsiCode.

Repository (GitHub)
View/report issues

License

BSD-3-Clause (license)

Dependencies

io, logging

More

Packages that depend on belatuk_pretty_logging