feat: add configurable logging level for backend and Mini App

- Introduced a new `LOG_LEVEL` configuration option in the `.env.example` file to allow users to set the logging level (DEBUG, INFO, WARNING, ERROR).
- Updated the `Settings` class to include the `log_level` attribute, normalizing its value to ensure valid logging levels are used.
- Modified the logging setup in `run.py` to utilize the configured log level, enhancing flexibility in log management.
- Enhanced the Mini App to include the logging level in the JavaScript configuration, allowing for consistent logging behavior across the application.
- Added a new `logger.js` module for frontend logging, implementing level-based filtering and console delegation.
- Included unit tests for the new logger functionality to ensure proper behavior and level handling.
This commit is contained in:
2026-03-02 23:15:22 +03:00
parent 67ba9826c7
commit 43386b15fa
16 changed files with 226 additions and 15 deletions

View File

@@ -17,6 +17,7 @@ import {
} from "./dom.js";
import { showAccessDenied, hideAccessDenied, showError, setNavEnabled } from "./ui.js";
import { fetchDuties, fetchCalendarEvents } from "./api.js";
import { logger } from "./logger.js";
import {
dutiesByDate,
calendarEventsByDate,
@@ -65,6 +66,8 @@ export function applyLangToUi() {
applyLangToUi();
logger.info("App init", "lang=" + state.lang);
window.__dtReady = true;
/**
@@ -148,6 +151,7 @@ async function loadMonth() {
const from = localDateString(start);
const to = localDateString(gridEnd);
try {
logger.debug("Loading month", from, to);
const dutiesPromise = fetchDuties(from, to, signal);
const eventsPromise = fetchCalendarEvents(from, to, signal);
const duties = await dutiesPromise;
@@ -186,6 +190,7 @@ async function loadMonth() {
return;
}
if (e.message === "ACCESS_DENIED") {
logger.warn("Access denied in loadMonth", e.serverDetail);
showAccessDenied(e.serverDetail);
setNavEnabled(true);
if (
@@ -198,6 +203,7 @@ async function loadMonth() {
}
return;
}
logger.error("Load month failed", e);
showError(e.message || t(state.lang, "error_generic"), loadMonth);
setNavEnabled(true);
return;