Skip to main content

Classe que implementa um logger com funções de log performance, log error, log warning, log info, log debug, log critical, log alert, log emergency, log warning, log error, log critical, log alert, log emergency

Project description

LogPerformance

A Python logging utility class that provides performance monitoring, error tracking, and colored console output with file logging capabilities.

Class Overview

LogPerformance is a singleton class that implements a comprehensive logging system with the following features:

  • Colored console output
  • File logging with timestamp-based filenames
  • Performance monitoring for functions
  • Error tracking
  • Warning messages
  • Custom log levels

Methods

__new__(cls, *args, **kwargs)

Singleton pattern implementation that ensures only one instance of the class exists.

__init__(self)

Initializes the logger with:

  • Colored console output handler
  • File logging handler (if enabled)
  • Custom log level configuration
  • Directory creation for log files

check_exists_directory(work_directory: str) -> bool

Static method that checks if a directory exists.

create_directory(cls, work_directory: str) -> None

Class method that creates a directory if it doesn't exist and logs the creation.

log_performance(self, func: Callable) -> Callable

Decorator that measures and logs the execution time of a function.

  • Logs function name, arguments, and execution time
  • Returns the function's result

log_error(self, func: Callable) -> Callable

Decorator that catches and logs exceptions in a function.

  • Logs the function name and error message
  • Re-raises the exception after logging

log_warning(self, func: Callable) -> Callable

Decorator that logs warnings for function execution.

  • Logs function name, arguments, and execution time
  • Returns the function's result

info(self, msg: str) -> None

Logs an informational message with a smile emoji prefix.

warning(self, msg: str) -> None

Logs a warning message.

error(self, msg: str) -> None

Logs an error message with an exclamation mark emoji prefix.

_append_log_message(self, msg: str, level: int) -> None

Private method that appends log messages with timestamp and level.

  • Handles debug level filtering
  • Stores the last log message

Usage Example

from logperformance import LogPerformance

log = LogPerformance()

@log.log_performance
def example_function(arg1, arg2):
    # Your code here
    pass

@log.log_error
def error_prone_function():
    # Your code here
    pass

# Log messages
log.info("This is an info message")
log.warning("This is a warning")
log.error("This is an error")

Configuration

The logger can be configured using environment variables:

  • LOG_LEVEL: Set to "DEBUG" for debug level logging
  • DEBUG_WRITE_FILE: Set to "True" to enable file logging (default)

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

logperformance-1.0.0.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

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

logperformance-1.0.0-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file logperformance-1.0.0.tar.gz.

File metadata

  • Download URL: logperformance-1.0.0.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.13.3 Linux/6.11.0-1012-azure

File hashes

Hashes for logperformance-1.0.0.tar.gz
Algorithm Hash digest
SHA256 3d784716afd9e7ef3939c4e496663f8c036d25bf3b607e90142d3c679b3cd9e5
MD5 b4e3f59895c790f47f7a51e2f885beb1
BLAKE2b-256 5472fa162d8bd2ffd9c34b5903f2f3948644d28680a9afd641f5929d5cdbc685

See more details on using hashes here.

File details

Details for the file logperformance-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: logperformance-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 3.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.13.3 Linux/6.11.0-1012-azure

File hashes

Hashes for logperformance-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3a21995b7aa4d3ab22d4bd700ba25511772fb2b6bb3401aafbe8055fccbbeb91
MD5 e8a3bc4160a238ea3be0a76438f0dea3
BLAKE2b-256 1b820ee8c2912fd00a57dcb4bc86518c5432a256b93b5b5f41b7f7b7bb421829

See more details on using hashes here.

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