Overview
CherriLog is perhaps the simplest and most useful log library for all dart program
Features
- Log messages directly by calling static methods
- Nice stacktrace formatter
- Custom log levels support
- Custom loggers:
- Direct output to console with different colors
TODOs
Usage
-
Add the dependency to your
pubspec.yaml
file
Recommend to use command line:With Flutter
flutter pub add cherrilog
With Dart
dart pub add cherrilog
-
Import library
import 'package:cherrilog/cherrilog.dart';
-
Initialize cherrilog
CherriLog.init( options: CherriOptions() ..logLevelRange = CherriLogLevelRanges.all ..useBuffer = false, ).logTo(CherriConsole());
-
Call log methods
debug('This is a debug message'); info('This is an info message'); warning('This is a warning message'); error('Something went wrong'); fatal('Oh oh :(');
Log levels
Cherrilog provides a CherriLogLevel
class to support custom level, and below is the default instances:
CherriLogLevel.fatal
: Fatal errorsCherriLogLevel.error
: ErrorsCherriLogLevel.warning
: WarningsCherriLogLevel.info
: Information messagesCherriLogLevel.debug
: Debug messages
And you will also see nether
and upperBond
, these two instances is to help with comparison, don't use them directly.
You can find some predefined log level ranges in CherriLogLevelRanges
class.
Timestamp Patterns
We offer some preset timestamp formats with in formatter/timestamp.dart
.
You can also use your own format.
Output
[2024-04-13 18:07:28] [DBG] This is a debug message [2024-04-13 18:07:28] [INF] This is an info message [2024-04-13 18:07:28] [WRN] This is a warning message [2024-04-13 18:07:28] [ERR] Something went wrong [2024-04-13 18:07:28] [FTL] Oh oh :(
Note: The colors may vary depending on the terminal. This is probably the result on VSCode. Reference