diff --git a/docs/main/lib-not-dr/change_logs/0-4.md b/docs/main/lib-not-dr/change_logs/0-4.md index ff11ce8..be5707d 100644 --- a/docs/main/lib-not-dr/change_logs/0-4.md +++ b/docs/main/lib-not-dr/change_logs/0-4.md @@ -1,10 +1,10 @@ -# lndl 0.4.0 (draft) +# lndl 0.4.0 ## Logger - [x] 完成配置解析 - [x] 支持读取配置之后自动应用 -- [ ] 达到可用级别 +- [x] 达到可用级别 - `Outstream` - `FileCacheOutputStream` diff --git a/docs/main/lib-not-dr/change_logs/_meta.json b/docs/main/lib-not-dr/change_logs/_meta.json index bdb7a9d..5597ce9 100644 --- a/docs/main/lib-not-dr/change_logs/_meta.json +++ b/docs/main/lib-not-dr/change_logs/_meta.json @@ -2,7 +2,7 @@ { "type": "file", "name": "0-4", - "label": "lndl 0.4 更新日志 (草稿)" + "label": "lndl 0.4 更新日志" }, { "type": "file", diff --git a/docs/main/lib-not-dr/loggers.md b/docs/main/lib-not-dr/loggers.md index eb6eb9f..b0d7c6b 100644 --- a/docs/main/lib-not-dr/loggers.md +++ b/docs/main/lib-not-dr/loggers.md @@ -1,3 +1,112 @@ # lib_not_dr.loggers > 欢迎来到 lndl 的 logger 的文档! + +使用范例: + +## 简单的 + +```python title=use_logger.py +from lib_not_dr import loggers + +logger = loggers.config.get_logger("somename") + +logger.info("abc") +``` + +## 复杂一些的 + +```python title=use_config.py +from lib_not_dr.loggers import config + +your_toml_config = "aaa" + +config.read_config(your_toml_config) +logger = config.get_logger("你定义好的logger") +``` + +### 这里的 config 范例 + +> 其实就是把 DR 的 config 复制过来了而已 + +```toml title=lndl-logger.toml + +config_version = 1 + +[Logger] + + [Logger.client] + # 日志名称 + logger_name = "client" + level_name = "debug" + # or 'DEBUG' + # or level = 10 + outputs = ["std_out", "file_out"] + + [Logger.server] + # 日志名称 + logger_name = "server" + level_name = "debug" + # or 'DEBUG' + # or level = 10 + outputs = ["std_out", "file_out"] + + [Logger.main] + # 日志名称 + logger_name = "main" + level_name = "debug" + # or 'DEBUG' + # or level = 10 + outputs = ["std_out", "file_out"] + +[Formatter] + + [Formatter.main_formatter] + # 格式化器名称 + class = "MainFormatter" + # 格式化器参数 + time_format = "%Y-%m-%d %H:%M:%S" + msec_time_format = "{}-{:03d}" + use_absolute_path = false + + [Formatter.std_formatter] + class = "StdFormatter" + enable_color = true + sub_formatter = ["main_formatter"] + default_template = "[${log_time}][${level}]|${logger_name}:${logger_tag}|${messages}" + + [Formatter.file_std_formatter] + class = "StdFormatter" + enable_color = false + sub_formatter = ["main_formatter"] + default_template = "[${log_time}][${level}]|${logger_name}:${logger_tag}|${messages}" + +[Outstream] + + [Outstream.std_out] + # 输出流名称 + class = "StdioOutputStream" + # 输出流参数 + formatter = "std_formatter" + use_stderr = false + # or true + level_name = "debug" + # or 'DEBUG' + # or level = 10 + + [Outstream.file_out] + class = "FileCacheOutputStream" + + level = 10 + # or level_name = 'DEBUG' + # or level_name = 'debug' + formatter = "file_std_formatter" + flush_count_limit = 10 + # 5 条日志刷新一次 + flush_time_limit = 5 + # 5 秒刷新一次 + # or flush_time_limit = 0.5 + file_path = "./logs" + file_name = "dr-{time}.log" + +```