Skip to main content

Advanced console logging with color support

Project description

kingkybel-pyflashlogger

Advanced console logging with color support and minimal configuration interface.

Features

  • 🎨 Color-Coded Logging: Automatic ANSI color coding for different log levels
  • 🏷️ Custom Log Levels: Support for custom log levels with configurable labels
  • 🔄 Minimal Interface: Simple API for logging without complex setup
  • 🌈 Special Color Support: Configurable colors for timestamps, process IDs, brackets, operators, etc.
  • 📋 Field Ordering: Base class configurable field ordering (level, timestamp, pid, tid, message) for all log channels
  • 💾 JSON Configuration: Save and load color/label configurations
  • 🔗 Multiple Channels: Console and file logging implementations with unified configuration
  • 🧪 Format Flexibility: Different formats for standard logs, commands, and std streams
  • 📤 Output Formats: Multiple output formats (Human readable, JSON pretty, JSON lines) available to all channels
  • Comprehensive Testing: Full test coverage including all new functionality

Installation

pip install kingkybel-pyflashlogger

Or from source:

git clone https://github.com/kingkybel/FlashLogger.git
cd FlashLogger
pip install -e .

Quick Start

from flashlogger import FlashLogger, ColorScheme, LogLevel

# Basic usage
logger = FlashLogger()
logger.log_info("This is an info message")
logger.log_warning("This is a warning")

# With custom colors
scheme = ColorScheme.default_color_scheme()
console_logger = FlashLogger(console=scheme)
console_logger.log_error("Colorized error message")

# Custom log levels
logger.log_custom0("Custom level message")

Advanced Usage

Color Configuration

from flashlogger import ColorScheme

# Load predefined schemes
color_scheme = ColorScheme(ColorScheme.Default.COLOR)
bw_scheme = ColorScheme(ColorScheme.Default.BLACK_AND_WHITE)

# Create custom scheme
custom_scheme = ColorScheme()
custom_scheme.warning_normal_foreground = Fore.RED
custom_scheme.warning_normal_background = Back.YELLOW

Field Ordering

# Customize log field display order
scheme.field_order = ["level", "timestamp", "message"]  # Omit pid/tid
logger = FlashLogger(console=scheme)

# Output: [WARNING] [2025-10-26 00:00:00.000] This is a message

Custom Labels

from flashlogger import LogLevel

# Define custom labels
LogLevel.set_str_repr(LogLevel.custom0, "NETWORK_IO")
LogLevel.set_str_repr(LogLevel.custom1, "DB_QUERY")

logger = FlashLogger()
logger.log_custom0("Network I/O operation")  # Shows as "NETWORK_IO"

Output Formats

from flashlogger import LogChannelConsole, OutputFormat

# Human readable (default)
human_channel = LogChannelConsole(minimum_log_level="INFO")

# JSON pretty printing
json_channel = LogChannelConsole(output_format=OutputFormat.JSON_PRETTY)

# JSON lines for streaming
lines_channel = LogChannelConsole(output_format="JSON_LINES")

# Example output comparison:
# Human: [2025-10-27 08:35:00.123] [INFO] [PID:1234|TID:5678] Operation completed
# JSON: {"timestamp": "2025-10-27 08:35:00.123", "level": "info", "message": "Operation completed", "pid": 1234, "tid": 5678}

Log Levels

  • DEBUG: Debugging information
  • INFO: General information
  • WARNING: Warning conditions
  • ERROR: Error conditions
  • FATAL: Fatal errors
  • CRITICAL: Critical conditions
  • COMMAND: Command execution
  • COMMAND_OUTPUT: Command stdout capture
  • COMMAND_STDERR: Command stderr capture
  • CUSTOM0-9: Custom user-defined levels

Configuration Files

FlashLogger includes default configuration files for color schemes and log level labels:

  • color_scheme_color.json: Full color scheme
  • color_scheme_bw.json: Black and white scheme
  • log_levels_en.json: English log level labels
  • log_levels_de.json: German log level labels

Channels

Console Channel

from flashlogger import LogChannelConsole

channel = LogChannelConsole(color_scheme=my_scheme, minimum_log_level="WARNING")
channel.do_log("ERROR", "This error will be logged")

File Channel

from flashlogger import LogChannelFile

channel = LogChannelFile(filename="app.log")
channel.do_log("INFO", "This goes to file")

Custom Channels

Extend LogChannelABC for custom logging destinations:

from flashlogger import LogChannelABC

class MyChannel(LogChannelABC):
    def do_log(self, log_level, *args, **kwargs):
        # Your custom logging logic
        pass

API Reference

FlashLogger

  • log_debug(message): Log debug message
  • log_info(message): Log info message
  • log_warning(message): Log warning message
  • log_error(message): Log error message
  • log_fatal(message): Log fatal error
  • log_custom0(message): Log custom level 0

ColorScheme

  • Constructor: ColorScheme(default_scheme_or_path)
  • Methods: save_to_json(path), set_level_color()

LogLevel

  • Standard levels: DEBUG, INFO, WARNING, etc.
  • Custom levels: CUSTOM0 through CUSTOM9
  • Methods: set_str_repr(level, label), load_str_reprs_from_json(path)

License

GPLv2 - See the LICENSE file for details.

Contributing

Contributions welcome! Please open issues for bugs or feature requests.

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kingkybel_pyflashlogger-1.0.1.tar.gz (30.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kingkybel_pyflashlogger-1.0.1-py3-none-any.whl (26.0 kB view details)

Uploaded Python 3

File details

Details for the file kingkybel_pyflashlogger-1.0.1.tar.gz.

File metadata

  • Download URL: kingkybel_pyflashlogger-1.0.1.tar.gz
  • Upload date:
  • Size: 30.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for kingkybel_pyflashlogger-1.0.1.tar.gz
Algorithm Hash digest
SHA256 e3e903f1334a0558eecaec23f0e8237be81c92238e7fa4fea3453a4d14af0962
MD5 9db161b3311f148ae906a755a786635c
BLAKE2b-256 8a511580aad50ce9311205ed5096eaffa030ef661a0b6b6fdd88d837a7f76de2

See more details on using hashes here.

File details

Details for the file kingkybel_pyflashlogger-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for kingkybel_pyflashlogger-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 76546b08f8acc86f705e293c7525781640f4d38b38cc51d3317332b5402fd274
MD5 b296e2f6446bb5b9b28f7acf622b5188
BLAKE2b-256 96eb8ad122600d65b1fce16ee2fd762206fb891cc9fbd7e85b6ff0b986f979f9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page