调试Python程序时输出跟踪日志
debugtrace的Python项目详细描述
DebugTrace py是一个输出跟踪日志的库 调试Python程序时。 它支持python3.7或更高版本。 通过在方法的开头嵌入“_ = debugtrace.enter()”, 您可以输出正在开发的程序的执行状态。在
1。特点
- 自动输出方法名、源文件名和行号 debugtrace.enter函数的调用程序。在
- 当作用域结束时还输出结束日志。在
- 使用嵌套方法和对象自动缩进日志。在
- 在值输出中自动换行。在
- 使用反射输出内容,即使是类的对象 不实现__str__方法的。在
- 您可以通过设置debugtrace.inifile自定义输出内容。在
- 您可以选择系统标准输出, 系统标准或者日志记录。记录器输出。在
2。安装
pip install debugtrace
3。如何使用
对调试目标及相关函数和方法执行以下操作:
- 在函数和方法的开头插入“_ = debugtrace.enter()”。在
- 如有必要,插入“debugtrace.print('foo', foo)”以将变量输出到日志中。在
下面是一个Python程序的示例,在执行时使用DebugTrace py和日志。在
# ReadmeExample.py import datetime import debugtrace # for Debugging # Contact class class Contact(object): def __init__(self, id: int, firstName: str, lastName: str, birthday: datetime.date) -> None: _ = debugtrace.enter(self) # for Debugging self.id = id self.firstName = firstName self.lastName = lastName self.birthday = birthday def func2(): _ = debugtrace.enter() # for Debugging contact = [ Contact(1, 'Akane' , 'Apple', datetime.date(1991, 2, 3)), Contact(2, 'Yukari', 'Apple', datetime.date(1992, 3, 4)) ] debugtrace.print('contact', contact) # for Debugging def func1(): _ = debugtrace.enter() # for Debugging func2() func1()
日志输出内容:
^{pr2}$4。功能
主要有以下功能。在
Name | Discription |
---|---|
^{tt8}$ | Outputs an entering log. Also outputs a leaving log at the end of the code block. Arguments: invoker (^{tt9}$): Pass the self or cls of the invoker. (Optional) Examples: ^{tt10}$ ^{tt11}$ ^{tt1}$ |
^{tt13}$ | Outputs the variable name and value. Arguments: name (str): Variable name, etc. value (object): Output value output_private (bool): Output private member if True (default: False) output_method (bool): Output method if True (default: False) The following are keyword arguments and can be omitted. force_reflection (^{tt14}$): If true, outputs using reflection even if it has a ^{tt3}$ or ^{tt16}$ method (default: ^{tt17}$) output_private (^{tt14}$): If true, also outputs private members when using reflection (default: ^{tt17}$) output_method (^{tt14}$): If true, also outputs method members when using reflection (default: ^{tt17}$) collection_limit (^{tt22}$): The limit value of elements such as ^{tt23}$, ^{tt24}$ and ^{tt25}$ to output (default: ^{tt26}$) bytes_limit (^{tt22}$): The limit value of elements for ^{tt28}$ and ^{tt29}$ to output (default: ^{tt26}$) string_limit (^{tt22}$): The limit value of characters for string to output (default: ^{tt26}$) reflection_nest_limit (int): The The limit value for reflection nesting (default: ^{tt26}$) Examples: ^{tt34}$ ^{tt7}$ ^{tt36}$ ^{tt37}$ |
5。可以在^{str 1}中指定的选项$调试跟踪.ini文件
DebugTrace py读取debugtrace.ini文件 在当前目录中进行初始化。 该部分是[debugtrace]。在
您可以在debugtrace.ini文件中指定以下选项。在
^{tb2}$将\s转换为空间。
6。许可证
麻省理工学院执照
7。发行说明
DebugTrace-py 1.0.2 - November 29, 2020
- 更改开始消息。('DebugTrace-py...'<;-'DebugTrace-python...')
DebugTrace-py 1.0.1 - July 19, 2020
- 改进了数据输出的换行处理。在
DebugTrace-py 1.0.0 - May 26, 2020
- 首次发布
(C)2020 Masato Kokubo
- 项目
标签: