Skip to main content

一个全局拦截日志并转为loguru日志的插件

Project description

一个全局拦截日志并转为loguru日志的插件

Package version Supported Python versions

安装

pip install 'usepy[logger]'

使用

from usepy import useLogger

useLogger()  # 使用默认配置

如果你自身项目正在使用loguru,这一切似乎感觉毫无变化。因为默认的配置只是修改了一点输出样式。

如果想要感受它带来的“魔法”,需要稍微配置一下。

from usepy import useLogger

useLogger(packages=["scrapy", "django", "usepy"])
Logstash/Filebeat

日志的更重要能力是将日志记录发送到Logstash/Filebeat,这样就可以将日志记录存储到Elasticsearch 中,方便进行日志分析。所以统一日志的最终输出格式是非常重要的。

useLogger内置一个logstash_handler统一化输出格式。

from loguru import logger
from usepy import useLogger, useLoggerHandlers

useLogger(
    handlers=[
        useLoggerHandlers.logstash_handler(level="DEBUG", extra={"app_name": "spider"})
    ],
    packages=["usepy"],  # hook拦截 usepy 的日志
    extra={"project_name": "usepy"}
)
logger.warning("test warning")
logger.info("test info")
logger.debug("test debug")

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

usepy_plugin_logger-0.1.6.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

usepy_plugin_logger-0.1.6-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file usepy_plugin_logger-0.1.6.tar.gz.

File metadata

  • Download URL: usepy_plugin_logger-0.1.6.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.10.12 Linux/5.15.0-1041-azure

File hashes

Hashes for usepy_plugin_logger-0.1.6.tar.gz
Algorithm Hash digest
SHA256 7d3192dfe7d447fb7e2c063a30540df69ea3aa6e9c3aba1e45818e6d4f3cd490
MD5 05b91da8ad0318644f0be3a3ed69cbff
BLAKE2b-256 0972dabc46b9e637aa85fdc2dcaca66e734b08034b81825c1cc0100a027b7ae3

See more details on using hashes here.

File details

Details for the file usepy_plugin_logger-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: usepy_plugin_logger-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.10.12 Linux/5.15.0-1041-azure

File hashes

Hashes for usepy_plugin_logger-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 1fc04c9051d1dd8c21d86171f8a73026e9620379a944c244d1ec4d8bf109e36f
MD5 4b0c0ff02b66f595b09d14776fbd29bf
BLAKE2b-256 697c59dc316e081ac44e980c25e1d43671dad3d9c5fb1d106ff35bece0a65e05

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