VWED_server/docs/sc/日志相关.md

71 lines
1.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

```markdown
## 日志记录
#### 获取日志打印对象
* 方法说明
获取日志打印对象,可用于将指定信息打印进日志文件。
```python
def get_logger() -> Logger
```
* 输入参数
* 输出参数是日志对象,定义如下:
```python
class Logger:
def info(self, message: str) -> None:
"""记录信息级别日志"""
pass
def debug(self, message: str) -> None:
"""记录调试级别日志"""
pass
def warn(self, message: str) -> None:
"""记录警告级别日志"""
pass
def error(self, message: str, e: Exception = None) -> None:
"""记录错误级别日志"""
pass
```
调用方法:
```python
get_logger().info("hello world")
get_logger().error("there is an error.", Exception("错误详情"))
```
使用以上方法,可在日志文件中打印指定记录。
* 异常
本方法会抛出异常。
#### 在脚本页面下打印日志
* 方法说明
在 RDS 脚本页面下,打印日志信息。
```python
def script_log(level: str, function_name: str, content: any) -> None
```
* 输入参数
* levelstr 类型,日志等级,可选 "INFO""ERROR"。
* function_namestr 类型,一般填入所在函数的签名,用于快速定位信息。
* contentany 类型,日志信息。
* 输出参数
* 异常
本方法会抛出异常。
```