Skip to main content

一个全局拦截日志并转为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")

Metadata

Release files for usepy-plugin-logger 0.1.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for usepy-plugin-logger 0.1.6
File Size Uploaded Provenance
usepy_plugin_logger-0.1.6.tar.gz 4.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for usepy-plugin-logger 0.1.6
File Interpreter ABI Platform
usepy_plugin_logger-0.1.6-py3-none-any.whl Python 3 none any Details

Total release size: 11.1 kB

Release files / usepy_plugin_logger-0.1.6.tar.gz

Download URL usepy_plugin_logger-0.1.6.tar.gz
Size 4.7 kB
Tags Source
SHA-256 checksum
How to use checksums
7d3192dfe7d447fb7e2c063a30540df69ea3aa6e9c3aba1e45818e6d4f3cd490
BLAKE2b-256 checksum
How to use checksums
0972dabc46b9e637aa85fdc2dcaca66e734b08034b81825c1cc0100a027b7ae3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.10.12 Linux/5.15.0-1041-azure

Release files / usepy_plugin_logger-0.1.6-py3-none-any.whl

Download URL usepy_plugin_logger-0.1.6-py3-none-any.whl
Size 6.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1fc04c9051d1dd8c21d86171f8a73026e9620379a944c244d1ec4d8bf109e36f
BLAKE2b-256 checksum
How to use checksums
697c59dc316e081ac44e980c25e1d43671dad3d9c5fb1d106ff35bece0a65e05
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.10.12 Linux/5.15.0-1041-azure

Security for usepy-plugin-logger 0.1.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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