diff --git a/README.md b/README.md index dd267c1..7f971a7 100644 --- a/README.md +++ b/README.md @@ -6,11 +6,10 @@ A python lib came from [Difficult Rocket](https://github.com/shenjackyuanjie/Dif ## Information/信息 -- Version/版本: 0.1.8 +- Version / 版本: 0.1.8 +- Author / 作者: shenjackyuanjie 3695888@qq.com -### Author/作者 - -[shenjackyuanjie](https://github/shenjackyuanjie) +> [shenjackyuanjie](https://github/shenjackyuanjie) ### License/许可证 diff --git a/example/logger/.gitignore b/example/logger/.gitignore new file mode 100644 index 0000000..cd3d225 --- /dev/null +++ b/example/logger/.gitignore @@ -0,0 +1 @@ +logs \ No newline at end of file diff --git a/lib_not_dr/logger/formatter/__init__.py b/lib_not_dr/logger/formatter/__init__.py index 84e09be..47bb3cb 100644 --- a/lib_not_dr/logger/formatter/__init__.py +++ b/lib_not_dr/logger/formatter/__init__.py @@ -5,6 +5,7 @@ # ------------------------------- import time +from pathlib import Path from string import Template from typing import List, Union, Optional, Dict, Tuple, TYPE_CHECKING @@ -180,7 +181,7 @@ class TraceFormatter(BaseFormatter): def _format(self, message: FormattingMessage) -> FormattingMessage: if message[0].stack_trace is None: return message - message[1]['log_source'] = message[0].stack_trace.f_code.co_filename + message[1]['log_source'] = Path(message[0].stack_trace.f_code.co_filename) message[1]['log_line'] = message[0].stack_trace.f_lineno message[1]['log_function'] = message[0].stack_trace.f_code.co_name return message diff --git a/lib_not_dr/logger/outstream.py b/lib_not_dr/logger/outstream.py index f8a2c1f..8741e86 100644 --- a/lib_not_dr/logger/outstream.py +++ b/lib_not_dr/logger/outstream.py @@ -120,6 +120,7 @@ class FileCacheOutputStream(BaseOutputStream): if self.text_cache is None: self.text_cache = io.StringIO() self.flush_lock = threading.Lock() + self.get_file_path() return False def _write(self, message: LogMessage) -> None: @@ -220,7 +221,7 @@ class FileCacheOutputStream(BaseOutputStream): current_file = self.check_flush() if not current_file.exists(): current_file.parent.mkdir(parents=True, exist_ok=True) - current_file.touch() + current_file.touch(exist_ok=True) with current_file.open('a', encoding=self.file_encoding) as f: f.write(text) return None