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.2.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

isolated_logging-0.0.2-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: isolated_logging-0.0.2.tar.gz
  • Upload date:
  • Size: 6.3 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.2.tar.gz
Algorithm Hash digest
SHA256 a22570cb8bf66c1e8e2ca985b26ae7f439a45fd54d94803c86a9d395adf84d1e
MD5 343af1a3cf450be15e03213b835dc8aa
BLAKE2b-256 b8f0383ada71c1df6f0322823a4e4838c08c0d810e25b3e4583b7600ca52bd5c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for isolated_logging-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ee491658d75fa3a0b2f062e1ae55d3582c6606c227ce0a9062f0ecf742fad91b
MD5 81b2b13c4a7fc62a3e60eb74a884025a
BLAKE2b-256 ffcb28b26073dd40c80817c0fbeb8e48717b8b2bb54bb1f78b09e575a6a840e1

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