logging library
A flexible and extensible structured logging library for Dart and Flutter.
The jetleaf_log
library provides a pluggable, highly customizable logging solution
for applications that require clarity, consistency, and control over how logs are
captured, formatted, and displayed.
π§ Features:
- Multiple log levels:
TRACE
,DEBUG
,INFO
,WARN
,ERROR
,FATAL
- Structured, human-readable, and colorized output
- Supports tagging, timestamps, error handling, stack traces, and more
- Easily switch or create custom log output styles via
LogPrinter
- Customizable logging steps (
LogStep
) to include/exclude parts of a log
π¨οΈ Built-in Printer Types (via LogType
)
Type | Description | Output Style | Structured | Colorized |
---|---|---|---|---|
SIMPLE |
Concise single-line output with optional emoji and tags | Minimal | β | βοΈ |
FLAT |
Flat, raw output of the message only | Plain | β | β |
FLAT_STRUCTURED |
Flat output with structured fields like level, timestamp, etc. | One-line Structured | βοΈ | β |
PRETTY |
Formatted and aligned multi-line logs | Multi-line | β | βοΈ |
PRETTY_STRUCTURED |
Verbose, pretty-printed logs with section headers and stack traces | Multi-line Structured | βοΈ | βοΈ |
PREFIX |
Logs prefixed with info like [T:main] or [INFO] |
Prefixed | βοΈ | β |
FMT |
C-style formatted string logger | Formatted Strings | β | β |
HYBRID |
Combines pretty and structured logging for detailed yet readable output | Mixed Style | βοΈ | βοΈ |
π οΈ Creating a Custom Printer
To define a custom log printer, extend the LogPrinter abstract class:
class MyCustomPrinter extends LogPrinter {
@override
List<String> log(LogRecord record) {
return ['[${record.level.name}] ${record.message}'];
}
}
Then attach your printer to a custom tracing listener:
final myLogger = Jet();
myLogger.addListener(LoggerListener.withPrinter(MyCustomPrinter()));
myLogger.info('Hello from custom logger!');
π§ͺ Quick Usage Example
import 'package:jetleaf/logger.dart';
void main() {
console.debug('Initializing system...');
console.error('Failed to connect', error: Exception('Timeout'));
}
π¦ Exports:
This library exports core types and interfaces:
- LogLevel β log severity levels
- LogStep β defines log components like timestamp, message, error, etc.
JetType
β enum for built-in printer styles- LogPrinter β base class for custom printer implementations
- LoggingListener β interface for log event listening
@author Evaristus Adimonyemma @emailAddress evaristusadimonyemma@hapnium.com @organization Hapnium @website https://hapnium.com
Classes
- AnsiColor
- A utility class to apply ANSI terminal color codes to strings.
- AnsiOutput
- A utility class for formatting terminal output using ANSI colors and background styles.
- DefaultLoggingListener
- A default implementation of LoggingListener that outputs logs to the console.
- Log
- A convenient logging utility built on top of LogFactory.
- LogConfig
- Configuration class that controls the appearance and content of log output.
- LogFactory
- A base class for building structured logging mechanisms within Jet-based applications.
- Logger
- A flexible and extensible logging interface.
- LoggingListener
- A listener interface for reacting to logging events within an application.
- LogPrinter
- A base class for implementing custom log output formatting.
- LogProperties
- A small, thread-safe global registry for logging configuration and diagnostic properties within Jetleaf.
- LogRecord
-
A
LogRecord
represents a single logging event captured by the logging system.