Compare commits

...

2 Commits

Author SHA1 Message Date
5a4d867bef
pnpm update 2024-11-16 16:47:36 +08:00
f9a8c69613
接着改 2024-11-16 16:47:27 +08:00
3 changed files with 394 additions and 341 deletions

View File

@ -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
```

View File

@ -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"
} }

File diff suppressed because it is too large Load Diff