Skip to main content

A logging library for Python

Project description

NsparkleLog日志库

Sparkle!

描述

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

CAUTION

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

Get started

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

from NsparkleLog import logger

# 就可以开始记录日志

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

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

  • 同时修复了一个addNewLevel可能会覆盖自己日志库定义等级的bug
from NsparkleLog import logger
from NsparkleLog.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方法来提升灵活性

from NsparkleLog import logger

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

logger.log(TEST, "test")

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

from NsparkleLog import logger
from NsparkleLog.core._handler import FileHandler
from NsparkleLog.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 NsparkleLog import logger
from NsparkleLog.core._handler import FileHandler
from NsparkleLog.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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

NsparkleLog-1.0.1.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

NsparkleLog-1.0.1-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file NsparkleLog-1.0.1.tar.gz.

File metadata

  • Download URL: NsparkleLog-1.0.1.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for NsparkleLog-1.0.1.tar.gz
Algorithm Hash digest
SHA256 95e124565c1ab7a76bc212f435716b52c57bf5616dd92d5e53204935c4c875cd
MD5 7e17f1639d09fe4e264e4a9f5bdeb573
BLAKE2b-256 97c5138c24fda3c0118e0ad81e0b813276548066853135b6acc5e878485b2e1c

See more details on using hashes here.

File details

Details for the file NsparkleLog-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: NsparkleLog-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 11.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for NsparkleLog-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 870e030a027b4afd52f0e6e0ca829684cff99954d82452ad1da4b5d24c6a101d
MD5 3fe98a56b47617c90dc5431d5f6cdc7b
BLAKE2b-256 bb595a2d40778f30788d93b5437d665cf02bcd5eb1d06b44de7f9610549c242f

See more details on using hashes here.

Supported by

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