Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py-ztj-json-logging-1.0.0.tar.gz (2.5 kB view details)

Uploaded Source

Built Distribution

py_ztj_json_logging-1.0.0-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file py-ztj-json-logging-1.0.0.tar.gz.

File metadata

  • Download URL: py-ztj-json-logging-1.0.0.tar.gz
  • Upload date:
  • Size: 2.5 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for py-ztj-json-logging-1.0.0.tar.gz
Algorithm Hash digest
SHA256 5d8a8cd4eedd2d7d595a4dc4f8b93523bdcf8c3849ff9d8068236e72d65b47a8
MD5 d748105ca377a30f8d8bb84186542d6f
BLAKE2b-256 c192e0602efc961e954daac2b02e229d8ea438684d231520212bd872c0186473

See more details on using hashes here.

File details

Details for the file py_ztj_json_logging-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: py_ztj_json_logging-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 3.5 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for py_ztj_json_logging-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cdf5e659bf75c810d4e44a338d8aef2fb09f7ddfadad1cad71fff7cfcbcffe6e
MD5 a787c17f876e54b74a4743a0d004402e
BLAKE2b-256 a6982130de6947cb165fe1eb05cfee37ad45764348834bdf7d4d9b1bb0b8af27

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page