contextual_logging 1.0.0 copy "contextual_logging: ^1.0.0" to clipboard
contextual_logging: ^1.0.0 copied to clipboard

A log mixin that uses logger package and allows to make messages contextual.

contextual_logging pub version #

✏️ A mixin for Dart classes that brings contextual logging functionality.

What's contextual logging? #

We all know log messages. They are printed to the console, to the files or whatever. Dart provides us with loggable methods like:

print('A message');
debugPrint('Another message');

Good enough to debug. But when you actually need to investigate users' journey, it is not. You'll need context. The context here answers the question who has printed the message?.

Bringing the context could be done like this:

print('My Controller : A message');
debugPrint('My Controller : Another message');

Though to write the context every time is pretty boring. This is what contextual_logging solves.

How to use #

Attach the mixin it to your class that you want to use for logging:

class MyController with ContextualLogging

And... Go for it!

class MyController with ContextualLogging {
  Future<void> init() async {
    log.i('Initializing ...'); // <-- Access logging via the log field
    await fetchData();
    log.i('Initialized!');
  }
}

What will be printed? #

In the console you'll see this:

10:03:00 [I] MyController : Initializing ...
10:03:01 [I] MyController : Initialized!

A timestamp, a log level, a context and a message.

Timestamp

// TODO...

Log level

// TODO...

Context

// TODO...

Message

// TODO...

10
likes
0
pub points
63%
popularity

Publisher

unverified uploader

A log mixin that uses logger package and allows to make messages contextual.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

intl, logger, meta

More

Packages that depend on contextual_logging