This commit is contained in:
shenjack 2023-11-05 21:04:35 +08:00
parent 2ed3bdce68
commit 0efdbf36b1
Signed by: shenjack
GPG Key ID: 7B1134A979775551
4 changed files with 8 additions and 6 deletions

View File

@ -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/许可证

1
example/logger/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
logs

View File

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

View File

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