Skip to main content

Easy log library for Elasticsearch

Project description

log.client

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


v1.2.2:

新功能

1、支持通过环境变设置日志组件配置

v1.2.1:

新功能

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.1版本新增配置
es_username = elastic
es_password = search

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

1.2.2 支持同名的环境变量替换config.ini.

优先使用环境变量的设置.
linux:
export app_name=testapp
export es_urls=http://es-ip:9200

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

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

log.client-1.2.2.tar.gz (6.0 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: log.client-1.2.2.tar.gz
  • Upload date:
  • Size: 6.0 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.2.tar.gz
Algorithm Hash digest
SHA256 6278d07b463797ed4230d18dd0f442c795a55bdcedb09e40ae70135d02ce9d41
MD5 10271485f1746ba833702e551269e1e1
BLAKE2b-256 2fadfac819ab2b3b18e4c9cf3a629af6fddc67083ca84de6702685411d8c3d60

See more details on using hashes here.

Supported by

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