logging_appenders

v1.4.0+1

Logging appenders for the dart logging package for print, file and remote (logz, loki, graylog (gelf)).

Package archive: https://pubdev.letsnova.ru/api/archives/logging_appenders/1.4.0+1.tar.gz

Installdart pub add logging_appenders

Readme

logging_appenders

Pub codecov

Native dart package for logging appenders usable with the logging package.

Color Output Screenshot

It currently includes appenders for:

Performance of Remote Logging Appenders

I am not sure if it is wise to use this in production, but it's great during beta testing with a handful of users so you have all logs available.

It tries to stay reasonable performant by batching log entries and sending them off only every few seconds. If network is down it will retry later. (with an ever increasing interval).

Getting Started

After installing package logging and logging_appenders:

import 'package:logging/logging.dart';
                import 'package:logging_appenders/logging_appenders.dart';
                
                final _logger = Logger('main');
                
                void main() {
                  PrintAppender.setupLogging();
                
                  // The above code is the same as:
                  // Logger.root.level = Level.ALL;
                  // PrintAppender()..attachToLogger(Logger.root);
                
                  _logger.fine('Lorem ipsum');
                }
                

Outputs:

$ dart main.dart
                2019-08-19 15:36:03.827563 FINE main - Lorem ipsum
                

Support for Exception chaining

To chain exception you can use the extension method on Exception: causedBy().

int test() {
                  try {
                    int.parse('a');
                  } catch (e, stackTrace) {
                    throw Exception('unable to parse').causedBy(e, stackTrace);
                  }
                }
                int main() {
                  try {
                    test();
                  } catch (e, stackTrace) {
                    logger.severe('catched Exception', e, stackTrace);
                  }
                }
                

Color Formatter

    PrintAppender(formatter: const ColorFormatter())
                        ..attachToLogger(Logger.root);
                

Produces:

Color Output Screenshot

Logging to stderr

When using dart:io (ie. command line apps) it is possible to define which log levels should go to stderr instead of stdout:

PrintAppender.setupLogging(stderrLevel: Level.SEVERE);
                

Remote Appenders

Appender for logz.io

  final _logzIoApiSender = LogzIoApiAppender(
                    // you can find your API key and the required URL from 
                    // the logz.io dashboard: https://app-eu.logz.io/#/dashboard/settings/general
                    apiToken: 'MY API KEY',
                    url: 'https://listener-eu.logz.io:8071/',
                    labels: {'app': 'MyApp', 'os': Platform.operatingSystem},
                  );
                  _logzIoApiSender.attachToLogger(Logger.root);
                  
                  
                  // ...
                  If you know that you no longer need the appender. it's good to dispose it:
                  _logzIoApiSender.dispose();
                

Changelog

1.4.0+1

  • Don't try to use dart:isolate on web.

1.4.0

  • Allow customizing of default Log Formatter using BaseLogAppender.defaultFormatter
  • By default prefix log messages by Isolate.current.debugName
  • Export SyslogLevel

1.3.1

  • Default formatter: add support for printing cause of [JsonUnsupportedObjectError]

1.3.0

  • Support for exception chaining.
  • Allow closing of subscriptions without disposing. detachFromLoggers

1.2.0+1

  • Graylog: Send timestamp with decimal places.
  • Require at least Dio 5.2.0

1.2.0

  • Support for gelf / Graylog appender.
  • Fix concurrent modification exception (thanks @andreacimino #23)

1.1.0

  • Support logging 1.2.0 package.

1.0.2

  • Fix RotatingFileAppender on windows #15 / #18

1.0.1

  • Allow dio 5.x

1.0.0+2

  • Update dependencies.

1.0.0+1

  • AsyncInitializingLogHandler: Allow access to underlying async handler.

1.0.0

  • Support for null safety

0.4.3+1

  • Fix concurrent modification #9 thanks @rvasqz86

0.4.3

  • Remove dependency on rxdart.
  • Loki: use UTC for all timestamps (thanks @hsmade)

0.4.3-dev.1

  • Remove dependency on rxdart.

0.4.2+5

  • Improve documentation
  • Add possibility to log to stderr.
    PrintAppender.setupLogging(stderrLevel: Level.SEVERE);
                    

0.4.2+4

  • Add error runtimeType to default log output.

0.4.2+3

  • fix passing along level on PrintAppender.setupLogging

0.4.2+2

  • Slightly improve the default formatting of errors/stack traces.

0.4.2 (and 0.4.2+1)

  • Separated PrintAppender initializer into a default and a dart:io file, so to remove dependency on dart:io.
  • Created a PrintAppender.setupLogging() method which configures the root logger.

0.4.1

  • Expose BaseLogSender and similar classes required to build custom log senders.

0.4.0

  • Upgrade to dio 3.x

0.3.0

  • Upgraded to rxdart 0.23

0.2.2

  • Added a ColorFormatter when outputting to interactive terminal.
    • If stdout.supportsAnsiEscapes returns true, the PrintAppender will default to ColorFormatter
  • Correctly dispose close timer.

0.2.1+1

  • Make LogzIoApiAppender more configurable (host, type, bufferSize, etc.).
  • Make internal logging levels configurable, to help debugging the Appenders themselves.

0.2.1

  • Improved API, use attachToLogger.
  • Updated documentation, improved readme
  • More test coverage for RotatingFileAppender

[0.2.0] - 2019-08-19

  • Renamed everything from handler to appender.
  • Major refactoring.

[0.1.0+2] - 2019-04-20 hotfix

[0.1.0+1] - 2019-04-20 broaden dependencies for 0.x versions.

[0.1.0] - 2019-04-20 initial release

  • Initial release with logz.io and loki logging backends.