Skip to content

Commit 49608eb

Browse files
committed
Add logging configuration and ensure logs directory exists
1 parent 8ca9f78 commit 49608eb

File tree

4 files changed

+30
-9
lines changed

4 files changed

+30
-9
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,5 @@ cython_debug/
174174
.pypirc
175175

176176
storage/
177+
logs/
177178

codetide/__init__.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
)
66
from codetide.core.models import CodeFileModel, CodeBase, CodeContextStructure
77
from codetide.core.common import readFile, writeFile
8+
from codetide.core.logs import logger
89

910
from codetide.parsers import BaseParser
1011
from codetide import parsers
@@ -13,19 +14,11 @@
1314
from typing import Optional, List, Tuple, Union, Dict
1415
from datetime import datetime, timezone
1516
from pathlib import Path
16-
import logging
1717
import asyncio
1818
import pygit2
1919
import time
2020
import json
2121
import os
22-
23-
logging.basicConfig(
24-
level=logging.INFO,
25-
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
26-
)
27-
logger = logging.getLogger(__name__)
28-
2922
class CodeTide(BaseModel):
3023
"""Root model representing a complete codebase"""
3124
rootpath : Union[str, Path]

codetide/core/defaults.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from pathlib import Path
22
import os
33

4-
INSTALLATION_DIR = Path(os.path.abspath(os.path.dirname(__file__)))
4+
INSTALLATION_DIR = Path(os.path.abspath(os.path.dirname(__file__))).parent
55

66
# Language extensions mapping
77
LANGUAGE_EXTENSIONS = {

codetide/core/logs.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from .defaults import INSTALLATION_DIR
2+
from loguru import logger
3+
from pathlib import Path
4+
import sys
5+
6+
# Ensure logs directory exists
7+
logs_dir = Path(INSTALLATION_DIR) / "logs"
8+
logs_dir.mkdir(exist_ok=True, parents=True)
9+
10+
# Configure logger
11+
logger.remove()
12+
13+
# Console output (INFO and above)
14+
logger.add(sys.stderr, level="INFO")
15+
16+
# File output (DEBUG and above, rotated daily, kept for 5 days)
17+
logger.add(
18+
logs_dir / "codetide_{time:YYYY-MM-DD}.log",
19+
level="DEBUG",
20+
rotation="00:00",
21+
retention="5 days",
22+
enqueue=True,
23+
backtrace=True,
24+
diagnose=True,
25+
compression="zip",
26+
format="{time:YYYY-MM-DD HH:mm:ss.SSS} | {level: <8} | {message}"
27+
)

0 commit comments

Comments
 (0)