Skip to main content

Enhanced Logger


PyPI version Downloads License

The Enhanced Logger package is an extension of the built-in Python logging module, designed to address additional features and performance metrics. This package includes:

  • Trace logging to log all function entry and exit
  • JSON and XML formatters
  • Performance metrics logging
  • HTTP and database logging handlers
  • File logging for all logger types (except DB Handler)

Features

  • Trace Logging: Log entry and exit points of functions with context.
  • Performance Metrics: Log execution time and memory usage of functions.
  • Enhanced Formatters: Log entries in JSON and XML formats.
  • HTTP Logging: Send log entries to a remote server via HTTP.
  • Database Logging: Store log entries in various types of databases (SQLite, PostgreSQL, MongoDB).
  • File Logging: Option to store logs in a .log file.

Installation

To install the Enhanced Logger package, use the following command:

pip install enhanced-logger

Usage

Trace Logger

Trace logging allows you to trace the entry and exit points of functions.

from enhanced_logger import EnhancedLogger

trace_logger = EnhancedLogger.configure_trace_logger('trace_logger')

@trace_logger.trace
def sample_function(x, y):
    return x + y

sample_function(5, 10)

Performance Logger

Performance logging provides execution time and memory usage information.

from enhanced_logger import EnhancedLogger

performance_logger = EnhancedLogger.configure_performance_logger('performance_logger')

@performance_logger.log_performance
def example_function(n):
    total = 0
    for i in range(n):
        total += i
    return total

example_function(1000000)

Enhanced Performance Logger

Enhanced performance logging with additional details.

from enhanced_logger import EnhancedLogger

enhanced_performance_logger = EnhancedLogger.configure_enhanced_performance_logger('enhanced_performance_logger')

@enhanced_performance_logger.log_performance
def compute_factorial(n):
    if n == 0:
        return 1
    else:
        return n * compute_factorial(n - 1)

compute_factorial(10)

JSON Formatter

Logs entries in JSON format.

from enhanced_logger import EnhancedLogger

json_logger = EnhancedLogger.configure_json_logger('json_logger')
json_logger.info('This is a test log entry in JSON format.')

You can also log context data.

from enhanced_logger import EnhancedLogger

json_logger = EnhancedLogger.configure_json_logger('json_logger')
context_info = {
    'context': {
        'user_id': 12345,
        'transaction_id': 'abcde12345'
    }
}
json_logger.info('This is a test log entry in JSON format with context.', extra=context_info)

or you can also use decorator.

@EnhancedLogger.json_log('json_logger')
def add(x, y):
    return x + y

@EnhancedLogger.json_log('json_logger')
def multiply(x, y):
    return x * y

print(add(5, 3))
print(multiply(5, 3))

XML Formatter

Logs entries in XML format.

from enhanced_logger import EnhancedLogger

xml_logger = EnhancedLogger.configure_xml_logger('xml_logger')
xml_logger.info('This is a test log entry in XML format.')

HTTP Handler

Sends log entries to a remote server via HTTP. (Assumes a logging endpoint is available)

from enhanced_logger import EnhancedLogger

http_logger = EnhancedLogger.configure_http_logger('http_logger', 'http://example.com/log', method='POST', headers={'Content-Type': 'application/json'})
http_logger.info('This is a test log entry sent via HTTP.')

DB Handler

Stores log entries in various types of databases likes SQLite/Postgres/MongoDB.

SQLite

from enhanced_logger import EnhancedLogger

sqlite_logger = EnhancedLogger.configure_db_logger('sqlite_logger', 'sqlite', {'db_path': 'logs.db'})
sqlite_logger.info('This is a test log entry stored in a SQLite database.')

PostgreSQL

from enhanced_logger import EnhancedLogger
postgres_logger = EnhancedLogger.configure_db_logger('postgres_logger', 'postgres', {
    'dbname': 'testdb',
    'user': 'dbuser',
    'password': 'dbpass',
    'host': 'localhost',
    'port': 5432
})
postgres_logger.info('This is a test log entry stored in a PostgreSQL database.')

MongoDB

from enhanced_logger import EnhancedLogger
mongodb_logger = EnhancedLogger.configure_db_logger('mongodb_logger', 'mongodb', {
    'uri': 'mongodb://localhost:27017/',
    'db_name': 'testdb'
})
mongodb_logger.info('This is a test log entry stored in a MongoDB database.')

More Examples

You can also store logs in a .log file by specifying file name for the log_to_file argument.

from enhanced_logger import EnhancedLogger

# JSON Logger
@EnhancedLogger.json_log('json_logger', log_to_file='json_logs.log')
def add(x, y):
    return x + y

print(add(5, 3))


# Performance Logger
performance_logger = EnhancedLogger.configure_performance_logger('performance_logger', log_to_file='performance_logs.log')

@performance_logger.log_performance
def compute_factorial(n):
    if n == 0:
        return 1
    else:
        return n * compute_factorial(n - 1)

print(compute_factorial(10))

# HTTP Logger
from enhanced_logger import EnhancedLogger

http_logger = EnhancedLogger.configure_http_logger('http_logger', 'http://example.com/log', method='POST', headers={'Content-Type': 'application/json'}, log_to_file='http_logs.log')
http_logger.info('This is a test log entry sent via HTTP.')

Metadata

Release files for enhanced-logger 0.1.3

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

Source distribution (sdist)

Source distribution for enhanced-logger 0.1.3
File Size Uploaded Provenance Actions
enhanced_logger-0.1.3.tar.gz 5.8 kB Without provenance Details for enhanced_logger-0.1.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for enhanced-logger 0.1.3
File Interpreter ABI Platform Actions
enhanced_logger-0.1.3-py3-none-any.whl Python 3 none any Details for enhanced_logger-0.1.3-py3-none-any.whl

Total release size: 11.6 kB

Release files / enhanced_logger-0.1.3.tar.gz

Download URL enhanced_logger-0.1.3.tar.gz
Size 5.8 kB
Tags Source
SHA-256 checksum
How to use checksums
ab1af8a4e0937f985a679d71a9e7a0a04c2488f5ae9ed6f4108d2e1888bfe342
BLAKE2b-256 checksum
How to use checksums
dcd07494c4cb3d50b258bf7fef13d603931ac8edbdecc8d25ee3f971235069bb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.3

Release files / enhanced_logger-0.1.3-py3-none-any.whl

Download URL enhanced_logger-0.1.3-py3-none-any.whl
Size 5.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7193de5e7decb2d81aeb4bef0690f30a1500718a95ddc4e47017cb1c957a5e3b
BLAKE2b-256 checksum
How to use checksums
53a7180390741d7695992b3d6ea3913e29ede3a154c57da78284edbda290cb6a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.3

Security for enhanced-logger 0.1.3

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.

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