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
Custom Delimiters
Customize the brackets around icons and timestamps:
Log = DLogger(
icons={'info': 'INFO', 'error': 'ERR'},
styles={'info': 'bright_cyan', 'error': 'bright_red'},
delimiters='()' # Use parentheses instead of brackets
)
Log.info("Message with parentheses")
Output:
(INFO) Message with parentheses
Available delimiter styles:
'[]'→[INFO](default)'()'→(INFO)'{}'→{INFO}'<>'→<INFO>'||'→|INFO|'--'→-INFO-
Note: Delimiters must have an even number of characters. The first half becomes the left delimiter, the second half becomes the right delimiter.
Available Colors
DLogger supports the following color styles:
Standard Colors
black, red, green, yellow, blue, magenta, cyan, white, gray
Bright Colors
bright_red, bright_green, bright_yellow, bright_blue, bright_magenta, bright_cyan, bright_white
Special Colors
orange, purple, pink
Text Styles
bold, dim, italic, underline, blink, reverse, hidden, strikethrough
Background Colors
bg_black, bg_red, bg_green, bg_yellow, bg_blue, bg_magenta, bg_cyan, bg_white, bg_gray, bg_orange, bg_purple, bg_pink
Bright Background Colors
bg_bright_red, bg_bright_green, bg_bright_yellow, bg_bright_blue, bg_bright_magenta, bg_bright_cyan, bg_bright_white
Advanced Color Options
True Color (RGB)
Use 16 million colors with RGB values:
# Create a custom RGB color
coral = Log.rgb(255, 127, 80)
Log.print("Beautiful coral text", style=coral, icon='RGB')
# Background colors
bg_color = Log.rgb(50, 50, 50, background=True)
Log.print("Text with custom background", style=bg_color, icon='BG')
# Combine with other styles
Log.print("Bold coral", style=f'bold {coral}', icon='MIX')
256-Color Palette
Access the 256-color terminal palette:
# Use 256-color codes (0-255)
orange = Log.c256(208)
Log.print("Orange text", style=orange, icon='256')
# Background colors
bg = Log.c256(234, background=True)
Log.print("Dark background", style=bg, icon='BG')
Combining Styles
Mix multiple styles together:
# Multiple styles with spaces
Log.print("Bold + Underline + Color",
style='bold underline bright_green',
icon='MIX')
# RGB with text styles
custom = Log.rgb(255, 100, 50)
Log.print("Bold custom color", style=f'bold {custom}', icon='RGB')
# Inline style definitions
Log.print("Inline RGB", style='rgb(255, 100, 50)', icon='RGB')
Log.print("Inline 256", style='c256(208)', icon='256')
Log.print("Combined", style='bold underline rgb(255,100,50)', icon='ALL')
Inline Style Formats:
- RGB:
'rgb(r,g,b)'or'rgb(r,g,b,bg)'for background - 256-color:
'c256(code)'or'c256(code,bg)'for background
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')
Saving Logs to Files
DLogger can save logs to files in addition to displaying them in the console:
Single File Mode
Save all logs to a single file:
Log = DLogger(
icons={'info': 'INFO', 'error': 'ERR', 'success': 'OK'},
styles={'info': 'bright_cyan', 'error': 'bright_red', 'success': 'bright_green'},
save=True,
single_file=True,
save_to='app.log' # File path
)
Log.info("Application started")
Log.error("Connection failed")
Log.success("Recovered successfully")
Result: All logs saved to app.log:
[INFO] Application started
[ERR] Connection failed
[OK] Recovered successfully
Multiple Files Mode
Save logs to separate files based on their icon names:
Log = DLogger(
icons={'info': 'INFO', 'error': 'ERR', 'success': 'OK'},
styles={'info': 'bright_cyan', 'error': 'bright_red', 'success': 'bright_green'},
save=True,
single_file=False,
save_to='./logs' # Directory path
)
Log.info("Application started")
Log.error("Connection failed")
Log.success("Recovered successfully")
Result: Creates separate files:
./logs/INFO.log→[INFO] Application started./logs/ERR.log→[ERR] Connection failed./logs/OK.log→[OK] Recovered successfully
Save Options
Log = DLogger(
icons={'info': 'INFO'},
save=True, # Enable saving (default: False)
single_file=True, # One file vs. multiple files (default: False)
save_to='app.log', # File or directory path (default: '.')
strip_ansi=True # Remove color codes from files (default: True)
)
Parameters:
save: Enable or disable file savingsingle_file: IfTrue, all logs go to one file. IfFalse, separate files per iconsave_to: File path (single file mode) or directory path (multiple files mode)strip_ansi: IfTrue, removes color codes from saved logs for clean text files
With Timestamps
Timestamps are automatically included in saved logs when enabled:
Log = DLogger(
icons={'info': 'INFO'},
show_time=True,
time_format='%Y-%m-%d %H:%M:%S',
save=True,
save_to='app.log'
)
Log.info("Server started")
Saved to file:
[2024-03-15 14:30:45] [INFO] Server started
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',
save=True,
single_file=True,
save_to='application.log'
)
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!")
# All logs are now saved to 'application.log' without color codes
Requirements
- Python >= 3.6
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_bluebright_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
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dlogger-1.0.3.tar.gz.
File metadata
- Download URL: dlogger-1.0.3.tar.gz
- Upload date:
- Size: 23.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
81f47817b7f54c43c34e83238981173c335f95ea7fe8dbd83b494a3af3305c98
|
|
| MD5 |
68de3252240f41a193743892405938e6
|
|
| BLAKE2b-256 |
9d5c7a971e193a67607c5b8bf7447596ceb200ec3035e1c94a3273b0e7b54b19
|
Provenance
The following attestation bundles were made for dlogger-1.0.3.tar.gz:
Publisher:
python-publish.yml on dpipstudio/dlogger
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dlogger-1.0.3.tar.gz -
Subject digest:
81f47817b7f54c43c34e83238981173c335f95ea7fe8dbd83b494a3af3305c98 - Sigstore transparency entry: 725580030
- Sigstore integration time:
-
Permalink:
dpipstudio/dlogger@0f7e5ebb2b5fa897f0a89a1fa8c601c384eaf6bc -
Branch / Tag:
refs/heads/main - Owner: https://github.com/dpipstudio
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@0f7e5ebb2b5fa897f0a89a1fa8c601c384eaf6bc -
Trigger Event:
push
-
Statement type:
File details
Details for the file dlogger-1.0.3-py3-none-any.whl.
File metadata
- Download URL: dlogger-1.0.3-py3-none-any.whl
- Upload date:
- Size: 23.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
567add5354115c8db3d206bcab8d93ccada82c54715163282785ace59a3f0c2c
|
|
| MD5 |
36bca2e79843a31c2f9fd624c23e417e
|
|
| BLAKE2b-256 |
36dccda08a205df5c2b60df3c4d3d44c828a68bbe9a90b2015f7a344fd28ee05
|
Provenance
The following attestation bundles were made for dlogger-1.0.3-py3-none-any.whl:
Publisher:
python-publish.yml on dpipstudio/dlogger
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dlogger-1.0.3-py3-none-any.whl -
Subject digest:
567add5354115c8db3d206bcab8d93ccada82c54715163282785ace59a3f0c2c - Sigstore transparency entry: 725580037
- Sigstore integration time:
-
Permalink:
dpipstudio/dlogger@0f7e5ebb2b5fa897f0a89a1fa8c601c384eaf6bc -
Branch / Tag:
refs/heads/main - Owner: https://github.com/dpipstudio
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@0f7e5ebb2b5fa897f0a89a1fa8c601c384eaf6bc -
Trigger Event:
push
-
Statement type: