logger 0.3.1

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 40

Linux build Code coverage Docs reference

Logger is an efficient structured logger for Dart.

Installation #

The process of installation is very common and only requires pub to be installed on the machine.

$ pub get logger

Make sure you are running on Dart 2.0 or greater, as logger is currently limits support only to this platform.

Quick Start #

Once package is installed on the machine you are ready to getting started, here is a quick example you can use:

import "dart:async" show Future;

import "package:logger/logger.dart" show Logger;
import "package:logger/handlers.dart" show ConsoleHandler;

void main() async {
  final logger = Logger.getLogger("example.console")
    ..addHandler(ConsoleHandler());

  final context = (logger.bind()
        ..string("username", "vanesyan")
        ..string("type", "image/png")
        ..string("image", "avatar.png"))
      .build();

  final tracer = context.trace("uploading!");

  await Future<void>.delayed(const Duration(milliseconds: 1000));

  tracer.stop("uploaded!");
}

The logger package comes with a bunch of log records handlers that are available at the handlers package entry; e.g. ConsoleHandler, FileHandler, etc.

By the way the logger package also exposes a default_logger entry which provides a top-level logger used to quick start.

import "dart:async" show Future;

import "package:logger/default_logger.dart" as log;
import "package:logger/handlers.dart" show ConsoleHandler;

void main() {
  log.addHandler(ConsoleHandler());

  log.info("Hello world!");
}

Logger provided by the default_logger package entry shares the same API as the Logger available from logger package entry, with exception that the former cannot be closed.

You can find out more about API by following the link.

License #

The source code is released under the terms of MIT license.

CHANGELOG.md #

0.1.0 #

  • Initial release

example/logger.dart

import "dart:async" show Future;

import "package:logger/logger.dart" show Handler, Logger, Record;

class PrintHandler extends Handler {
  @override
  void call(Record record) {
    final result = StringBuffer();
    final fields = StringBuffer();

    for (final field in record.fields) {
      fields.write(" ${field.key}=${field.value}");
    }

    result
      ..write("${record.name} ")
      ..write("${record.time}  ")
      ..write("${record.level.toString().toUpperCase()} ")
      ..write("${record.message}")
      ..write("$fields");

    print(result.toString());
  }
}

void main() async {
  final logger = Logger.getLogger("example.print_handler")
    ..addHandler(PrintHandler());

  final context = (logger.bind()
    ..string("username", "vanesyan")
    ..string("type", "image/png")
    ..string("image", "avatar.png"))
      .build();

  final tracer = context.trace("uploading!");

  await Future<void>.delayed(const Duration(milliseconds: 1000));

  tracer.stop("uploaded!");
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  logger: ^0.3.1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:logger/logger.dart';
  
Version Uploaded Documentation Archive
0.3.1 Oct 31, 2018 Go to the documentation of logger 0.3.1 Download logger 0.3.1 archive
0.3.0 Oct 31, 2018 Go to the documentation of logger 0.3.0 Download logger 0.3.0 archive
0.2.0 Jul 6, 2018 Go to the documentation of logger 0.2.0 Download logger 0.2.0 archive
0.1.0 Jan 29, 2018 Go to the documentation of logger 0.1.0 Download logger 0.1.0 archive
0.1.0-alpha.1 Jan 22, 2018 Go to the documentation of logger 0.1.0-alpha.1 Download logger 0.1.0-alpha.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
80
Health:
Code health derived from static analysis. [more]
--
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
--
Overall:
Weighted score of the above. [more]
40
Learn more about scoring.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Analysis issues and suggestions

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see https://www.dartlang.org/dart-2#migration.

Maintenance issues and suggestions

Make sure dartdoc successfully runs on your package's source files. (-10 points)

Dependencies were not resolved.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <=3.0.0