This is a lightweight and scalable Python logging library.
Project description
pylogop
This is a lightweight and scalable Python logging library.
Introduce 介绍
This is a lightweight and scalable Python logging library.
It is a library independent from simplepylibs.
这是一个轻量级且可扩展的 Python 日志库。
它是从 simplepylibs 中独立出来的一部分。
Install 安装
The preferred way to install logop is via pip.
推荐使用 pip 安装 logop 。
pip install logop
To upgrade logop to the latest version, use the following command:
要将 logop 升级到最新版本,请使用以下命令:
pip install --upgrade logop
Usage 使用
Basic usage 基础用法
Here is a simple usage example:
以下是一个简单的使用示例:
import logop
logger = logop.Logging()
logger.info("Hello, world!")
logger.debug("This is a debug message.") # This message will not be printed.
You can adjust the logger's log level and format.
您可以调整记录器的日志级别和格式。
logger.set_level(logop.DEBUG)
logger.set_format(logop.FORMAT_DEBUG)
Or set them on instantiation.
或者在实例化时设置它们。
logger = logop.Logging(level=logop.DEBUG, format=logop.FORMAT_DEBUG)
You can also write your own log format.
您还可以编写自己的日志格式。
logger.set_format("[$(.levelname)] $(.message)")
If you want to output a log with color,
then you need to refuse it to automaticallycreate a standard output object when creating logging.
如果你想输出带有颜色的日志,那么你需要拒绝它在创建日志记录器时自动创建一个标准输出对象。
Then add a better output object to it.
然后向其添加一个更好的输出对象。
logger = Logging(stdout=False)
logger.add_op(logop.LogopStandardPlus())
Or you want to output the log to the file.
或者您想将日志输出到文件。
fileobj = logop.LogopFile(directory="logs", filename="$(.date).log")
logger.add_op(fileobj)
Advanced usage 高级用法
You can use custom levels and names to output logs
您可以使用自定义的级别和名称来输出日志。
logger.call(logop.DEBUG, "FINE", "This is a fine message.")
You can also add custom log levels to LEVEL_TABLE
in the following format
您也可以按以下格式将自定义日志级别添加到 LEVEL_TABLE
中。
# ? LEVEL_TABLE[alias] = (level, level_name)
logop.LEVEL_TABLE["fine"] = (logop.DEBUG, "FINE")
Then you can use the alias as the attribute name to output the log directly in the logger.
然后你就可以使用别名作为属性名直接在日志记录器中输出日志。
logger.fine("This is a fine message.")
Add the callabletrack
decorator to a function to track who calls the function,
the parameters provided and its return value.
为函数添加 callabletrack
装饰器可以追踪函数被谁调用、提供的参数及其返回值。
@logop.callabletrack
def test_func(a, b, c):
...
Set exception
of callabletrack
to True
to log exception information.
将 callabletrack
的 exception
设置为 True
可以记录异常信息。
@logop.callabletrack(exception=True)
def test_func(a, b, c):
...
Demo 演示
Output some simple log messages.
输出一些简单的日志消息。
Or output more detailed content.
或者输出更详细的内容。
Trace function calls and returns.
跟踪函数调用和返回。
Trace function exceptions.
跟踪函数异常。
I've provided some simple demo files. You can run them by executing the following command.
我提供了一些简单的演示文件。 您可以通过执行以下命令来运行它们。
python ./demo/demo_basic.py
python ./demo/demo_calleetrack.py
Documentation 文档
Nothing
没写
License 许可证
This project is licensed under the MIT License.
该项目使用 MIT 许可证。
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 Distributions
Built Distribution
File details
Details for the file logop-1.2.3-py3-none-any.whl
.
File metadata
- Download URL: logop-1.2.3-py3-none-any.whl
- Upload date:
- Size: 16.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 80a20957bcd519fa2534e11e5cc74f5a7a3d751a30ebee54ac2307202434e63a |
|
MD5 | 964aa97e1350f9319e25749f83785e19 |
|
BLAKE2b-256 | 3f1d7bd0ea2b18318c1178468d95bddd06a6dbdfea29b8982d56af7e0e10ee64 |