logging 0.11.3+2

  • Readme
  • Changelog
  • Installing
  • 85

Initializing #

By default, the logging package does not do anything useful with the log messages. You must configure the logging level and add a handler for the log messages.

Here is a simple logging configuration that logs all messages via print.

Logger.root.level = Level.ALL;
Logger.root.onRecord.listen((LogRecord rec) {
  print('${rec.level.name}: ${rec.time}: ${rec.message}');

First, set the root [Level]. All messages at or above the level are sent to the [onRecord] stream.

Then, listen on the [onRecord] stream for [LogRecord] events. The [LogRecord] class has various properties for the message, error, logger name, and more.

Logging messages #

Create a [Logger] with a unique name to easily identify the source of the log messages.

final Logger log = new Logger('MyClassName');

Here is an example of logging a debug message and an error:

var future = doSomethingAsync().then((result) {
  log.fine('Got the result: $result');
}).catchError((e, stackTrace) => log.severe('Oh noes!', e, stackTrace));

When logging more complex messages, you can pass a closure instead that will be evaluated only if the message is actually logged:

log.fine(() => [1, 2, 3, 4, 5].map((e) => e * 4).join("-"));

See the [Logger] class for the different logging methods.

0.11.3+2 #

  • Set max SDK version to <3.0.0, and adjust other dependencies.

0.11.3+1 #

  • Fixed several documentation comments.

0.11.3 #

  • Added optional LogRecord.object field.

  • Logger.log sets LogRecord.object if the message is not a string or a function that returns a string. So that a handler can access the original object instead of just its toString().

0.11.2 #

  • Added Logger.detached - a convenience factory to obtain a logger that is not attached to this library's logger hierarchy.

0.11.1+1 #

  • Include default error with the auto-generated stack traces.

0.11.1 #

  • Add support for automatically logging the stack trace on error messages. Note this can be expensive, so it is off by default.

0.11.0 #

  • Revert change in 0.10.0. stackTrace must be an instance of StackTrace. Use the Trace class from the stack_trace package to convert strings.

0.10.0 #

  • Change type of stackTrace from StackTrace to Object.

0.9.3 #

  • Added optional LogRecord.zone field.

  • Record current zone (or user specified zone) when creating new LogRecords.

Use this package as a library

1. Depend on it

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

  logging: ^0.11.3+2

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

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

3. Import it

Now in your Dart code, you can use:

import 'package:logging/logging.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

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

  • Dart: 2.6.1
  • pana: 0.12.21


Detected platforms: Flutter, web, other

No platform restriction found in primary library package:logging/logging.dart.

Health suggestions

Fix lib/logging.dart. (-11.78 points)

Analysis of lib/logging.dart reported 25 hints, including:

line 55 col 45: Unnecessary new keyword.

line 67 col 12: Unnecessary new keyword.

line 67 col 45: Unnecessary new keyword.

line 72 col 13: Unnecessary new keyword.

line 79 col 32: Unnecessary new keyword.

Maintenance suggestions

Package is getting outdated. (-38.63 points)

The package was last published 72 weeks ago.

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and logging.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.

The description is too long. (-5 points)

Search engines display only the first part of the description. Try to keep the value of the description field in your package's pubspec.yaml file between 60 and 180 characters.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.5.0 <3.0.0
Dev dependencies
test >=0.12.0 <2.0.0