logger 0.3.1 logger: ^0.3.1 copied to clipboard
An efficient structured logger for Dart. The library provides a strongly-typed APIs to log structural records advantaging a better debugging experience.
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.