Compare commits
2 Commits
2bdfb7fe1f
...
5a4d867bef
Author | SHA1 | Date | |
---|---|---|---|
5a4d867bef | |||
f9a8c69613 |
@ -14,7 +14,7 @@ logger = loggers.config.get_logger("somename")
|
|||||||
logger.info("abc")
|
logger.info("abc")
|
||||||
```
|
```
|
||||||
|
|
||||||
## 复杂一些的
|
## 使用 config 的范例
|
||||||
|
|
||||||
```python title=use_config.py
|
```python title=use_config.py
|
||||||
from lib_not_dr.loggers import config
|
from lib_not_dr.loggers import config
|
||||||
@ -110,3 +110,32 @@ config_version = 1
|
|||||||
file_name = "dr-{time}.log"
|
file_name = "dr-{time}.log"
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## 直接在代码里配置的案例
|
||||||
|
|
||||||
|
```python title=code_config.py
|
||||||
|
from lib_not_dr import loggers
|
||||||
|
|
||||||
|
logger = loggers.config.get_logger("main")
|
||||||
|
|
||||||
|
# 比如你想在控制台输出所有,文件里输出 error 及以上
|
||||||
|
error_stream = loggers.outstream.FileCacheOutputStream(file_name="check-err.log", level=loggers.LogLevel.warn)
|
||||||
|
logger.add_output(error_stream)
|
||||||
|
```
|
||||||
|
|
||||||
|
或者
|
||||||
|
|
||||||
|
```python title=fmt_log.py
|
||||||
|
import sys
|
||||||
|
from lib_not_dr import loggers
|
||||||
|
|
||||||
|
logger = loggers.config.get_logger("transfer")
|
||||||
|
log_file_name = f"{time.strftime('%Y-%m-%d-%H-%M-%S', time.localtime())}-transfer.log"
|
||||||
|
logger.add_output(FileCacheOutputStream(file_name=log_file_name, level=0))
|
||||||
|
|
||||||
|
# 使用命令行参数来调节等级
|
||||||
|
if "-v" in sys.argv:
|
||||||
|
logger.global_level = 10
|
||||||
|
if "-vv" in sys.argv:
|
||||||
|
logger.global_level = 5
|
||||||
|
```
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
"preview": "rspress preview"
|
"preview": "rspress preview"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"rspress": "^1.35.1",
|
"rspress": "^1.37.0",
|
||||||
"ts-node": "^10.9.2",
|
"ts-node": "^10.9.2",
|
||||||
"typescript": "^5.6.3"
|
"typescript": "^5.6.3"
|
||||||
}
|
}
|
||||||
|
702
pnpm-lock.yaml
702
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user