Skip to main content

tasklogger

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

Metadata

Release files for tasklogger 1.2.0

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

Source distribution (sdist)

Source distribution for tasklogger 1.2.0
File Size Uploaded
tasklogger-1.2.0.tar.gz 16.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tasklogger 1.2.0
File Interpreter ABI Platform
tasklogger-1.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 30.6 kB

Release files / tasklogger-1.2.0.tar.gz

Download URL tasklogger-1.2.0.tar.gz
Size 16.0 kB
Tags Source
SHA-256 checksum
How to use checksums
b0a390dbe1d4c6f7465e58ee457b5bb381657b5ede3a85bcf45199cb56ac01a4
BLAKE2b-256 checksum
How to use checksums
0849284c99df2cbe3a0d6df5a3d5010dfc5d425bb332f5b04739af469703f9f5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Release files / tasklogger-1.2.0-py3-none-any.whl

Download URL tasklogger-1.2.0-py3-none-any.whl
Size 14.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b320fcabbb6bbd88e63c65cd994d75038c2cde45b58eb28941c3848710855524
BLAKE2b-256 checksum
How to use checksums
d6f524855d6d8862ad03ae4dbb8f3ec06baf930a276c92af603b3d9bf32600d0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Release history Release notifications | RSS feed

This release

1.2.0 This release

2 release files

1.1.2

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.4.2

3 release files

0.4.1

3 release files

0.4.0

2 release files

0.3.0

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.2

1 release file

0.1

1 release file

0.0

1 release file

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