Skip to content

Commit 360f956

Browse files
new: store logs in user log dir and display the location on startup
1 parent 53c5433 commit 360f956

2 files changed

Lines changed: 14 additions & 9 deletions

File tree

DocToolsLLM/DocToolsLLM.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"""
44

55
# import this first because it sets the logging level
6-
from .utils.logger import whi, yel, red, md_printer, log, set_docstring, config_dir, cache_dir
6+
from .utils.logger import whi, yel, red, md_printer, log, set_docstring, log_dir, cache_dir
77

88
import sys
99
import faulthandler
@@ -247,6 +247,8 @@ def handle_exception(exc_type, exc_value, exc_traceback):
247247

248248
if debug:
249249
llm_verbosity = True
250+
whi(f"Cache location: {cache_dir.absolute()}")
251+
whi(f"Config location: {log_dir.absolute()}")
250252

251253
# storing as attributes
252254
self.modelbackend = modelname.split("/", 1)[0].lower()

DocToolsLLM/utils/logger.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,24 @@
1313
from typing import Type, Callable, Optional, Union
1414
from rich.markdown import Markdown
1515
from rich.console import Console
16-
from platformdirs import user_cache_dir
16+
from platformdirs import user_cache_dir, user_log_dir
1717

1818
from .typechecker import optional_typecheck
1919

20-
assert Path(user_cache_dir()).exists(), f"User cache dir not found: '{user_cache_dir()}'"
21-
cache_dir = Path(user_cache_dir()) / "DocToolsLLM"
22-
cache_dir.mkdir(exist_ok=True)
23-
log_dir = cache_dir / "logs"
24-
log_dir.mkdir(exist_ok=True)
25-
(log_dir / "logs.txt").touch(exist_ok=True)
20+
cache_dir = Path(user_cache_dir(appname="DocToolsLLM"))
21+
assert cache_dir.parent.exists() or cache_dir.parent.parent.exists(), f"Invalid cache dir location: '{cache_dir}'"
22+
cache_dir.mkdir(parents=True, exist_ok=True)
23+
24+
log_dir = Path(user_log_dir(appname="DocToolsLLM"))
25+
assert log_dir.parent.exists() or log_dir.parent.parent.exists() or log_dir.parent.parent.parent.exists(), f"Invalid log_dir location: '{log_dir}'"
26+
log_dir.mkdir(exist_ok=True, parents=True)
27+
log_file = (log_dir / "logs.txt")
28+
log_file.touch(exist_ok=True)
2629

2730
# logger
2831
log_formatter = logging.Formatter('%(asctime)s %(levelname)s %(funcName)s(%(lineno)d) %(message)s')
2932
handler = logging.handlers.RotatingFileHandler(
30-
filename=log_dir / "logs.txt",
33+
filename=log_file,
3134
mode="a",
3235
encoding=None,
3336
delay=0,

0 commit comments

Comments
 (0)