Skip to main content

DivineGift Logger

A flexible and configurable logging package for Python applications with file rotation and command-line configuration support.

Features

  • ✅ Easy configuration via code or command-line arguments
  • ✅ File rotation with customizable intervals
  • ✅ Both file and console logging support
  • ✅ Thread-safe implementation
  • ✅ Type hints for better IDE support
  • ✅ Exception logging with stack traces

Installation

pip install dglog

Basic Usage

Simple console logging

from dglog import get_logger

logger = get_logger()
logger.configure_logger()
logger.info("Application started")
logger.warning("This is a warning")

Configure logger programmatically

from dglog import configure_logger

# Configure with daily file rotation
configure_logger(
    log_level="DEBUG",
    log_name="app.log",
    log_dir="./logs",
    when="D",
    backup_count=14
)

log_info("This will be logged to file")

Command-line configuration

Run your script with logging parameters:

python your_script.py --log_level DEBUG --log_name app.log --log_dir ./logs

The logger will automatically pick up these parameters.

API Reference

Core Functions

Function Description
get_logger() Returns the global logger instance
configure_logger(**kwargs) Configures the global logger
log_debug(*args, separator=" ") Logs debug message
log_info(*args, separator=" ") Logs info message
log_warning(*args, separator=" ") Logs warning message
log_error(*args, separator=" ") Logs error message
log_critical(*args, separator=" ") Logs critical message
log_exception(*args, separator=" ") Logs exception with stack trace

Logger Class Methods

from dglog import get_logger

logger = get_logger()

# Configuration
logger.configure_logger(
    log_level="INFO",          # Logging level
    log_name=None,             # File name (None for console)
    log_dir="./logs",          # Log directory
    when="midnight",          # Rotation interval
    interval=1,               # Rotation frequency
    backup_count=7,           # Number of backups
    formatter=None            # Custom formatter
)

# Logging methods
logger.debug("Debug message")
logger.info("Information")
logger.warning("Warning message")
logger.error("Error occurred")
logger.critical("Critical failure")
logger.exception("Exception occurred")  # With stack trace

Advanced Examples

Custom Formatter

from logging import Formatter
from dglog import configure_logger

custom_format = Formatter('%(name)s - %(levelname)s - %(message)s')
configure_logger(log_level="DEBUG", formatter=custom_format)

Exception Handling

from dglog import log_exception

try:
    1 / 0
except Exception:
    log_exception("Division failed")
    # Output includes the stack trace

Multiple Arguments

log_info("User", "logged in", "from IP", "192.168.1.1", separator=" | ")
# Output: User | logged in | from IP | 192.168.1.1

Dynamic Configuration

import sys
from dglog import get_logger

logger = get_logger()

if '--debug' in sys.argv:
    logger.configure_logger(log_level="DEBUG")
else:
    logger.configure_logger(log_level="INFO")

Configuration Parameters

Parameter Default Description
log_level "INFO" Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
log_name None Log file name (None for console logging)
log_dir "./logs" Directory for log files
when "midnight" Rotation interval ('S', 'M', 'H', 'D', 'midnight', etc.)
interval 1 Rotation frequency
backup_count 7 Number of backup files to keep
formatter Default format Custom log message formatter

Best Practices

  1. Early Configuration: Configure the logger at the start of your application
  2. Proper Log Levels: Use appropriate levels for different situations
  3. Structured Data: Include context in your log messages
  4. Exception Handling: Always use log_exception() for errors
  5. Rotation Policy: Choose appropriate rotation settings based on your needs

License

MIT License - Free for commercial and personal use.

Metadata

Release files for dglog 1.0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dglog 1.0.0.1
File Size Uploaded Provenance Actions
dglog-1.0.0.1.tar.gz 6.3 kB Without provenance Details for dglog-1.0.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for dglog 1.0.0.1
File Interpreter ABI Platform Actions
dglog-1.0.0.1-py3-none-any.whl Python 3 none any Details for dglog-1.0.0.1-py3-none-any.whl

Total release size: 12.4 kB

Release files / dglog-1.0.0.1.tar.gz

Download URL dglog-1.0.0.1.tar.gz
Size 6.3 kB
Tags Source
SHA-256 checksum
How to use checksums
45cfdeb3b2076abc6d27accba3aff570d97b0bc6b8615700154ed76bae60dfa5
BLAKE2b-256 checksum
How to use checksums
c0c10ac75546a739e3c125dd2fe859a0e796a2e09ee0f3328871aed13da7c101
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Release files / dglog-1.0.0.1-py3-none-any.whl

Download URL dglog-1.0.0.1-py3-none-any.whl
Size 6.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2c54c28d8652bbac3f70e8153052786ff0c91cbb54d8db65a6cc962095b076f7
BLAKE2b-256 checksum
How to use checksums
8262634f4b3a0f78f14155dea818b23fd9a9591877e191510bd9052bc79a7667
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Security for dglog 1.0.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page