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.0.tar.gz (32.8 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.0-py3-none-any.whl (30.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: kingkybel_pyflashlogger-1.0.0.tar.gz
  • Upload date:
  • Size: 32.8 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.0.tar.gz
Algorithm Hash digest
SHA256 7d99072f9d52203c91c1eb8aa1d742d2cf91bf1f48afc0eddd3531c3a3ec2a12
MD5 10265737b5e9f3bfdaccd7ba839adb78
BLAKE2b-256 3ca266fde4d7542bf0c211043d3e6cc305bffc6e03ec5a0ccd2ffbf7c23b4c90

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kingkybel_pyflashlogger-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ff0650258b21d427455174079e49e9dbb87179128aa104276d0e3cfbedb73034
MD5 120a2106d78d295328512f2b7222d23e
BLAKE2b-256 1e9e71d08a0f8d86030d31316bd8f7ffd42161159eb7d2008e10337935084ecc

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