Compare commits

..

No commits in common. "91d70dd3322806d983b78ffeec8a6621504268fd" and "987631c0f307aca70c78f0fbdda4568a6e0a6150" have entirely different histories.

11 changed files with 85 additions and 128 deletions

View File

@ -6,7 +6,7 @@ A python lib came from [Difficult Rocket](https://github.com/shenjackyuanjie/Dif
## Information/信息 ## Information/信息
- Version / 版本: 0.3.5 - Version / 版本: 0.3.4
- Author / 作者: shenjackyuanjie <3695888@qq.com> - Author / 作者: shenjackyuanjie <3695888@qq.com>
[shenjackyuanjie](https://github.com/shenjackyuanjie) [shenjackyuanjie](https://github.com/shenjackyuanjie)

View File

@ -1,10 +1,5 @@
# lndl 0.3 # lndl 0.3
## 0.3.5
- 向后移植了一些 `0.4` 的 logger 改动
- 其实就是懒得发 0.4, 先测试一下再说
## 0.3.2/3/4 ## 0.3.2/3/4
仅用于测试新的 `pdm publish` hook 仅用于测试新的 `pdm publish` hook

View File

@ -3,11 +3,6 @@
## Logger ## Logger
- [ ] 达到可用级别 - [ ] 达到可用级别
- `Outstream`
- `FileCacheOutputStream`
- 现在如果输入的文件名包含 `{time}`
- 会自动替换为 `time.strftime("%Y-%m-%d_%H-%M-%S")`
- 修复了一些之前没有发现的问题
## Nuitka Compiler Helper ## Nuitka Compiler Helper

View File

@ -9,7 +9,7 @@ from typing import TYPE_CHECKING
if TYPE_CHECKING: if TYPE_CHECKING:
from lib_not_dr import loggers, nuitka, types, command from lib_not_dr import loggers, nuitka, types, command
_version_ = "0.3.5" _version_ = "0.3.4"
# fmt: off # fmt: off
__all__ = [ __all__ = [

View File

@ -86,11 +86,7 @@ class ConfigStorage(Options):
return sorted(cycles_set) # 返回排序后的循环列表 return sorted(cycles_set) # 返回排序后的循环列表
def parse_level(self, level_config: dict) -> Optional[int]: def parse_level(self, level_config: dict) -> Optional[int]:
""" """ """
Parse level config
:param level_config:
:return:
"""
level_found: Tuple[Optional[int], Optional[str]] = ( level_found: Tuple[Optional[int], Optional[str]] = (
level_config.get("level"), level_config.get("level"),
level_config.get("level_name"), level_config.get("level_name"),
@ -276,22 +272,21 @@ class ConfigStorage(Options):
env = ConfigStorage() env = ConfigStorage()
for logger_name, config in logger_config.items(): for logger_name, config in logger_config.items():
# get output for logger # get output for logger
if "outputs" in config: if "output" in config:
for i, output_name in enumerate(config["outputs"]): if self.outputs.get(config["output"]) is None:
if self.outputs.get(output_name) is None: if self.fail_outputs.get(config["output"]) is None:
if self.fail_outputs.get(output_name) is None: self.log.error(
self.log.error( f'Logger {logger_name} output {config["output"]} not found, ignored'
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: else:
config["outputs"][i] = self.outputs[output_name] self.log.error(
if (level := self.parse_level(config)) is not None: 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["level"] = level config["level"] = level
if "level_name" in config: if "level_name" in config:
config.pop("level_name") config.pop("level_name")

View File

@ -76,9 +76,9 @@ class BaseFormatter(Options):
template = Template(template) template = Template(template)
try: try:
return template.substitute(info) return template.substitute(**info)
except (KeyError, ValueError): except (KeyError, ValueError):
return template.safe_substitute(info) return template.safe_substitute(**info)
def _format(self, message: FormattingMessage) -> FormattingMessage: def _format(self, message: FormattingMessage) -> FormattingMessage:
""" """

View File

@ -44,8 +44,6 @@ class BaseColorFormatter(BaseFormatter):
} }
def get_color(self, message: FormattingMessage) -> str: 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: for level in self.color:
if message[0].level <= level: if message[0].level <= level:
break break

View File

@ -103,17 +103,17 @@ class Logger(Options):
output.level = level output.level = level
def make_log( def make_log(
self, self,
messages: Union[list, tuple], messages: Union[list, tuple],
tag: Optional[str] = None, tag: Optional[str] = None,
end: str = "\n", end: str = "\n",
split: str = " ", split: str = " ",
flush: bool = True, flush: bool = True,
level: int = 20, # info level: int = 20, # info
# log_time: Optional[float] = None, # log_time: Optional[float] = None,
# logger_name: str = 'root', # logger_name: str = 'root',
# logger_tag: Optional[str] = None, # logger_tag: Optional[str] = None,
stack_trace: Optional[FrameType] = None, stack_trace: Optional[FrameType] = None,
) -> None: ) -> None:
# 检查是否需要记录 # 检查是否需要记录
if not self.log_for(level): if not self.log_for(level):
@ -133,7 +133,7 @@ class Logger(Options):
stack_trace = stack stack_trace = stack
message = LogMessage( message = LogMessage(
messages=messages, # type: ignore messages=messages, # type: ignore
end=end, end=end,
split=split, split=split,
flush=flush, flush=flush,
@ -153,13 +153,13 @@ class Logger(Options):
# 20231106 00:06 # 20231106 00:06
def info( def info(
self, self,
*message, *message,
tag: Optional[str] = None, tag: Optional[str] = None,
end: str = "\n", end: str = "\n",
split: str = " ", split: str = " ",
flush: bool = True, flush: bool = True,
stack_trace: Optional[FrameType] = None, stack_trace: Optional[FrameType] = None,
) -> None: ) -> None:
if not self.log_for(LogLevel.info): if not self.log_for(LogLevel.info):
return return
@ -174,13 +174,13 @@ class Logger(Options):
) )
def trace( def trace(
self, self,
*message, *message,
tag: Optional[str] = None, tag: Optional[str] = None,
end: str = "\n", end: str = "\n",
split: str = " ", split: str = " ",
flush: bool = True, flush: bool = True,
stack_trace: Optional[FrameType] = None, stack_trace: Optional[FrameType] = None,
) -> None: ) -> None:
if not self.log_for(LogLevel.trace): if not self.log_for(LogLevel.trace):
return return
@ -195,13 +195,13 @@ class Logger(Options):
) )
def fine( def fine(
self, self,
*message, *message,
tag: Optional[str] = None, tag: Optional[str] = None,
end: str = "\n", end: str = "\n",
split: str = " ", split: str = " ",
flush: bool = True, flush: bool = True,
stack_trace: Optional[FrameType] = None, stack_trace: Optional[FrameType] = None,
) -> None: ) -> None:
if not self.log_for(LogLevel.fine): if not self.log_for(LogLevel.fine):
return return
@ -216,13 +216,13 @@ class Logger(Options):
) )
def debug( def debug(
self, self,
*message, *message,
tag: Optional[str] = None, tag: Optional[str] = None,
end: str = "\n", end: str = "\n",
split: str = " ", split: str = " ",
flush: bool = True, flush: bool = True,
stack_trace: Optional[FrameType] = None, stack_trace: Optional[FrameType] = None,
) -> None: ) -> None:
if not self.log_for(LogLevel.debug): if not self.log_for(LogLevel.debug):
return return
@ -237,13 +237,13 @@ class Logger(Options):
) )
def warn( def warn(
self, self,
*message, *message,
tag: Optional[str] = None, tag: Optional[str] = None,
end: str = "\n", end: str = "\n",
split: str = " ", split: str = " ",
flush: bool = True, flush: bool = True,
stack_trace: Optional[FrameType] = None, stack_trace: Optional[FrameType] = None,
) -> None: ) -> None:
if not self.log_for(LogLevel.warn): if not self.log_for(LogLevel.warn):
return return
@ -258,13 +258,13 @@ class Logger(Options):
) )
def error( def error(
self, self,
*message, *message,
tag: Optional[str] = None, tag: Optional[str] = None,
end: str = "\n", end: str = "\n",
split: str = " ", split: str = " ",
flush: bool = True, flush: bool = True,
stack_trace: Optional[FrameType] = None, stack_trace: Optional[FrameType] = None,
) -> None: ) -> None:
if not self.log_for(LogLevel.error): if not self.log_for(LogLevel.error):
return return
@ -279,13 +279,13 @@ class Logger(Options):
) )
def fatal( def fatal(
self, self,
*message, *message,
tag: Optional[str] = None, tag: Optional[str] = None,
end: str = "\n", end: str = "\n",
split: str = " ", split: str = " ",
flush: bool = True, flush: bool = True,
stack_trace: Optional[FrameType] = None, stack_trace: Optional[FrameType] = None,
) -> None: ) -> None:
if not self.log_for(LogLevel.fatal): if not self.log_for(LogLevel.fatal):
return return

View File

@ -61,11 +61,10 @@ class StdioOutputStream(BaseOutputStream):
return None return None
if message.level < self.level: if message.level < self.level:
return None return None
out_msg = self.formatter.format_message(message)
if message.flush is not None: if message.flush is not None:
print(out_msg, end="", flush=message.flush) print(self.formatter.format_message(message), end="", flush=message.flush)
else: else:
print(out_msg, end="", flush=True) print(self.formatter.format_message(message), end="", flush=True)
return None return None
def write_stderr(self, message: LogMessage) -> None: def write_stderr(self, message: LogMessage) -> None:
@ -116,7 +115,6 @@ class FileCacheOutputStream(BaseOutputStream):
flush_timer: Optional[threading.Timer] = None flush_timer: Optional[threading.Timer] = None
file_path: Path = Path("./logs") file_path: Path = Path("./logs")
# if contain {time} -> time.strftime("%Y-%m-%d_%H-%M-%S", time.gmtime(time.time)
file_name: str file_name: str
# file mode: always 'a' # file mode: always 'a'
file_encoding: str = "utf-8" file_encoding: str = "utf-8"
@ -140,17 +138,9 @@ class FileCacheOutputStream(BaseOutputStream):
file_swap_on_both: bool = False # swap file when both size and time limit reached file_swap_on_both: bool = False # swap file when both size and time limit reached
def init(self, **kwargs) -> bool: def init(self, **kwargs) -> bool:
# 时间取整
self.file_start_time = round(time.time()) 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: if self.text_cache is None:
self.text_cache = io.StringIO() self.text_cache = io.StringIO()
# 检查文件名
self.get_file_path() self.get_file_path()
return False return False
@ -234,7 +224,8 @@ class FileCacheOutputStream(BaseOutputStream):
if file_time > self.file_time_limit: if file_time > self.file_time_limit:
time_pass = False time_pass = False
if (self.file_swap_on_both and size_pass and time_pass) or ( 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: if size_pass and time_pass:
@ -252,7 +243,6 @@ class FileCacheOutputStream(BaseOutputStream):
if text == "": if text == "":
return None return None
current_file = self.check_flush() current_file = self.check_flush()
# 检查文件是否存在
if not current_file.exists(): if not current_file.exists():
current_file.parent.mkdir(parents=True, exist_ok=True) current_file.parent.mkdir(parents=True, exist_ok=True)
current_file.touch(exist_ok=True) current_file.touch(exist_ok=True)

View File

@ -13,13 +13,4 @@ nuitka_config_type = Dict[str, Union[str, bool, List[Union[str, tuple]]]]
raw_config_type = Dict[str, Union[nuitka_config_type, str]] raw_config_type = Dict[str, Union[nuitka_config_type, str]]
parse_config_function = Callable[[raw_config_type], nuitka_config_type] parse_config_function = Callable[[raw_config_type], nuitka_config_type]
# fmt: off __all__ = ["reader", "compile", "raw_config_type", "parse_config_function", "nuitka_config_type"]
__all__ = [
"reader",
"compile",
"raw_config_type",
"parse_config_function",
"nuitka_config_type"
]
# fmt: on

View File

@ -8,10 +8,3 @@
TMD 啊啊啊啊啊啊啊啊啊 TMD 啊啊啊啊啊啊啊啊啊
这里不是用来直接调用的啊啊啊啊啊 这里不是用来直接调用的啊啊啊啊啊
""" """
from lib_not_dr.nuitka.reader import cli_main
if __name__ == "__main__":
cli_main()
main = cli_main