Skip to main content

JSON logging logger formatter

说明

Python JSON 日志记录器对象和格式化器。

记录器处理了线程隔离,可以设置全局参数和线程局部参数。

链接

安装

pip install py-ztj-json-logging

使用

# 定义格式化器
formatter = JsonFormatter()
formatter.set_ensure_ascii(False)
formatter.set_indent(4)

# 定义处理器
handler = logging.StreamHandler()
handler.setLevel(logging.DEBUG)
handler.setFormatter(formatter)

# 定义记录器
logger = JsonLogger(__name__)
logger.addHandler(handler)

# 全局参数
logger.glob('全局参数', '这是一个全局参数,在所有的线程中有效')


logger.info('主线程日志输出 Start')


def thread_1():
    logger.set('局部参数', '这是一个局部的参数,只在线程一日志中有效')
    logger.info('线程一日志输出')


def thread_2():
    time.sleep(1)
    logger.info('线程二日志输出')


logger.info('主线程日志输出 End')


t1 = threading.Thread(target=thread_1, args=())
t2 = threading.Thread(target=thread_2, args=())
t1.start()
t2.start()

Metadata

Release files for py-ztj-json-logging 1.0.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 py-ztj-json-logging 1.0.0
File Size Uploaded
py-ztj-json-logging-1.0.0.tar.gz 2.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for py-ztj-json-logging 1.0.0
File Interpreter ABI Platform
py_ztj_json_logging-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 6.0 kB

Release files / py-ztj-json-logging-1.0.0.tar.gz

Download URL py-ztj-json-logging-1.0.0.tar.gz
Size 2.5 kB
Tags Source
SHA-256 checksum
How to use checksums
5d8a8cd4eedd2d7d595a4dc4f8b93523bdcf8c3849ff9d8068236e72d65b47a8
BLAKE2b-256 checksum
How to use checksums
c192e0602efc961e954daac2b02e229d8ea438684d231520212bd872c0186473
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.9.0

Release files / py_ztj_json_logging-1.0.0-py3-none-any.whl

Download URL py_ztj_json_logging-1.0.0-py3-none-any.whl
Size 3.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cdf5e659bf75c810d4e44a338d8aef2fb09f7ddfadad1cad71fff7cfcbcffe6e
BLAKE2b-256 checksum
How to use checksums
a6982130de6947cb165fe1eb05cfee37ad45764348834bdf7d4d9b1bb0b8af27
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.9.0

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

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