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:
@@ -2,6 +2,8 @@
|
||||
* Telegram init data and access checks.
|
||||
*/
|
||||
|
||||
import { logger } from "./logger.js";
|
||||
|
||||
/**
|
||||
* Get tgWebAppData value from hash when it contains unencoded & and =.
|
||||
* Value runs from tgWebAppData= until next &tgWebApp or end.
|
||||
@@ -33,7 +35,10 @@ export function getInitData() {
|
||||
const hash = window.location.hash ? window.location.hash.slice(1) : "";
|
||||
if (hash) {
|
||||
const fromHash = getTgWebAppDataFromHash(hash);
|
||||
if (fromHash) return fromHash;
|
||||
if (fromHash) {
|
||||
logger.debug("initData from hash");
|
||||
return fromHash;
|
||||
}
|
||||
const hashParams = new URLSearchParams(hash);
|
||||
const tgFromHash = hashParams.get("tgWebAppData");
|
||||
if (tgFromHash) return tgFromHash;
|
||||
@@ -42,6 +47,7 @@ export function getInitData() {
|
||||
? new URLSearchParams(window.location.search).get("tgWebAppData")
|
||||
: null;
|
||||
if (q) {
|
||||
logger.debug("initData from query");
|
||||
return q;
|
||||
}
|
||||
return "";
|
||||
|
||||
Reference in New Issue
Block a user