mirror of
https://github.com/j93es/browser-use-oauth.git
synced 2026-06-04 06:41:53 +09:00
[Update] logger
This commit is contained in:
parent
a655697b0f
commit
267fb40fa4
3 changed files with 90 additions and 50 deletions
29
lib/logger.py
Normal file
29
lib/logger.py
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
from pathlib import Path
|
||||
from datetime import datetime
|
||||
|
||||
# 미리 정해진 파일 경로
|
||||
FILE_PATH = Path("data/log.txt")
|
||||
|
||||
def logger(msg: str) -> None:
|
||||
try:
|
||||
"""
|
||||
msg 문자열을 파일 끝에 추가합니다.
|
||||
- 파일이 없으면 새로 생성
|
||||
- 디렉터리가 없으면 생성
|
||||
"""
|
||||
# 상위 디렉터리 생성 (이미 있으면 무시)
|
||||
FILE_PATH.parent.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# 현재 시각 구해서 포맷팅
|
||||
now = datetime.now()
|
||||
timestamp = now.strftime("%Y-%m-%d %H:%M:%S")
|
||||
|
||||
# 메시지에 개행이 없으면 자동으로 붙이기
|
||||
newline = "" if msg.endswith("\n") else "\n"
|
||||
line = f"[{timestamp}] {msg}{newline}"
|
||||
|
||||
# 'a' 모드: 파일이 없으면 생성, 있으면 이어쓰기
|
||||
with FILE_PATH.open(mode="a", encoding="utf-8") as f:
|
||||
f.write(line)
|
||||
except:
|
||||
print(msg)
|
||||
Loading…
Add table
Add a link
Reference in a new issue