tasklogger
Project description
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.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.task("Supertask"): ... time.sleep(1) ... with logger.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.task("Supertask"): ... time.sleep(1) ... with logger.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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file tasklogger-1.1.0.tar.gz
.
File metadata
- Download URL: tasklogger-1.1.0.tar.gz
- Upload date:
- Size: 16.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.3.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | eb7bf78b30a30c3cdeaae8533276e0daa58480f2596a2b85e1259f2abad5f051 |
|
MD5 | e50211cb20c5373809bdc2b6b1cc5d6e |
|
BLAKE2b-256 | 9ac7fd584f0c351d5ea45311cba9a9178cea90106bb342066b0f082920100b19 |
File details
Details for the file tasklogger-1.1.0-py3-none-any.whl
.
File metadata
- Download URL: tasklogger-1.1.0-py3-none-any.whl
- Upload date:
- Size: 15.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.3.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ba45b3488abc08a53639e8b5b38d9cfca2911daf664010c1929dfb7b2e98aeb0 |
|
MD5 | ec968f2807005bd44f279f177d7ac3e1 |
|
BLAKE2b-256 | 2abad9b56be2de592e106013930718ba3d3bb0154ae55a3a4ab59197324dd60e |