A logging library for Python
Project description
SparkleLogging日志库 [new]
描述
新的 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")
添加了addNewLevel方法来提升灵活性
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()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file SparkleLogging-new-1.0.0.tar.gz
.
File metadata
- Download URL: SparkleLogging-new-1.0.0.tar.gz
- Upload date:
- Size: 8.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9282358d4594d9087c4cb5a6397c65be518ba24b813999ec97d89a7e09cb3540 |
|
MD5 | 3b78c6d0f4212ae62e182b8c978f4967 |
|
BLAKE2b-256 | 696f557776d52780e0a9d2efaa581d68f8cf805b04970431dd1fd7a7e6e90ac4 |
File details
Details for the file SparkleLogging_new-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: SparkleLogging_new-1.0.0-py3-none-any.whl
- Upload date:
- Size: 10.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 015e11225407cab40e4bb679fde3fc3de1f789fd0d3cdc21d699a1862556e34d |
|
MD5 | 40720d9fd75e900b6a101a7fa2e42106 |
|
BLAKE2b-256 | 93ef2dbfc8c91b5ea3de8b39af8748651a448585225f48e7301fbb0c95fd678e |