python json logging logger formatter
Project description
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()
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
Close
Hashes for py-ztj-json-logging-1.0.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d8a8cd4eedd2d7d595a4dc4f8b93523bdcf8c3849ff9d8068236e72d65b47a8 |
|
MD5 | d748105ca377a30f8d8bb84186542d6f |
|
BLAKE2b-256 | c192e0602efc961e954daac2b02e229d8ea438684d231520212bd872c0186473 |
Close
Hashes for py_ztj_json_logging-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cdf5e659bf75c810d4e44a338d8aef2fb09f7ddfadad1cad71fff7cfcbcffe6e |
|
MD5 | a787c17f876e54b74a4743a0d004402e |
|
BLAKE2b-256 | a6982130de6947cb165fe1eb05cfee37ad45764348834bdf7d4d9b1bb0b8af27 |