cherrilog 0.1.1
cherrilog: ^0.1.1 copied to clipboard
Perhaps the simplest and most useful log library for dart. Lightweight and easy to apply.
CherriLog #
CherriLog is perhaps the simplest and most useful log library for dart
Overview #
CherriLog is a simple and useful log library for dart. It is easy to use and can be costumized to your needs.
Features #
- Log messages directly by calling the method directly.
- Direct output to console with different colors.
- Nice stacktrace output.
- [In Progress] Log to file. (Program Full Platform Support)
- [In Progress] Highly customizable log format.
- Log levels support.
Usage #
- Add the dependency to your
pubspec.yamlfile. Recommended command line.
With Flutter
flutter pub add cherrilog
With Dart
dart pub add cherrilog
- Import the library in your code.
import 'package:cherrilog/cherrilog.dart';
- Initialize the logger.
CherriLog.init(
options: CherriOptions()
..maximumLevel = CherriLogLevel.all
..minimumLevel = CherriLogLevel.off
..timeStampPattern = CherriFormatterTimeStampPattern.standardLongDateTime
..useBuffer = false,
).logTo(CherriConsole());
- Use the logger.
info('This is an info message');
warning('This is a warning message');
error('Something went wrong');
Configuration #
The class CherriOptions contains all the configuration options for the logger.
CherriLogLevel maximumLevel: The maximum log level to be displayed. Default isCherriLogLevel.warning.CherriLogLevel minimumLevel: The minimum log level to be displayed. Default isCherriLogLevel.all.String timeStampPattern: The pattern to be used for the timestamp. Default isCherriFormatterTimeStampPattern.standardLongDateTime.bool useBuffer: Iftrue, the logs will be buffered and only displayed when the buffer is full. Default istrue.int bufferLineLength: The number of lines to be buffered before displaying them. Default is30.Duration flushInterval: The interval to flush the buffer. Default isconst Duration(milliseconds: 500).
Log Levels #
The log levels are defined in the CherriLogLevel enum.
Ranking of importance from highest to lowest.
CherriLogLevel.all: All log levels. You should NOT use this loglevel when logging messages.CherriLogLevel.fatal: Fatal errors.CherriLogLevel.error: Errors.CherriLogLevel.warning: Warnings.CherriLogLevel.info: Informational messages.CherriLogLevel.debug: Debug messages.CherriLogLevel.off: No log messages. You should NOT use this loglevel when logging messages.
timeStampPattern #
We offer some preset formats. You can also create your own format.
You can see formatter/timestamp.dart for more information.
Customization #
TODO
Output #
[2024-04-13 18:07:28] [DBG] You are doing something right [2024-04-13 18:07:28] [INF] You are doing something [2024-04-13 18:07:28] [WRN] You are doing something wrong [2024-04-13 18:07:28] [ERR] You can not shutdown power [2024-04-13 18:07:28] [FTL] The power is off
Note: The colors may vary depending on the terminal. This is probably the result on VSCode. Reference