Compare commits
7 Commits
987631c0f3
...
91d70dd332
Author | SHA1 | Date | |
---|---|---|---|
91d70dd332 | |||
5ff3468293 | |||
40462cf663 | |||
a8f326dca9 | |||
4fa5089819 | |||
e404486ccb | |||
a4e63ef73f |
@ -6,7 +6,7 @@ A python lib came from [Difficult Rocket](https://github.com/shenjackyuanjie/Dif
|
||||
|
||||
## Information/信息
|
||||
|
||||
- Version / 版本: 0.3.4
|
||||
- Version / 版本: 0.3.5
|
||||
- Author / 作者: shenjackyuanjie <3695888@qq.com>
|
||||
|
||||
[shenjackyuanjie](https://github.com/shenjackyuanjie)
|
||||
|
@ -1,5 +1,10 @@
|
||||
# lndl 0.3
|
||||
|
||||
## 0.3.5
|
||||
|
||||
- 向后移植了一些 `0.4` 的 logger 改动
|
||||
- 其实就是懒得发 0.4, 先测试一下再说
|
||||
|
||||
## 0.3.2/3/4
|
||||
|
||||
仅用于测试新的 `pdm publish` hook
|
||||
|
@ -3,6 +3,11 @@
|
||||
## Logger
|
||||
|
||||
- [ ] 达到可用级别
|
||||
- `Outstream`
|
||||
- `FileCacheOutputStream`
|
||||
- 现在如果输入的文件名包含 `{time}`
|
||||
- 会自动替换为 `time.strftime("%Y-%m-%d_%H-%M-%S")`
|
||||
- 修复了一些之前没有发现的问题
|
||||
|
||||
## Nuitka Compiler Helper
|
||||
|
||||
|
@ -9,7 +9,7 @@ from typing import TYPE_CHECKING
|
||||
if TYPE_CHECKING:
|
||||
from lib_not_dr import loggers, nuitka, types, command
|
||||
|
||||
_version_ = "0.3.4"
|
||||
_version_ = "0.3.5"
|
||||
|
||||
# fmt: off
|
||||
__all__ = [
|
||||
|
@ -86,7 +86,11 @@ class ConfigStorage(Options):
|
||||
return sorted(cycles_set) # 返回排序后的循环列表
|
||||
|
||||
def parse_level(self, level_config: dict) -> Optional[int]:
|
||||
""" """
|
||||
"""
|
||||
Parse level config
|
||||
:param level_config:
|
||||
:return:
|
||||
"""
|
||||
level_found: Tuple[Optional[int], Optional[str]] = (
|
||||
level_config.get("level"),
|
||||
level_config.get("level_name"),
|
||||
@ -272,21 +276,22 @@ class ConfigStorage(Options):
|
||||
env = ConfigStorage()
|
||||
for logger_name, config in logger_config.items():
|
||||
# get output for logger
|
||||
if "output" in config:
|
||||
if self.outputs.get(config["output"]) is None:
|
||||
if self.fail_outputs.get(config["output"]) is None:
|
||||
self.log.error(
|
||||
f'Logger {logger_name} output {config["output"]} not found, ignored'
|
||||
)
|
||||
if "outputs" in config:
|
||||
for i, output_name in enumerate(config["outputs"]):
|
||||
if self.outputs.get(output_name) is None:
|
||||
if self.fail_outputs.get(output_name) is None:
|
||||
self.log.error(
|
||||
f'Logger {logger_name} output {output_name} not found, ignored'
|
||||
)
|
||||
else:
|
||||
self.log.error(
|
||||
f'Logger {logger_name} require a fail output {output_name}, ignored'
|
||||
)
|
||||
env.fail_loggers[logger_name] = config
|
||||
continue
|
||||
else:
|
||||
self.log.error(
|
||||
f'Logger {logger_name} require a fail output {config["output"]}, ignored'
|
||||
)
|
||||
env.fail_loggers[logger_name] = config
|
||||
continue
|
||||
else:
|
||||
config["output"] = self.outputs[config["output"]]
|
||||
if level := self.parse_level(config) is not None:
|
||||
config["outputs"][i] = self.outputs[output_name]
|
||||
if (level := self.parse_level(config)) is not None:
|
||||
config["level"] = level
|
||||
if "level_name" in config:
|
||||
config.pop("level_name")
|
||||
|
@ -76,9 +76,9 @@ class BaseFormatter(Options):
|
||||
template = Template(template)
|
||||
|
||||
try:
|
||||
return template.substitute(**info)
|
||||
return template.substitute(info)
|
||||
except (KeyError, ValueError):
|
||||
return template.safe_substitute(**info)
|
||||
return template.safe_substitute(info)
|
||||
|
||||
def _format(self, message: FormattingMessage) -> FormattingMessage:
|
||||
"""
|
||||
|
@ -44,6 +44,8 @@ class BaseColorFormatter(BaseFormatter):
|
||||
}
|
||||
|
||||
def get_color(self, message: FormattingMessage) -> str:
|
||||
if message[0].level in self.color:
|
||||
return self.color[message[0].level]
|
||||
for level in self.color:
|
||||
if message[0].level <= level:
|
||||
break
|
||||
|
@ -103,17 +103,17 @@ class Logger(Options):
|
||||
output.level = level
|
||||
|
||||
def make_log(
|
||||
self,
|
||||
messages: Union[list, tuple],
|
||||
tag: Optional[str] = None,
|
||||
end: str = "\n",
|
||||
split: str = " ",
|
||||
flush: bool = True,
|
||||
level: int = 20, # info
|
||||
# log_time: Optional[float] = None,
|
||||
# logger_name: str = 'root',
|
||||
# logger_tag: Optional[str] = None,
|
||||
stack_trace: Optional[FrameType] = None,
|
||||
self,
|
||||
messages: Union[list, tuple],
|
||||
tag: Optional[str] = None,
|
||||
end: str = "\n",
|
||||
split: str = " ",
|
||||
flush: bool = True,
|
||||
level: int = 20, # info
|
||||
# log_time: Optional[float] = None,
|
||||
# logger_name: str = 'root',
|
||||
# logger_tag: Optional[str] = None,
|
||||
stack_trace: Optional[FrameType] = None,
|
||||
) -> None:
|
||||
# 检查是否需要记录
|
||||
if not self.log_for(level):
|
||||
@ -133,7 +133,7 @@ class Logger(Options):
|
||||
stack_trace = stack
|
||||
|
||||
message = LogMessage(
|
||||
messages=messages, # type: ignore
|
||||
messages=messages, # type: ignore
|
||||
end=end,
|
||||
split=split,
|
||||
flush=flush,
|
||||
@ -153,13 +153,13 @@ class Logger(Options):
|
||||
# 20231106 00:06
|
||||
|
||||
def info(
|
||||
self,
|
||||
*message,
|
||||
tag: Optional[str] = None,
|
||||
end: str = "\n",
|
||||
split: str = " ",
|
||||
flush: bool = True,
|
||||
stack_trace: Optional[FrameType] = None,
|
||||
self,
|
||||
*message,
|
||||
tag: Optional[str] = None,
|
||||
end: str = "\n",
|
||||
split: str = " ",
|
||||
flush: bool = True,
|
||||
stack_trace: Optional[FrameType] = None,
|
||||
) -> None:
|
||||
if not self.log_for(LogLevel.info):
|
||||
return
|
||||
@ -174,13 +174,13 @@ class Logger(Options):
|
||||
)
|
||||
|
||||
def trace(
|
||||
self,
|
||||
*message,
|
||||
tag: Optional[str] = None,
|
||||
end: str = "\n",
|
||||
split: str = " ",
|
||||
flush: bool = True,
|
||||
stack_trace: Optional[FrameType] = None,
|
||||
self,
|
||||
*message,
|
||||
tag: Optional[str] = None,
|
||||
end: str = "\n",
|
||||
split: str = " ",
|
||||
flush: bool = True,
|
||||
stack_trace: Optional[FrameType] = None,
|
||||
) -> None:
|
||||
if not self.log_for(LogLevel.trace):
|
||||
return
|
||||
@ -195,13 +195,13 @@ class Logger(Options):
|
||||
)
|
||||
|
||||
def fine(
|
||||
self,
|
||||
*message,
|
||||
tag: Optional[str] = None,
|
||||
end: str = "\n",
|
||||
split: str = " ",
|
||||
flush: bool = True,
|
||||
stack_trace: Optional[FrameType] = None,
|
||||
self,
|
||||
*message,
|
||||
tag: Optional[str] = None,
|
||||
end: str = "\n",
|
||||
split: str = " ",
|
||||
flush: bool = True,
|
||||
stack_trace: Optional[FrameType] = None,
|
||||
) -> None:
|
||||
if not self.log_for(LogLevel.fine):
|
||||
return
|
||||
@ -216,13 +216,13 @@ class Logger(Options):
|
||||
)
|
||||
|
||||
def debug(
|
||||
self,
|
||||
*message,
|
||||
tag: Optional[str] = None,
|
||||
end: str = "\n",
|
||||
split: str = " ",
|
||||
flush: bool = True,
|
||||
stack_trace: Optional[FrameType] = None,
|
||||
self,
|
||||
*message,
|
||||
tag: Optional[str] = None,
|
||||
end: str = "\n",
|
||||
split: str = " ",
|
||||
flush: bool = True,
|
||||
stack_trace: Optional[FrameType] = None,
|
||||
) -> None:
|
||||
if not self.log_for(LogLevel.debug):
|
||||
return
|
||||
@ -237,13 +237,13 @@ class Logger(Options):
|
||||
)
|
||||
|
||||
def warn(
|
||||
self,
|
||||
*message,
|
||||
tag: Optional[str] = None,
|
||||
end: str = "\n",
|
||||
split: str = " ",
|
||||
flush: bool = True,
|
||||
stack_trace: Optional[FrameType] = None,
|
||||
self,
|
||||
*message,
|
||||
tag: Optional[str] = None,
|
||||
end: str = "\n",
|
||||
split: str = " ",
|
||||
flush: bool = True,
|
||||
stack_trace: Optional[FrameType] = None,
|
||||
) -> None:
|
||||
if not self.log_for(LogLevel.warn):
|
||||
return
|
||||
@ -258,13 +258,13 @@ class Logger(Options):
|
||||
)
|
||||
|
||||
def error(
|
||||
self,
|
||||
*message,
|
||||
tag: Optional[str] = None,
|
||||
end: str = "\n",
|
||||
split: str = " ",
|
||||
flush: bool = True,
|
||||
stack_trace: Optional[FrameType] = None,
|
||||
self,
|
||||
*message,
|
||||
tag: Optional[str] = None,
|
||||
end: str = "\n",
|
||||
split: str = " ",
|
||||
flush: bool = True,
|
||||
stack_trace: Optional[FrameType] = None,
|
||||
) -> None:
|
||||
if not self.log_for(LogLevel.error):
|
||||
return
|
||||
@ -279,13 +279,13 @@ class Logger(Options):
|
||||
)
|
||||
|
||||
def fatal(
|
||||
self,
|
||||
*message,
|
||||
tag: Optional[str] = None,
|
||||
end: str = "\n",
|
||||
split: str = " ",
|
||||
flush: bool = True,
|
||||
stack_trace: Optional[FrameType] = None,
|
||||
self,
|
||||
*message,
|
||||
tag: Optional[str] = None,
|
||||
end: str = "\n",
|
||||
split: str = " ",
|
||||
flush: bool = True,
|
||||
stack_trace: Optional[FrameType] = None,
|
||||
) -> None:
|
||||
if not self.log_for(LogLevel.fatal):
|
||||
return
|
||||
|
@ -61,10 +61,11 @@ class StdioOutputStream(BaseOutputStream):
|
||||
return None
|
||||
if message.level < self.level:
|
||||
return None
|
||||
out_msg = self.formatter.format_message(message)
|
||||
if message.flush is not None:
|
||||
print(self.formatter.format_message(message), end="", flush=message.flush)
|
||||
print(out_msg, end="", flush=message.flush)
|
||||
else:
|
||||
print(self.formatter.format_message(message), end="", flush=True)
|
||||
print(out_msg, end="", flush=True)
|
||||
return None
|
||||
|
||||
def write_stderr(self, message: LogMessage) -> None:
|
||||
@ -115,6 +116,7 @@ class FileCacheOutputStream(BaseOutputStream):
|
||||
flush_timer: Optional[threading.Timer] = None
|
||||
|
||||
file_path: Path = Path("./logs")
|
||||
# if contain {time} -> time.strftime("%Y-%m-%d_%H-%M-%S", time.gmtime(time.time)
|
||||
file_name: str
|
||||
# file mode: always 'a'
|
||||
file_encoding: str = "utf-8"
|
||||
@ -138,9 +140,17 @@ class FileCacheOutputStream(BaseOutputStream):
|
||||
file_swap_on_both: bool = False # swap file when both size and time limit reached
|
||||
|
||||
def init(self, **kwargs) -> bool:
|
||||
# 时间取整
|
||||
self.file_start_time = round(time.time())
|
||||
# 初始化文件名
|
||||
if "{time}" in self.file_name:
|
||||
self.file_name = self.file_name.format(time=time.strftime(
|
||||
"%Y-%m-%d_%H-%M-%S", time.gmtime(self.file_start_time)
|
||||
))
|
||||
# 初始化缓存
|
||||
if self.text_cache is None:
|
||||
self.text_cache = io.StringIO()
|
||||
# 检查文件名
|
||||
self.get_file_path()
|
||||
return False
|
||||
|
||||
@ -224,8 +234,7 @@ class FileCacheOutputStream(BaseOutputStream):
|
||||
if file_time > self.file_time_limit:
|
||||
time_pass = False
|
||||
if (self.file_swap_on_both and size_pass and time_pass) or (
|
||||
not self.file_swap_on_both and (size_pass or time_pass)
|
||||
):
|
||||
not self.file_swap_on_both and (size_pass or time_pass)):
|
||||
# 两个都满足
|
||||
# 或者只有一个满足
|
||||
if size_pass and time_pass:
|
||||
@ -243,6 +252,7 @@ class FileCacheOutputStream(BaseOutputStream):
|
||||
if text == "":
|
||||
return None
|
||||
current_file = self.check_flush()
|
||||
# 检查文件是否存在
|
||||
if not current_file.exists():
|
||||
current_file.parent.mkdir(parents=True, exist_ok=True)
|
||||
current_file.touch(exist_ok=True)
|
||||
|
@ -13,4 +13,13 @@ nuitka_config_type = Dict[str, Union[str, bool, List[Union[str, tuple]]]]
|
||||
raw_config_type = Dict[str, Union[nuitka_config_type, str]]
|
||||
parse_config_function = Callable[[raw_config_type], nuitka_config_type]
|
||||
|
||||
__all__ = ["reader", "compile", "raw_config_type", "parse_config_function", "nuitka_config_type"]
|
||||
# fmt: off
|
||||
__all__ = [
|
||||
"reader",
|
||||
"compile",
|
||||
"raw_config_type",
|
||||
"parse_config_function",
|
||||
"nuitka_config_type"
|
||||
]
|
||||
# fmt: on
|
||||
|
||||
|
@ -8,3 +8,10 @@
|
||||
TMD 啊啊啊啊啊啊啊啊啊
|
||||
这里不是用来直接调用的啊啊啊啊啊
|
||||
"""
|
||||
|
||||
from lib_not_dr.nuitka.reader import cli_main
|
||||
|
||||
if __name__ == "__main__":
|
||||
cli_main()
|
||||
|
||||
main = cli_main
|
||||
|
Loading…
Reference in New Issue
Block a user