A package for advanced logging and visualization of Python objects, especially tensors.
Project description
Core features
Log data as tables, and then render them as entries in web log viewer with extremely simple functions !
Additional Features
best_logger.print_basic
- Format and log lists, dictionaries, nested dictionaries, and other structures using richly styled tables.
- Functions:
print_list: Log lists in a structured table format.print_dict: Log flat dictionaries with keys and values.print_listofdict: Log a list of dictionaries as rows in a table.print_dictofdict: Log nested dictionaries as a table.sprintf_nested_structure: View nested structures hierarchically in plain text.
best_logger.print_tensor
- Specialized features for PyTorch tensors:
print_tensor: Log tensor attributes (shape, dtype, device) with a preview.print_tensor_dict: Log a dictionary of tensors with detailed attributes (handles exceptions gracefully).
- Automatically limits preview content for long tensors.
from best_logger import *
# === log nested dictionaries as table ===
print_dictofdict({
'sample-1':{
"a": 1,
"b": 2,
"c": 3,
},
'sample-2':{
"a": 4,
"b": 5,
"c": 6,
}
}, narrow=True, header="this is a header", mod="", attach="create a copy button in web log viewer, when clicked, copy this message into clipboard")
# ╭─────────────── this is a header ───────────────╮
# │ ┏━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━┳━━━━━━┳━━━━━━┓ │
# │ ┃ ┃ a ┃ b ┃ c ┃ │
# │ ┡━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━╇━━━━━━╇━━━━━━┩ │
# │ │ sample-1 │ 1 │ 2 │ 3 │ │
# │ ├──────────────────────┼───────┼──────┼──────┤ │
# │ │ sample-2 │ 4 │ 5 │ 6 │ │
# │ └──────────────────────┴───────┴──────┴──────┘ │
# ╰────────────────────────────────────────────────╯
# === log a list of dictionaries as table ===
print_listofdict(
[{
"a": 1,
"b": 2,
"c": 3,
},
{
"a": 4,
"b": 5,
"c": 6,
}], narrow=True)
# ╭────────────────────────────────────────────────╮
# │ ┏━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━┓ │
# │ ┃ ┃ a ┃ b ┃ c ┃ │
# │ ┡━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━┩ │
# │ │ 0 │ 1 │ 2 │ 3 │ │
# │ ├───────────┼──────────┼──────────┼──────────┤ │
# │ │ 1 │ 4 │ 5 │ 6 │ │
# │ └───────────┴──────────┴──────────┴──────────┘ │
# ╰────────────────────────────────────────────────╯
# === log dictionary as table ===
print_dict({
"a": 1,
"b": 2,
"c": 3,
}, mod="abc")
# ╭────────────────────────────────────────────────╮
# │ ┌──────────────────────┬─────────────────────┐ │
# │ │ a │ 1 │ │
# │ ├──────────────────────┼─────────────────────┤ │
# │ │ b │ 2 │ │
# │ ├──────────────────────┼─────────────────────┤ │
# │ │ c │ 3 │ │
# │ └──────────────────────┴─────────────────────┘ │
# ╰────────────────────────────────────────────────╯
Quick Start
-
install:
pip install beast-logger -i https://pypi.org/simple -
import
from best_logger import *
-
register file handler
def register_logger(mods=[], non_console_mods=[], base_log_path="logs", auto_clean_mods=[]): """ mods: 需要注册的模块名列表,同时向终端和文件输出 non_console_mods: 需要注册的模块名列表,只向文件输出 base_log_path: 日志文件存放的根目录 auto_clean_mods: 需要自动删除旧日志的模块名列表 """
-
begin logging
from best_logger import * register_logger(mods=["abc"]) print_dict({ "a": 1, "b": 2, "c": 3, }, mod="abc")
-
install nvm
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash -
launch web display on port 8181 (first time)
python -m web_display.install 8181or simplybeast_logger_install -
launch web display on port 8181 (skip npm install)
python -m web_display.go 8181or simplybeast_logger_go -
open in browser
http://localhost:8181
- test program and enter log dir (absolute path) into web log viewer.
from best_logger import * register_logger(mods=["abc"]) print_dict({ "a": 1, "b": 2, "c": 3, }, mod="abc")
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 beast_logger-0.1.0.tar.gz.
File metadata
- Download URL: beast_logger-0.1.0.tar.gz
- Upload date:
- Size: 2.3 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
511500571146b49da8e83d87c6f17021835413f6b2172bb5e6b3760b9e050df2
|
|
| MD5 |
f3f9632e05376ae1fe3933a9a50be88f
|
|
| BLAKE2b-256 |
72669bdfea6981f96f107fb64f8885030f14c4e9efb158e0b814fbbf1199536a
|
File details
Details for the file beast_logger-0.1.0-py3-none-any.whl.
File metadata
- Download URL: beast_logger-0.1.0-py3-none-any.whl
- Upload date:
- Size: 2.3 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fe3c1103643da942e32ecd04e924e3e51e7962522820eaf6f87ae9d6a13817bc
|
|
| MD5 |
45701143ef978c7b48c05ae7f9d0cc1f
|
|
| BLAKE2b-256 |
8b2fc6d4834f070b31a6ec2a79863f96e15a9657f9626ee9e92dff0c5587b435
|