Skip to content

Commit 1043930

Browse files
authored
update logging.md (#103)
1 parent 8be2aeb commit 1043930

File tree

2 files changed

+41
-33
lines changed

2 files changed

+41
-33
lines changed

docs/en/notes/dev_guide/logging.md

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,30 @@ permalink: /en/dev_guide/logging/
66

77
## Logger
88

9-
Currently, the logger is initialized in `pipeline_step.py`:
9+
The logger for DataFlow is initialized in [dataflow/logger.py](https://github.com/OpenDCAI/DataFlow/blob/main/dataflow/logger.py). Developers can directly use the `get_logger()` function defined there to obtain a logger.
1010

1111
```python
12-
import logging
13-
logging.basicConfig(level=logging.INFO,
14-
format="%(asctime)s | %(filename)-20s- %(module)-20s- %(funcName)-20s- %(lineno)5d - %(name)-10s | %(levelname)8s | Processno %(process)5d - Threadno %(thread)-15d : %(message)s",
15-
datefmt="%Y-%m-%d %H:%M:%S"
16-
)
12+
from dataflow.logger import get_logger
13+
logger = get_logger()
1714
```
1815

19-
Usage is as follows. `debug`, `info`, `warning`, and `error` represent different log levels. By default, logs at the DEBUG level are not shown.
16+
Usage is as follows. The debug, info, success, warning, and error methods correspond to different logging levels. By default, logs at the DEBUG level will not be displayed.
17+
If you want to specify a filtering rule (for example, to display DEBUG and above logging information), set the DF_LOGGING_LEVEL environment variable in the command line:
2018

19+
```bash
20+
export DF_LOGGING_LEVEL=DEBUG
21+
```
22+
23+
Here is an example:
2124
```python
2225
def main():
23-
24-
logging.debug("This is DEBUG message")
25-
logging.info("This is INFO message")
26-
logging.warning("This is WARNING message")
27-
logging.error("This is ERROR message")
28-
26+
27+
logger.debug("This is DEBUG message")
28+
logger.info("This is INFO message")
29+
logger.success("This is SUCCESS message")
30+
logger.warning("This is WARNING message")
31+
logger.error("This is ERROR message")
32+
2933
return
3034

3135
main()
@@ -50,7 +54,7 @@ Principles for assigning log levels:
5054
raise e
5155
```
5256

53-
2. **INFO**: Used to let users know the current execution status, such as:
57+
2. **INFO**: Used to inform the user about the current runtime status, for example:
5458

5559
```python
5660
def pipeline_step(yaml_path, step_name):
@@ -66,8 +70,8 @@ Principles for assigning log levels:
6670
algorithm.run()
6771
```
6872

69-
3. **WARNING**: Error messages indicating potential issues (no examples for now).
70-
71-
4. **ERROR**: Errors that occur during execution; used to print error messages.
73+
3. **SUCCESS**: Information indicating that an important step has been completed.
74+
4. **WARNING**: Messages indicating potential problems (currently no example).
75+
5. **ERROR**: Printed when an error occurs during execution.
7276

73-
For logging inside operators, refer to `DataFlow/dataflow/operators/generate/Reasoning/question_generator.py`.
77+
For logging inside operators, you can refer to [dataflow/operators/generate/Reasoning/question_generator.py](https://github.com/OpenDCAI/DataFlow/blob/main/dataflow/operators/generate/Reasoning/question_generator.py).

docs/zh/notes/dev_guide/logging.md

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,25 @@ permalink: /zh/dev_guide/logging/
66

77
## Logger
88

9-
目前logger的初始化在pipeline_step.py中
9+
DataFlow的日志管理器初始化在在[dataflow/logger.py](https://github.com/OpenDCAI/DataFlow/blob/main/dataflow/logger.py)中。开发者可直接使用其中定义的`get_logger()`函数获取logger.
1010
```python
11-
import logging
12-
logging.basicConfig(level=logging.INFO,
13-
format="%(asctime)s | %(filename)-20s- %(module)-20s- %(funcName)-20s- %(lineno)5d - %(name)-10s | %(levelname)8s | Processno %(process)5d - Threadno %(thread)-15d : %(message)s",
14-
datefmt="%Y-%m-%d %H:%M:%S"
15-
)
11+
from dataflow.logger import get_logger
12+
logger = get_logger()
1613
```
17-
使用方法如下所示,其中debug, info, warning, error代表不同的日志等级,默认情况下DEBUG等级的日志不会显示。
14+
使用方法如下所示,其中debug, info, success, warning, error代表不同的日志等级,默认情况下DEBUG等级的日志不会显示。
15+
如果想要指定屏蔽规则(如显示DEBUG及以上的logging信息)请在命令行指定`DF_LOGGING_LEVEL`环境变量:
16+
```bash
17+
export DF_LOGGING_LEVEL=DEBUG
18+
```
19+
下面是一个例子:
1820
```python
1921
def main():
2022

21-
logging.debug("This is DEBUG message")
22-
logging.info("This is INFO message")
23-
logging.warning("This is WARNING message")
24-
logging.error("This is ERROR message")
23+
logger.debug("This is DEBUG message")
24+
logger.info("This is INFO message")
25+
logger.success("This is SUCCESS message")
26+
logger.warning("This is WARNING message")
27+
logger.error("This is ERROR message")
2528

2629
return
2730

@@ -38,7 +41,7 @@ main()
3841
self._obj_map[name] = clss
3942
return clss
4043
except AttributeError as e:
41-
logging.debug(f"{str(e)}")
44+
logger.debug(f"{str(e)}")
4245
continue
4346
except Exception as e:
4447
raise e
@@ -57,7 +60,8 @@ main()
5760
logger.info("Start running ...")
5861
algorithm.run()
5962
```
60-
3. WARNING:可能出现问题的错误信息(暂时没有例子)
61-
4. ERROR:运行出现错误,打印错误信息
63+
3. SUCCESS: 重要步骤完成的信息。
64+
4. WARNING:可能出现问题的错误信息(暂时没有例子)
65+
5. ERROR:运行出现错误,打印错误信息
6266

63-
算子内部的logging可以参考`DataFlow/dataflow/operators/generate/Reasoning/question_generator.py`
67+
算子内部的logging可以参考[dataflow/operators/generate/Reasoning/question_generator.py](https://github.com/OpenDCAI/DataFlow/blob/main/dataflow/operators/generate/Reasoning/question_generator.py)。

0 commit comments

Comments
 (0)