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.2.tar.gz (18.5 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.2-py3-none-any.whl (18.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dlogger-1.0.2.tar.gz
  • Upload date:
  • Size: 18.5 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.2.tar.gz
Algorithm Hash digest
SHA256 b3235d6adf6c372a31d05cad6c05b1927af8d6eada8481412ac87fab62e47c77
MD5 2681dab971704314eca38296f7d2b426
BLAKE2b-256 1b06b0db6a228146615f849c23e61fe013498087438f6e39fb1676ca9d6ac0c9

See more details on using hashes here.

Provenance

The following attestation bundles were made for dlogger-1.0.2.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.2-py3-none-any.whl.

File metadata

  • Download URL: dlogger-1.0.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 584eb850bca634237fb848a7e46885a2e61972062321fac5aabe887d4e01e037
MD5 a80086448eab7504f8b6e27b70edcb55
BLAKE2b-256 ba5da851b4c3b9088af16565d35a060a8269a83d73a0a4eeccc96339d7240564

See more details on using hashes here.

Provenance

The following attestation bundles were made for dlogger-1.0.2-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