From 83e34e1799ca2e2a0a6ebe52998b19efbd0e8c29 Mon Sep 17 00:00:00 2001 From: busya Date: Sat, 27 Dec 2025 05:39:33 +0300 Subject: [PATCH] feat(logging): implement configurable belief state logging - Add LoggingConfig model and logging field to GlobalSettings - Implement belief_scope context manager for structured logging - Add configure_logger for dynamic level and file rotation settings - Add logging configuration UI to Settings page - Update ConfigManager to apply logging settings on initialization and updates --- .gitignore | 3 +- backend/mappings.db | Bin 28672 -> 28672 bytes backend/src/api/routes/environments.py | 3 + backend/src/core/config_manager.py | 14 ++- backend/src/core/config_models.py | 11 ++ backend/src/core/logger.py | 97 +++++++++++++++++- backend/tests/test_logger.py | 44 ++++++++ .../.svelte-kit/generated/server/internal.js | 2 +- frontend/src/pages/Settings.svelte | 48 ++++++++- specs/006-configurable-belief-logs/tasks.md | 26 ++--- 10 files changed, 224 insertions(+), 24 deletions(-) create mode 100644 backend/tests/test_logger.py diff --git a/.gitignore b/.gitignore index 43288a7..bd4f21d 100755 --- a/.gitignore +++ b/.gitignore @@ -60,4 +60,5 @@ keyring passwords.py *github* *git* *tech_spec* -dashboards \ No newline at end of file +dashboards +backend/mappings.db diff --git a/backend/mappings.db b/backend/mappings.db index 4639b40c39a1c90b2c40d38d31d893c592a60a00..99c019c64029cebd529ee9e08d527a3b6e016055 100644 GIT binary patch literal 28672 zcmeI(O>g2x7zc0@60+ot)$SpuNZvyfkUEXW?^X{jn!G(^`Ze|o^gHxYsbdn7&@9N8s?F+;1on6y598nS7-1voFRJZWs9|q# z!D7`=9x9oP@|CJ8ijtSlW%-;uvT|i{(vZu{t@T-}dFAu(->et@RC23Z%En)X-`D=w z_-%D-?dMrLU^@gL009U<00Izz00jOsfp-s3 zmD{UT%8iQJC_k-M)agF8xRP%N>dSI%?|HeVo}4z+lV-L0nYxmXdc%P)TB7@1Yeq!O z2InH47ZJrQ9!8Vli_|V9BM(Hs!{pEbSD&7qRx9O`WUD_AEEYjae%F5{r`tF@uBgu{ z`{ib}q3$(nwaQ7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\t\n\t\t
\n\t\t\t" + status + "\n\t\t\t
\n\t\t\t\t

" + message + "

\n\t\t\t
\n\t\t
\n\t\n\n" }, - version_hash: "uq8l2w" + version_hash: "n7gbte" }; export async function get_hooks() { diff --git a/frontend/src/pages/Settings.svelte b/frontend/src/pages/Settings.svelte index a15e419..6b8f73c 100755 --- a/frontend/src/pages/Settings.svelte +++ b/frontend/src/pages/Settings.svelte @@ -21,7 +21,14 @@ environments: [], settings: { backup_path: '', - default_environment_id: null + default_environment_id: null, + logging: { + level: 'INFO', + file_path: 'logs/app.log', + max_bytes: 10485760, + backup_count: 5, + enable_belief_state: true + } } }; @@ -180,10 +187,43 @@ - + +

Logging Configuration

+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+ +
diff --git a/specs/006-configurable-belief-logs/tasks.md b/specs/006-configurable-belief-logs/tasks.md index e9d0a80..3517a37 100644 --- a/specs/006-configurable-belief-logs/tasks.md +++ b/specs/006-configurable-belief-logs/tasks.md @@ -2,19 +2,19 @@ **Spec**: `specs/006-configurable-belief-logs/spec.md` **Plan**: `specs/006-configurable-belief-logs/plan.md` -**Status**: Pending +**Status**: Completed ## Phase 1: Setup *Goal: Initialize project structure for logging.* -- [ ] T001 Ensure logs directory exists at `logs/` (relative to project root) +- [x] T001 Ensure logs directory exists at `logs/` (relative to project root) ## Phase 2: Foundational *Goal: Define data models and infrastructure required for logging configuration.* -- [ ] T002 Define `LoggingConfig` model in `backend/src/core/config_models.py` -- [ ] T003 Update `GlobalSettings` model to include `logging` field in `backend/src/core/config_models.py` -- [ ] T004 Update `ConfigManager` to handle logging configuration persistence in `backend/src/core/config_manager.py` +- [x] T002 Define `LoggingConfig` model in `backend/src/core/config_models.py` +- [x] T003 Update `GlobalSettings` model to include `logging` field in `backend/src/core/config_models.py` +- [x] T004 Update `ConfigManager` to handle logging configuration persistence in `backend/src/core/config_manager.py` ## Phase 3: User Story 1 - Structured Belief State Logging *Goal: Implement the core "Belief State" logging logic with context managers.* @@ -22,9 +22,9 @@ **Independent Test**: Run `pytest backend/tests/test_logger.py` and verify `belief_scope` generates `[ID][Entry]`, `[ID][Action]`, and `[ID][Exit]` logs. -- [ ] T005 [US1] Create unit tests for belief state logging in `backend/tests/test_logger.py` -- [ ] T006 [US1] Implement `belief_scope` context manager in `backend/src/core/logger.py` -- [ ] T007 [US1] Implement log formatting and smart filtering (suppress Entry/Exit if disabled) in `backend/src/core/logger.py` +- [x] T005 [US1] Create unit tests for belief state logging in `backend/tests/test_logger.py` +- [x] T006 [US1] Implement `belief_scope` context manager in `backend/src/core/logger.py` +- [x] T007 [US1] Implement log formatting and smart filtering (suppress Entry/Exit if disabled) in `backend/src/core/logger.py` ## Phase 4: User Story 2 - Configurable Logging Settings *Goal: Expose logging configuration to the user via API and UI.* @@ -32,15 +32,15 @@ **Independent Test**: Update settings via API/UI and verify log level changes (e.g., DEBUG logs appear) and file rotation is active. -- [ ] T008 [US2] Implement `configure_logger` function to apply settings (level, file, rotation) in `backend/src/core/logger.py` -- [ ] T009 [US2] Update settings API endpoint to handle `logging` updates in `backend/src/api/routes/settings.py` -- [ ] T010 [P] [US2] Add Logging configuration section (Level, File Path, Enable Belief State) to `frontend/src/pages/Settings.svelte` +- [x] T008 [US2] Implement `configure_logger` function to apply settings (level, file, rotation) in `backend/src/core/logger.py` +- [x] T009 [US2] Update settings API endpoint to handle `logging` updates in `backend/src/api/routes/settings.py` +- [x] T010 [P] [US2] Add Logging configuration section (Level, File Path, Enable Belief State) to `frontend/src/pages/Settings.svelte` ## Final Phase: Polish & Cross-Cutting Concerns *Goal: Verify system stability and cleanup.* -- [ ] T011 Verify log rotation works by generating dummy logs (manual verification) -- [ ] T012 Ensure default configuration provides a sensible out-of-the-box experience +- [x] T011 Verify log rotation works by generating dummy logs (manual verification) +- [x] T012 Ensure default configuration provides a sensible out-of-the-box experience ## Dependencies