Skip to main content

log.client

一款Python日志客户端,支持直接写入Elasticsearch。


v1.2.0:

新功能

1、支持ElasticSearch最小安全性设置。

v1.1.1:

功能优化:

1、支持批量写入Elasticsearch(依赖Elasticsearch包)。

2、增加日志队列慢的异常处理。


Usage:

1、创建配置文件config.ini:

[log]
app_name = YOUR-APPNAME
es_urls = http://es-ip:9200
es_index_name = applog-20221228
# 1.2.0版本新增配置
es_username = elastic
es_password = search

app_name: 应用名称
es_urls: Elasticsearch 地址。填写多个时,用,分隔。
es_index_name: Elasticsearch 索引名称

2、创建配置文件logging.ini:

[loggers]
keys=root

[handlers]
keys=consoleHandler,qHandler

[formatters]
keys=simpleFmt,detailFmt

[logger_root]
level=DEBUG
handlers=consoleHandler,qHandler

[handler_consoleHandler]
class=StreamHandler
level=DEBUG
formatter=detailFmt
args=(sys.stdout,)

[handler_qHandler]
class=qlog.logger.QlogHandler
level=INFO
formatter=simpleFmt
args=()

[formatter_detailFmt]
format="%(asctime)-15s %(levelname)s %(filename)s %(funcName)s lineNo: %(lineno)d details: %(message)s"

[formatter_simpleFmt]
format="%(message)s"

3、日志写入测试

import logging
import logging.config
from time import sleep

logging.config.fileConfig('logging.ini')
logger = logging.getLogger('root')
logger.info('这是一条中文字符测试日志')
logger.info('this is a info log.')
logger.warning('this is a warning log.')
sleep(30)

4、查看Elasticsearch日志

img.png

Download files

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

Source Distribution

log.client-1.2.1.tar.gz (5.7 kB view details)

Uploaded Source

File details

Details for the file log.client-1.2.1.tar.gz.

File metadata

  • Download URL: log.client-1.2.1.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.7

File hashes

Hashes for log.client-1.2.1.tar.gz
Algorithm Hash digest
SHA256 b7a883217e1570023f1f2b9a7a17e136d3f10bfe743bc5418be80eee712a4b3d
MD5 977e64905a6f91f389932de7dac9107a
BLAKE2b-256 a7e146797ef3d9acb030d8c7e1938953b79418e97087cc25febda8550a0284b2

See more details on using hashes here.

Release history Release notifications | RSS feed

1.2.6

2 files

1.2.2

1 file

This release

1.2.1 This release

1 file

1.1.1

1 file

1.0.0

2 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