Skip to main content

Dynamic Console Logger for Python with colored output, custom icons, and other features.

Project description

DLogger

A lightweight, dynamic console logger for Python with colored output, automatic method generation, and optional timestamps.

Installation

pip install dlogger

Or just copy dlogger.py into your project.

Quick Start

from dlogger import DLogger

# Create your logger with custom icons and colors
Log = DLogger(
    icons={
        'success': 'OK',
        'error': 'ERR',
        'warning': 'WARN',
        'info': 'INFO',
    },
    styles={
        'success': 'bright_green',
        'error': 'bright_red',
        'warning': 'bright_yellow',
        'info': 'bright_cyan',
    }
)

# Use the dynamically generated methods
Log.success("Operation completed!")
Log.error("Something went wrong!")
Log.warning("Be careful!")
Log.info("Just so you know...")

Output:

[OK] Operation completed!        # in bright green
[ERR] Something went wrong!      # in bright red
[WARN] Be careful!               # in bright yellow
[INFO] Just so you know...       # in bright cyan

Timestamps (Optional)

Enable timestamps with customizable formats:

Log = DLogger(
    icons={'info': 'INFO', 'error': 'ERR'},
    styles={'info': 'bright_cyan', 'error': 'bright_red'},
    show_time=True,                      # Enable timestamps (default: False)
    time_format='%H:%M:%S',              # Customize format (default: '%H:%M:%S')
    time_style='bright_white'            # Timestamp color (default: 'bright_white')
)

Log.info("Application started")
Log.error("Connection failed")

Output:

[14:30:45] [INFO] Application started
[14:30:47] [ERR] Connection failed

Common Time Formats

  • '%H:%M:%S'14:30:45
  • '%Y-%m-%d %H:%M:%S'2024-03-15 14:30:45
  • '%I:%M:%S %p'02:30:45 PM
  • '%b %d %H:%M:%S'Mar 15 14:30:45
  • '%Y-%m-%d'2024-03-15

Runtime Control

# Enable/disable timestamps dynamically
Log.enable_time(True)   # Enable timestamps
Log.enable_time(False)  # Disable timestamps

# Change format on the fly
Log.set_time_format('%Y-%m-%d %H:%M:%S')

Available Colors

DLogger supports the following color styles:

Standard Colors

  • red, green, yellow, blue, magenta, cyan, white

Bright Colors

  • bright_red, bright_green, bright_yellow, bright_blue
  • bright_magenta, bright_cyan, bright_white

Text Styles

  • bold, underline, reset

Additional Features

Headers and Sections

Log.header("My Application")
Log.section("Configuration")

Progress Bars

for i in range(101):
    Log.progress_bar(i, 100, prefix='Loading:', suffix='Complete')

Output:

Loading: [#####################---------] 70.0% Complete

Manual Printing

# Print without using generated methods
Log.print("Custom message", style='magenta', icon='CUSTOM')

How It Works

DLogger automatically generates methods based on your icons dictionary. Each key becomes a method name:

Log = DLogger(
    icons={'database': 'DB', 'api': 'API', 'cache': 'CACHE'},
    styles={'database': 'green', 'api': 'blue', 'cache': 'yellow'}
)

Log.database("Connected to PostgreSQL")  # [DB] Connected to PostgreSQL
Log.api("Request received")              # [API] Request received
Log.cache("Cache hit!")                  # [CACHE] Cache hit!

You can create any method names you want - DLogger dynamically generates them at initialization!

Complete Example

from dlogger import DLogger
import time

# Initialize with timestamps
Log = DLogger(
    icons={
        'start': '▶',
        'done': '✓',
        'fail': '✗',
        'info': 'ℹ'
    },
    styles={
        'start': 'bright_blue',
        'done': 'bright_green',
        'fail': 'bright_red',
        'info': 'bright_cyan'
    },
    show_time=True,
    time_format='%H:%M:%S'
)

Log.header("Application Startup")
Log.start("Initializing...")

Log.section("Database Connection")
Log.info("Connecting to database...")
time.sleep(1)
Log.done("Database connected successfully")

Log.section("Loading Configuration")
for i in range(101):
    Log.progress_bar(i, 100, prefix='Loading:', suffix='Complete', 
                     fill='█', style='bright_green')
    time.sleep(0.02)

Log.done("Application ready!")

Requirements

  • Python >= 3.8

License

Licensed under GPL-3.0, see LICENSE


DLogger

A lightweight, dynamic console logger for Python with colored output, automatic method generation, and optional timestamps.

Installation

pip install dlogger

Or just copy dlogger.py into your project.

Quick Start

from dlogger import DLogger

# Create your logger with custom icons and colors
Log = DLogger(
    icons={
        'success': 'OK',
        'error': 'ERR',
        'warning': 'WARN',
        'info': 'INFO',
    },
    styles={
        'success': 'bright_green',
        'error': 'bright_red',
        'warning': 'bright_yellow',
        'info': 'bright_cyan',
    }
)

# Use the dynamically generated methods
Log.success("Operation completed!")
Log.error("Something went wrong!")
Log.warning("Be careful!")
Log.info("Just so you know...")

Output:

[OK] Operation completed!        # in bright green
[ERR] Something went wrong!      # in bright red
[WARN] Be careful!               # in bright yellow
[INFO] Just so you know...       # in bright cyan

Timestamps (Optional)

Enable timestamps with customizable formats:

Log = DLogger(
    icons={'info': 'INFO', 'error': 'ERR'},
    styles={'info': 'bright_cyan', 'error': 'bright_red'},
    show_time=True,                      # Enable timestamps (default: False)
    time_format='%H:%M:%S',              # Customize format (default: '%H:%M:%S')
    time_style='bright_white'            # Timestamp color (default: 'bright_white')
)

Log.info("Application started")
Log.error("Connection failed")

Output:

[14:30:45] [INFO] Application started
[14:30:47] [ERR] Connection failed

Common Time Formats

  • '%H:%M:%S'14:30:45
  • '%Y-%m-%d %H:%M:%S'2024-03-15 14:30:45
  • '%I:%M:%S %p'02:30:45 PM
  • '%b %d %H:%M:%S'Mar 15 14:30:45
  • '%Y-%m-%d'2024-03-15

Available Colors

DLogger supports the following color styles:

Standard Colors

  • red, green, yellow, blue, magenta, cyan, white

Bright Colors

  • bright_red, bright_green, bright_yellow, bright_blue
  • bright_magenta, bright_cyan, bright_white

Text Styles

  • bold, underline, reset

Additional Features

Headers and Sections

Log.header("My Application")
Log.section("Configuration")

Progress Bars

for i in range(101):
    Log.progress_bar(i, 100, prefix='Loading:', suffix='Complete')

Output:

Loading: [#####################---------] 70.0% Complete

Manual Printing

# Print without using generated methods
Log.print("Custom message", style='magenta', icon='CUSTOM')

How It Works

DLogger automatically generates methods based on your icons dictionary. Each key becomes a method name:

Log = DLogger(
    icons={'database': 'DB', 'api': 'API', 'cache': 'CACHE'},
    styles={'database': 'green', 'api': 'blue', 'cache': 'yellow'}
)

Log.database("Connected to PostgreSQL")  # [DB] Connected to PostgreSQL
Log.api("Request received")              # [API] Request received
Log.cache("Cache hit!")                  # [CACHE] Cache hit!

You can create any method names you want: DLogger dynamically generates them at initialization!

Complete Example

from dlogger import DLogger
import time

# Initialize with timestamps
Log = DLogger(
    icons={
        'start': '▶',
        'done': '✓',
        'fail': '✗',
        'info': 'ℹ'
    },
    styles={
        'start': 'bright_blue',
        'done': 'bright_green',
        'fail': 'bright_red',
        'info': 'bright_cyan'
    },
    show_time=True,
    time_format='%H:%M:%S'
)

Log.header("Application Startup")
Log.start("Initializing...")

Log.section("Database Connection")
Log.info("Connecting to database...")
time.sleep(1)
Log.done("Database connected successfully")

Log.section("Loading Configuration")
for i in range(101):
    Log.progress_bar(i, 100, prefix='Loading:', suffix='Complete', 
                     fill='█', style='bright_green')
    time.sleep(0.02)

Log.done("Application ready!")

Requirements

  • Python >= 3.8

License

Licensed under GPL-3.0, see LICENSE


madebydouxx adpipproject

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

dlogger-1.0.1.tar.gz (18.6 kB view details)

Uploaded Source

Built Distribution

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

dlogger-1.0.1-py3-none-any.whl (18.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dlogger-1.0.1.tar.gz
  • Upload date:
  • Size: 18.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dlogger-1.0.1.tar.gz
Algorithm Hash digest
SHA256 5d510f694c7ba0ca88ec6a5a71f1c4b473d65f36367cd1ee0273edeb237a1d5a
MD5 393c298ea7f4baffe4ba4cf80b00ef57
BLAKE2b-256 46061d4e2ab2e4fab7aa4b83e4cfaf955315bb952cb089e62e4a98e0e1a6d496

See more details on using hashes here.

Provenance

The following attestation bundles were made for dlogger-1.0.1.tar.gz:

Publisher: python-publish.yml on dpipstudio/dlogger

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: dlogger-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 18.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dlogger-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cded7a0e3fe20a5f9d1e29256915949857a37f238276e0a7563fd8f3ffd6c2fa
MD5 95a9cde797cc8cdb55fe9a4dfd0f2fc7
BLAKE2b-256 5237f39d0f6d7feb047c8cfda68cc74fc773f1b57337a9eb9a0a785901bf5e3d

See more details on using hashes here.

Provenance

The following attestation bundles were made for dlogger-1.0.1-py3-none-any.whl:

Publisher: python-publish.yml on dpipstudio/dlogger

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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