logger 0.3.1

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

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

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages 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]
65
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
83
Learn more about scoring.

We analyzed this package on Dec 5, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.1.0
  • pana: 0.12.7

Platforms

Detected platforms: Flutter, other

Primary library: package:logger/logger.dart with components: io.

Health suggestions

Format lib/src/level.dart.

Run dartfmt to format lib/src/level.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <=3.0.0
meta ^1.1.6 1.1.6
Dev dependencies
test ^1.3.0