Skip to content

Commit 82c32f1

Browse files
Merge pull request #105 from kevinbackhouse/log_dir
Use platformdirs.user_log_dir to create a log directory
2 parents fbf550d + 62f6771 commit 82c32f1

File tree

13 files changed

+80
-47
lines changed

13 files changed

+80
-47
lines changed

.devcontainer/post-create.sh

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,10 @@ hatch build
1717
# Install this package from local directory.
1818
pip install -e .
1919

20-
# Create logs directory if it doesn't exist
21-
mkdir -p logs
22-
23-
# Create optional data directories
24-
mkdir -p data
25-
2620
# Create .env file if it doesn't exist
2721
if [ ! -f .env ]; then
2822
echo "📝 Creating .env template..."
2923
echo "# Optional: CodeQL database base path" >> .env
30-
echo "CODEQL_DBS_BASE_PATH=$(realpath data)" >> .env
3124
echo "⚠️ Please configure the environment or your .env file with required tokens!"
3225
fi
3326

.dockerignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
__pycache__
22
docker/
3-
logs/**/*
43
.env
54
.venv
65
.direnv

.gitignore

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ __pycache__/
1313
# C extensions
1414
*.so
1515

16-
# Logs directory
17-
logs/
18-
1916
# Distribution / packaging
2017
.Python
2118
build/
@@ -186,5 +183,3 @@ config.yaml
186183

187184
#database
188185
*.db
189-
#logs
190-
logs/

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ if [ ! -f ".env" ]; then
150150
fi
151151

152152
docker run \
153-
--volume "$PWD"/logs:/app/logs \
154153
--mount type=bind,src="$PWD"/.env,dst=/app/.env,ro \
155154
${MY_DATA:+--mount type=bind,src=$MY_DATA,dst=/app/my_data} \
156155
${MY_MCP_SERVERS:+--mount type=bind,src=$MY_MCP_SERVERS,dst=/app/my_mcp_servers,ro} \

docker/run.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,9 @@
1616
# sudo -E ../docker/run.sh -p seclab_taskflow_agent.personalities.assistant 'explain modems to me please'
1717

1818
touch -a .env
19-
mkdir -p logs
20-
mkdir -p data
2119

2220
docker run -i \
2321
--mount type=bind,src="$PWD",dst=/app \
24-
-e DATA_DIR=/app/data \
2522
-e GITHUB_PERSONAL_ACCESS_TOKEN="$GITHUB_PERSONAL_ACCESS_TOKEN" \
2623
-e AI_API_TOKEN="$AI_API_TOKEN" \
2724
"ghcr.io/githubsecuritylab/seclab-taskflow-agent" "$@"

src/seclab_taskflow_agent/__main__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,14 @@
3333
from .agent import TaskAgent
3434
from .capi import list_tool_call_models, get_AI_token
3535
from .available_tools import AvailableTools
36+
from .path_utils import log_file_name
3637

3738
load_dotenv(find_dotenv(usecwd=True))
3839

3940
# only model output or help message should go to stdout, everything else goes to log
4041
logging.getLogger('').setLevel(logging.NOTSET)
41-
log_dir = pathlib.Path("logs")
42-
log_dir.mkdir(parents=True, exist_ok=True)
4342
log_file_handler = RotatingFileHandler(
44-
log_dir.joinpath('task_agent.log'),
43+
log_file_name('task_agent.log'),
4544
maxBytes=1024*1024*10,
4645
backupCount=10)
4746
log_file_handler.setLevel(os.getenv('TASK_AGENT_LOGLEVEL', default='DEBUG'))

src/seclab_taskflow_agent/mcp_servers/codeql/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import os
1313
import zipfile
1414
import yaml
15+
from seclab_taskflow_agent.path_utils import log_file_name
1516

1617
# this is a local fork of https://github.com/riga/jsonrpyc modified for our purposes
1718
from . import jsonrpyc
@@ -45,8 +46,7 @@ def __init__(self,
4546
log_stderr=False):
4647
self.server_options = server_options.copy()
4748
if log_stderr:
48-
os.makedirs("logs", exist_ok=True)
49-
self.stderr_log = f"logs/codeql_stderr_log.log"
49+
self.stderr_log = log_file_name('codeql_stderr_log.log')
5050
self.server_options.append("--log-to-stderr")
5151
else:
5252
self.stderr_log = os.devnull

src/seclab_taskflow_agent/mcp_servers/codeql/mcp_server.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@
22
# SPDX-License-Identifier: MIT
33

44
import logging
5-
logging.basicConfig(
6-
level=logging.DEBUG,
7-
format='%(asctime)s - %(levelname)s - %(message)s',
8-
filename='logs/mcp_codeql.log',
9-
filemode='a'
10-
)
115
from .client import run_query, file_from_uri, list_src_files, _debug_log, search_in_src_archive
126
from pydantic import Field
137
#from mcp.server.fastmcp import FastMCP, Context
@@ -20,7 +14,14 @@
2014
import re
2115
from urllib.parse import urlparse, unquote
2216
import zipfile
23-
from seclab_taskflow_agent.path_utils import mcp_data_dir
17+
from seclab_taskflow_agent.path_utils import mcp_data_dir, log_file_name
18+
19+
logging.basicConfig(
20+
level=logging.DEBUG,
21+
format='%(asctime)s - %(levelname)s - %(message)s',
22+
filename=log_file_name('mcp_codeql.log'),
23+
filemode='a'
24+
)
2425

2526
mcp = FastMCP("CodeQL")
2627

src/seclab_taskflow_agent/mcp_servers/echo/echo.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22
# SPDX-License-Identifier: MIT
33

44
import logging
5+
#from mcp.server.fastmcp import FastMCP
6+
from fastmcp import FastMCP # move to FastMCP 2.0
7+
from seclab_taskflow_agent.path_utils import log_file_name
8+
59
logging.basicConfig(
610
level=logging.DEBUG,
711
format='%(asctime)s - %(levelname)s - %(message)s',
8-
filename='logs/mcp_echo.log',
12+
filename=log_file_name('mcp_echo.log'),
913
filemode='a'
1014
)
11-
#from mcp.server.fastmcp import FastMCP
12-
from fastmcp import FastMCP # move to FastMCP 2.0
1315

1416
mcp = FastMCP("Echo")
1517

src/seclab_taskflow_agent/mcp_servers/logbook/logbook.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@
22
# SPDX-License-Identifier: MIT
33

44
import logging
5+
#from mcp.server.fastmcp import FastMCP
6+
from fastmcp import FastMCP # move to FastMCP 2.0
7+
import json
8+
from pathlib import Path
9+
from seclab_taskflow_agent.path_utils import mcp_data_dir, log_file_name
10+
511
logging.basicConfig(
612
level=logging.DEBUG,
713
format='%(asctime)s - %(levelname)s - %(message)s',
8-
filename='logs/mcp_logbook.log',
14+
filename=log_file_name('mcp_logbook.log'),
915
filemode='a'
1016
)
11-
#from mcp.server.fastmcp import FastMCP
12-
from fastmcp import FastMCP # move to FastMCP 2.0
13-
import json
14-
from pathlib import Path
15-
from seclab_taskflow_agent.path_utils import mcp_data_dir
1617

1718
mcp = FastMCP("Logbook")
1819

0 commit comments

Comments
 (0)