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.

Enums

LogLevel
Defines various levels of logging severity for controlling logging output.
LogStep
Defines individual components (steps) that can be included in log output.
LogType
Specifies the overall formatting strategy used for log output.

Properties

console β†’ Logger
Global singleton logger instance for convenience.
final