Skip to main content

tasklogger

Project description

Latest PyPi version Latest Conda version GitHub Actions Build Appveyor Build Coverage Status Twitter GitHub stars Code style: black Style Guide: OpenStack pre-commit

An extension to the core python logging library for logging the beginning and completion of tasks and subtasks.

Installation

tasklogger is available on pip. Install by running the following in a terminal:

pip install --user tasklogger

Alternatively, tasklogger can be installed using Conda (most easily obtained via the Miniconda Python distribution):

conda install -c conda-forge tasklogger

Usage examples

Receive timed updates mid-computation using tasklogger.log_start and tasklogger.log_complete:

>>> import tasklogger
>>> import time
>>> tasklogger.log_start("Supertask")
Calculating Supertask...
>>> time.sleep(1)
>>> tasklogger.log_start("Subtask")
  Calculating Subtask...
>>> time.sleep(1)
>>> tasklogger.log_complete("Subtask")
  Calculated Subtask in 1.01 seconds.
>>> time.sleep(1)
>>> tasklogger.log_complete("Supertask")
Calculated Supertask in 3.02 seconds.

Simplify logging syntax with tasklogger.log_task:

>>> import tasklogger
>>> import time
>>> with tasklogger.log_task("Supertask"):
...     time.sleep(1)
...     with tasklogger.log_task("Subtask"):
...        time.sleep(1)
...     time.sleep(1)
Calculating Supertask...
  Calculating Subtask...
  Calculated Subtask in 1.01 seconds.
Calculated Supertask in 3.02 seconds.

Log wall time, CPU time, or any other counter function with the class API:

>>> import tasklogger
>>> import time
>>> logger = tasklogger.TaskLogger(name='cpu_logger', timer='cpu', min_runtime=0)
>>> with logger.log_task("Supertask"):
...     time.sleep(1)
...     with logger.log_task("Subtask"):
...        _ = [[(i,j) for j in range(i)] for i in range(1000)]
...     time.sleep(1)
Calculating Supertask...
  Calculating Subtask...
  Calculated Subtask in 0.09 seconds.
Calculated Supertask in 0.09 seconds.
>>> logger = tasklogger.TaskLogger(name='nano_logger', timer=time.monotonic_ns)
>>> with logger.log_task("Supertask"):
...     time.sleep(1)
...     with logger.log_task("Subtask"):
...        time.sleep(1)
...     time.sleep(1)
Calculating Supertask...
  Calculating Subtask...
  Calculated Subtask in 1001083511.00 seconds.
Calculated Supertask in 3003702161.00 seconds.

Use tasklogger for all your logging needs:

>>> tasklogger.log_info("Log some stuff that doesn't need timing")
Log some stuff that doesn't need timing
>>> tasklogger.log_debug("Log some stuff that normally isn't needed")
>>> tasklogger.set_level(2)
Set TaskLogger logging to DEBUG
>>> tasklogger.log_debug("Log some stuff that normally isn't needed")
Log some stuff that normally isn't needed

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

tasklogger-1.1.2.tar.gz (16.4 kB view details)

Uploaded Source

Built Distribution

tasklogger-1.1.2-py3-none-any.whl (15.5 kB view details)

Uploaded Python 3

File details

Details for the file tasklogger-1.1.2.tar.gz.

File metadata

  • Download URL: tasklogger-1.1.2.tar.gz
  • Upload date:
  • Size: 16.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.12

File hashes

Hashes for tasklogger-1.1.2.tar.gz
Algorithm Hash digest
SHA256 5b443acb73b031f380628926ba8d33952c7a0f6f7115a051222c65b9900a7d84
MD5 d6e3b63871c6f2dee513e4c9c73a8bc2
BLAKE2b-256 c36c389ffaa9ee280ee04ae1b38956f140659984024ec6c90fda48c7667f7cdf

See more details on using hashes here.

File details

Details for the file tasklogger-1.1.2-py3-none-any.whl.

File metadata

  • Download URL: tasklogger-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 15.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.12

File hashes

Hashes for tasklogger-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6c9f9bf82b0866a2c75427f0f52e70087355789a20d46caa712f2b92c51e0891
MD5 944078e1352bee2498801be7bcf807ac
BLAKE2b-256 0884a55b3a5a0e11c3545377642f5e5acb724e3535aa21ef4574a2ae77c8fa83

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