Skip to main content

A Python library for tracking and logging function and loop execution times with stats and color-coded logs for easy performance monitoring and optimization.

Project description

Isolated Logging

Isolated Logging is a lightweight Python library for tracking and logging the performance of functions and loops showing them in an isolated way (color-coding and dedicated loggers or files). It helps developers assess and optimize their code by monitoring execution times and calculating statistics like average time per iteration, standard deviations, and estimated completion times.

Features

  • Function and Loop Execution Time Tracking: Measures execution times and logs details about each iteration.
  • Performance Statistics: Provides averages, standard deviations, and estimated time remaining.
  • Logging to Temporary or Specified File: Option to log messages and statistics to a temporary log file or a custom file path.
  • Color-coded Console Output: Uses ANSI escape codes to improve readability in terminal output.
  • Customizable Logging Options: Flexible setup options for independent logging, with decorator-based function timing and loop performance monitoring.

Installation

Simply clone this repository:

git clone https://github.com/jurrutiag/isolated-logging.git

Usage

1. Setting Up Logging

To begin, set up logging by calling setup_log_file_and_logger() at the start of your script. For this you either have to provide a logger or set setup_independent_logging=True.

from isolated_logging import setup_log_file_and_logger

# Set up logging to a temporary file
setup_log_file_and_logger(setup_independent_logging=True)

2. Timing Functions

Use the log_timed_function decorator to time a function and track its execution stats.

from isolated_logging import log_timed_function

@log_timed_function(ignore_instant_returns=True, threshold=0.001)
def your_function():
    # Your function logic
    pass

3. Timing Loops

Wrap your loops with log_timed_loop to measure and log each iteration’s execution time. If the iterable is a list it will also calculate ETA and tell you how many loops are left.

from isolated_logging import log_timed_loop

for item in log_timed_loop(your_iterable, loop_name="Processing Items"):
    # Process each item
    pass

Example

import time
from isolated_logging import log_timed_function, log_timed_loop, setup_log_file_and_logger

setup_log_file_and_logger(setup_independent_logging=True)

@log_timed_function(ignore_instant_returns=True, threshold=0.001)
def sample_function(n):
    time.sleep(n)

for _ in log_timed_loop(range(5), loop_name="Sample Loop"):
    sample_function(0.5)

License

This project is licensed under the MIT License. See LICENSE for details.

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

isolated_logging-0.0.3.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

isolated_logging-0.0.3-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file isolated_logging-0.0.3.tar.gz.

File metadata

  • Download URL: isolated_logging-0.0.3.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.12

File hashes

Hashes for isolated_logging-0.0.3.tar.gz
Algorithm Hash digest
SHA256 c68f3f25fbd85781b29da956f5cb74579b1ea493c1f5ca0e9430dac6e270b5bb
MD5 68083a2a1a806a71ae8e2116aa5be1bc
BLAKE2b-256 b5f34992e17f80e983575e3f7d56aef1f5d2f0e58e92925892897024544158ec

See more details on using hashes here.

File details

Details for the file isolated_logging-0.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for isolated_logging-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 4875ab4948e5f269e6d1a3720fd37c3554c2119c2a262ea086bd03c28d53dec1
MD5 f05fd932664bc8b329c8e95b7a071b07
BLAKE2b-256 03a23a43fe7d4f3719e595fa728c95bc2b2fb401a0231cc4d4d268922b741234

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page