Skip to main content

SparkleLogging日志库 [new]

Sparkle!

描述

新的 SparkleLogging日志库是从底层开始写起来的,并没有基于logging标准库往上搭建,所以功能暂时不完善,

CAUTION

注意,虽然我在需要共享资源的地方使用了 "with lock" 来确保线程安全,但这个日志库是我从底层开始编写的, 我无法绝对保证在多线程、多进程或异步环境中的绝对安全性。如果在特定环境下遇到问题,请务必审慎考虑并进行适当的调整。

Get started

一般来说,你只需要简单的

from SparkleLogging import logger

# 就可以开始记录日志

logger.trace("test")
logger.debug("test")
logger.info("test")
logger.warning("test")
logger.error("test")
logger.fatal("test")

更新了setLevel接口用于设置日志级别过滤

  • 同时修复了一个addNewLevel可能会覆盖自己日志库定义等级的bug
from SparkleLogging import logger
from SparkleLogging.core._level import Levels

logger.setLevel(Levels.INFO)

logger.trace("Trace message") # 过滤
logger.debug("Debug message") # 过滤
logger.info("Info message")
logger.warning("Warning message")
logger.error("Error message")
logger.fatal("fatal message")

# 添加了addNewLevel方法来提升灵活性

```python
from SparkleLogging import logger

TEST = 25
logger.addNewLevel("test", TEST, 91, "bright_magenta")

logger.log(TEST, "test")

更新了FileHandler,保证了部分线程安全

from SparkleLogging import logger
from SparkleLogging.core._handler import FileHandler
from SparkleLogging.core._formatter import Formatter

filehandler = FileHandler(filename="test.log", mode="a+")
fmts = Formatter() #懒得设置格式直接这样也行
filehandler.setFormatter(fmts)
logger.addHandler(filehandler)

logger.trace("Trace message")
logger.debug("Debug message")
logger.info("Info message")
logger.warning("Warning message")
logger.error("Error message")
logger.fatal("fatal message")

# 别忘了显示调用close方法释放资源
filehandler.close()

close方法写在了logger中,可以直接调用logger.close()方法来释放资源

from SparkleLogging import logger
from SparkleLogging.core._handler import FileHandler
from SparkleLogging.core._formatter import Formatter

filehandler = FileHandler(filename="test.log", mode="a+")
fmts = Formatter()
filehandler.setFormatter(fmts)
logger.addHandler(filehandler)

logger.trace("Trace message")
logger.debug("Debug message")
logger.info("Info message")
logger.warning("Warning message")
logger.error("Error message")
logger.fatal("fatal message")

#可以直接调用logger.close()方法释放资源,但是注意
# 这个close方法是释放所有的handler的资源比如线程之类的,如果你想要精确控制时机,最好还是手动调用每个handler的close方法
# fliehandler.close()
logger.close()

Metadata

Release files for SparkleLogging-new 1.0.1

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

Source distribution (sdist)

Source distribution for SparkleLogging-new 1.0.1
File Size Uploaded Provenance Actions
SparkleLogging-new-1.0.1.tar.gz 9.0 kB Without provenance Details for SparkleLogging-new-1.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for SparkleLogging-new 1.0.1
File Interpreter ABI Platform Actions
SparkleLogging_new-1.0.1-py3-none-any.whl Python 3 none any Details for SparkleLogging_new-1.0.1-py3-none-any.whl

Total release size: 20.1 kB

Release files / SparkleLogging-new-1.0.1.tar.gz

Download URL SparkleLogging-new-1.0.1.tar.gz
Size 9.0 kB
Tags Source
SHA-256 checksum
How to use checksums
4f1511e605ce7e658fbb7542bf5496b23819c9b0dfdf1c3a04e407ad90d51195
BLAKE2b-256 checksum
How to use checksums
f9ba33066d25bcb1722a843b8ab3325823fae2aa4e90935f29823ca44a256c61
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.3

Release files / SparkleLogging_new-1.0.1-py3-none-any.whl

Download URL SparkleLogging_new-1.0.1-py3-none-any.whl
Size 11.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
36b961f154bd8b976b9d8d0c33d7694b750d38961b11b5e7847e8c50a480edb6
BLAKE2b-256 checksum
How to use checksums
78461c3baa307a0f492f1d292e4583aa9f0a44c3e40c250054401d8f205dee5c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.3

Security for SparkleLogging-new 1.0.1

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.

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files No provenance

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