quiver_log 1.0.6
Quiver Log #
Quiver log is a set of logging utilities that make it easy to configure and manage Dart's built in logging capabilities.
Documentation #
API Docs are available.
The Basics #
Dart's built-in logging utilities are fairly low level. This means each time you
start a new project you have to copy/paste a bunch of logging configuration
code to setup output locations and logging formats. Quiver-log provides a set of
higher-level abstractions to make it easier to get logging setup correctly.
Specifically, there are two new concepts: appender
and formatter
. Appenders
define output locations like the console, http or even in-memory data structures
that can store logs. Formatters, as the name implies, allow for custom logging
formats.
Here is a simple example that sets up a InMemoryAppender
with a
SimpleStringFormatter
:
import 'package:logging/logging.dart';
import 'package:quiver_log/log.dart';
class SimpleStringFormatter implements FormatterBase<String> {
String call(LogRecord record) => record.message;
}
main() {
var logger = new Logger('quiver.TestLogger');
var appender = new InMemoryListAppender(new SimpleStringFormatter());
appender.attachLogger(logger);
}
That's all there is to it!
Quiver-log provides three Appender
s: PrintAppender
which uses Dart's print statement to write to the console,
InMemoryListAppender
which writes logs to a simple list (this can be useful for debugging or testing) and a WebAppender
which will take advantage of web console methods to improve readability in your browser. Additionally, a single Formatter
called
BasicLogFormatter
is included and uses a "MMyy HH:mm:ss.S" format. Of course
there is no limit to what kind of appenders you can create, we have plans to
add appenders HTTP, WebSocket, DOM, Isolate and SysOut.
To create a new kind of Appender
simply extends Appender
. To create a new
Formatter
just implement the Formatter
typedef or FormatterBase
class if
you need to hold state in your formtatter. Take a look at PrintAppender and BasicLogFormatter for an example.
Use this package as a library
1. Depend on it
Add this to your package's pubspec.yaml file:
dependencies:
quiver_log: ^1.0.6
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:quiver_log/log.dart';
import 'package:quiver_log/web.dart';
Popularity:
Describes how popular the package is relative to other packages.
[more]
|
62
|
Health:
Code health derived from static analysis.
[more]
|
98
|
Maintenance:
Reflects how tidy and up-to-date the package is.
[more]
|
27
|
Overall:
Weighted score of the above.
[more]
|
66
|
We analyzed this package on Dec 6, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:
- Dart: 2.6.1
- pana: 0.12.21
Platforms
Detected platforms: web
Platform components identified in package:
html
.
Health suggestions
Fix lib/src/web.dart
. (-1.49 points)
Analysis of lib/src/web.dart
reported 3 hints:
line 21 col 30: Unnecessary new keyword.
line 36 col 8: Unnecessary new keyword.
line 41 col 7: Unnecessary new keyword.
Fix lib/src/log.dart
. (-1 points)
Analysis of lib/src/log.dart
reported 2 hints:
line 66 col 41: Unnecessary new keyword.
line 90 col 29: Avoid const keyword.
Format lib/log.dart
.
Run dartfmt
to format lib/log.dart
.
Format lib/web.dart
.
Run dartfmt
to format lib/web.dart
.
Maintenance issues and suggestions
Provide a file named CHANGELOG.md
. (-20 points)
Changelog entries help developers follow the progress of your package. See the example generated by stagehand
.
Use constrained dependencies. (-20 points)
The pubspec.yaml
contains 2 dependencies without version constraints. Specify version ranges for the following dependencies: intl
, logging
.
Package is getting outdated. (-23.56 points)
The package was last published 64 weeks ago.
Documentation URL is insecure. (-5 points)
Update the documentation
field and use a secure (https
) URL.
The package description is too short. (-4 points)
Add more detail to the description
field of pubspec.yaml
. Use 60 to 180 characters to describe the package, what it does, and its target use case.
Maintain an example.
None of the files in the package's example/
directory matches known example patterns.
Common filename patterns include main.dart
, example.dart
, and quiver_log.dart
. Packages with multiple examples should provide example/README.md
.
For more information see the pub package layout conventions.