clever_logger 1.1.0+1 copy "clever_logger: ^1.1.0+1" to clipboard
clever_logger: ^1.1.0+1 copied to clipboard

An easy to use, highly extendable logger library with colorful prints.

Clever Logger #

style: very good analysis Powered by Mason License: MIT Coverage

An extendable logger library with colorful prints.

Basic Usage ๐Ÿš€ #

You can log messages with different levels of severity.

The default levels are the following:

  • fine
  • info
  • config
  • warning
  • shout

To log a message at level info with the default logger:

logInfo('Hello there!');

This prints this message to the console.

[Logger - INFO] Hello there!

Create a logger and use it to log messages.

final logger = CleverLogger('Test Logger');
// now you can use this logger
logger.logFine('Hello there!');

Advanced Usage ๐Ÿงช #

Log Actions #

Log actions are responsible for what happens with the logs (for example storing them in a file or sending them to your analytics service).

The LogRecords are passed to the actions in order. By default, the logger uses a ColorfulPrintAction as its default action, which is responsible for colorful outputs to the console.

final otherLogger = CleverLogger(
  'Other Logger',
  logActions: [
    // The default colorful console output.
    ColorfulPrintAction(),
    // A custom action
    MyLogAction(),
  ],
);

Log actions can also be configured to only run for logs with a certain level.

class MyLogAction extends LogAction {
  @override
  Level get level => Level.INFO;

  @override
  void onRecord(LogRecord record) {
    //This is only executed for logs with a level >= Level.info
    print('${record.loggerName} has a log with ${record.level}');
  }
}

Extending functionality #

You can write extension methods to extend the loggers functionality. Additional values can be stored in the value variable of the logger.

By default, the logger has a Stopwatch integrated as an extension.

See the example for more information.

Custom Printer #

Extend the ColorfulPrintAction and override the default print functions, like printInfo, printWarning etc. for custom-styled print messages.

You can use the ansicolor plugin for colorful prints.

2
likes
160
pub points
37%
popularity

Publisher

verified publisherclevertasks.de

An easy to use, highly extendable logger library with colorful prints.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

ansicolor, logging

More

Packages that depend on clever_logger