A hierarchical, context-manager logger utility with multiprocess mapping capabilities
Project description
logmap
A hierarchical, context-manager logger utility with multiprocess mapping capabilities
Install
!pip install git+https://github.com/quadrismegistus/logmap
Usage
from logmap import logmap
Basic usage
with logmap('testing...'):
# ... do something ...
pass
testing... @ 2023-12-12 12:58:19,866
⎿ 0 seconds @ 2023-12-12 12:58:19,867
Getting duration
# get duration
with logmap('testing...') as lm:
naptime = lm.nap()
testing... @ 2023-12-12 12:58:19,874
│ napping for 0.4 seconds @ 2023-12-12 12:58:19,875
⎿ 0.4 seconds @ 2023-12-12 12:58:20,280
assert naptime == lm.duration
Nested logging
with logmap('testing nested logging') as lm:
with logmap('opening nest level 2') as lm2:
with logmap('opening nest level 3') as lm3:
lm3.nap()
testing nested logging @ 2023-12-12 12:58:20,292
│ opening nest level 2 @ 2023-12-12 12:58:20,293
│ │ opening nest level 3 @ 2023-12-12 12:58:20,294
│ │ │ napping for 0.3 seconds @ 2023-12-12 12:58:20,294
│ │ ⎿ 0.3 seconds @ 2023-12-12 12:58:20,599
│ ⎿ 0.3 seconds @ 2023-12-12 12:58:20,600
⎿ 0.3 seconds @ 2023-12-12 12:58:20,601
Mapping
import random,time
# get objs to map
objs = list(range(5))
# define function to map
def function_to_map(naptime):
naptime = random.random() * naptime / 2
time.sleep(naptime)
return naptime
# open the logmap
with logmap('testing function mapping') as lm:
# get results as a list
results = lm.map(function_to_map, objs, num_proc=2)
testing function mapping @ 2023-12-12 13:00:31,037
│ mapping function_to_map to 5 objects [2x]: 100%|██████████| 5/5 [00:02<00:00, 2.09it/s]
⎿ 2.4 seconds @ 2023-12-12 13:00:33,433
Or get a generator for results as they arrive (in order):
with logmap('testing function mapping') as lm:
# this is a generator
results_iter = lm.imap(function_to_map, objs, num_proc=2)
# loop as results arrive
for res in results_iter:
# this will update progress bar
lm.log(f'got result: {res:.02}')
testing function mapping @ 2023-12-12 13:01:23,981
│ got result: 1.7 [2x]: 100%|██████████| 5/5 [00:02<00:00, 1.99it/s]
⎿ 2.5 seconds @ 2023-12-12 13:01:26,500
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file logmap-0.2.0.tar.gz.
File metadata
- Download URL: logmap-0.2.0.tar.gz
- Upload date:
- Size: 21.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
809fcafea4f3bc0a6f24b30ae0b9e7788d89ddf72fa24f6a9f840497d982771c
|
|
| MD5 |
68b3638d79a5d19f45572f0953d1782e
|
|
| BLAKE2b-256 |
2169be14275ded57c7a3dbce93ecded926316a373217c3fe07654b8ddf2b9e72
|
Provenance
The following attestation bundles were made for logmap-0.2.0.tar.gz:
Publisher:
publish.yml on quadrismegistus/logmap
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
logmap-0.2.0.tar.gz -
Subject digest:
809fcafea4f3bc0a6f24b30ae0b9e7788d89ddf72fa24f6a9f840497d982771c - Sigstore transparency entry: 1340593985
- Sigstore integration time:
-
Permalink:
quadrismegistus/logmap@83225fe52f836652863e663d0cbfa6001860dc73 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/quadrismegistus
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@83225fe52f836652863e663d0cbfa6001860dc73 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file logmap-0.2.0-py3-none-any.whl.
File metadata
- Download URL: logmap-0.2.0-py3-none-any.whl
- Upload date:
- Size: 19.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
26c11ba16284b93dea62f39218c74b48400929301187cdddb10cd0fe55fed538
|
|
| MD5 |
c24f5f9743dffe05ad1fc44133653ae8
|
|
| BLAKE2b-256 |
68457e9ab7afcc5eef472f39d8b3c131b692dc76b3483dcdfecd8603f6e2b307
|
Provenance
The following attestation bundles were made for logmap-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on quadrismegistus/logmap
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
logmap-0.2.0-py3-none-any.whl -
Subject digest:
26c11ba16284b93dea62f39218c74b48400929301187cdddb10cd0fe55fed538 - Sigstore transparency entry: 1340593986
- Sigstore integration time:
-
Permalink:
quadrismegistus/logmap@83225fe52f836652863e663d0cbfa6001860dc73 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/quadrismegistus
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@83225fe52f836652863e663d0cbfa6001860dc73 -
Trigger Event:
workflow_dispatch
-
Statement type: