Debug-Logging zentralisiert: Nutzung von process.env.NEXT_PUBLIC_DEBUG_LOG entfernt und auf getDebugLog() mit config.json umgestellt

- Alle Vorkommen von process.env.NEXT_PUBLIC_DEBUG_LOG entfernt
- Debug-Konfiguration erfolgt jetzt ausschließlich über public/config.json
- getDebugLog()-Utility überall verwendet
- .env-Dateien werden für Debug-Logging nicht mehr benötigt
- Alle betroffenen Komponenten, Services und API
This commit is contained in:
ISA
2025-08-22 11:10:40 +02:00
parent a013c07394
commit 3896381a8f
27 changed files with 94 additions and 84 deletions

26
utils/configUtils.js Normal file
View File

@@ -0,0 +1,26 @@
// utils/configUtils.js
let __configCache;
export async function getConfig() {
if (__configCache) return __configCache;
const res = await fetch("/config.json");
if (!res.ok) throw new Error("config.json konnte nicht geladen werden");
__configCache = await res.json();
return __configCache;
}
// Sync helper for debugLog (for use in event handlers etc.)
let debugLogValue;
export function getDebugLog() {
if (debugLogValue !== undefined) return debugLogValue;
// Try to read from window.__appConfig if available (set at app start)
if (
typeof window !== "undefined" &&
window.__appConfig &&
typeof window.__appConfig.debugLog !== "undefined"
) {
debugLogValue = !!window.__appConfig.debugLog;
return debugLogValue;
}
// Fallback: default false
return false;
}

View File

@@ -62,7 +62,7 @@ export const checkOverlappingMarkers = (map, markers, plusIcon, oms) => {
export const handlePlusIconClick = (map, markers, oms, clickedLatLng) => {
// Debugging-Ausgabe
if (process.env.NEXT_PUBLIC_DEBUG_LOG === "true") {
if (getDebugLog()) {
console.log("Plus-Icon Position:", clickedLatLng);
}
@@ -72,7 +72,7 @@ export const handlePlusIconClick = (map, markers, oms, clickedLatLng) => {
);
// Debugging-Ausgabe
if (process.env.NEXT_PUBLIC_DEBUG_LOG === "true") {
if (getDebugLog()) {
console.log("Gefundene Marker in der Nähe:", nearbyMarkers);
}
@@ -80,7 +80,7 @@ export const handlePlusIconClick = (map, markers, oms, clickedLatLng) => {
// Spiderfy die gefundenen Marker
oms.spiderfy(nearbyMarkers);
} else {
if (process.env.NEXT_PUBLIC_DEBUG_LOG === "true") {
if (getDebugLog()) {
console.log("Keine überlappenden Marker gefunden.");
}
}

View File

@@ -26,12 +26,12 @@ function getPool() {
cachedPool.on("acquire", () => {
connectionCount++;
if (process.env.NODE_ENV === "development") {
if (process.env.NEXT_PUBLIC_DEBUG_LOG === "true") {
if (getDebugLog()) {
console.log("\x1b[36m%s\x1b[0m", ` Connection acquired (${connectionCount} total)`);
}
if (connectionCount > maxUsed) {
maxUsed = connectionCount;
if (process.env.NEXT_PUBLIC_DEBUG_LOG === "true") {
if (getDebugLog()) {
console.log(`📈 Neue Höchstzahl aktiver gleichzeitiger Verbindungen: ${maxUsed}`);
}
}
@@ -40,7 +40,7 @@ function getPool() {
cachedPool.on("release", () => {
connectionCount--;
if (process.env.NODE_ENV === "development") {
if (process.env.NEXT_PUBLIC_DEBUG_LOG === "true") {
if (getDebugLog()) {
console.log("\x1b[32m%s\x1b[0m", ` Connection released (${connectionCount} total)`);
}
}
@@ -48,7 +48,7 @@ function getPool() {
cachedPool.on("enqueue", () => {
if (process.env.NODE_ENV === "development") {
if (process.env.NEXT_PUBLIC_DEBUG_LOG === "true") {
if (getDebugLog()) {
console.warn("\x1b[33m%s\x1b[0m", "⏳ Pool voll Anfrage in Warteschlange");
}
}

View File

@@ -30,7 +30,7 @@ export async function openInNewTab(e, target) {
}
if (link) {
if (process.env.NEXT_PUBLIC_DEBUG_LOG === "true") {
if (getDebugLog()) {
console.log("🟢 Öffne Link:", link);
}
window.open(link, "_blank");

View File

@@ -6,7 +6,7 @@ export function subscribeToPolylineContextMenu() {
store.subscribe(() => {
const state = store.getState(); // Redux-Toolkit empfohlene Methode
if (state.polylineContextMenu.forceClose) {
if (process.env.NEXT_PUBLIC_DEBUG_LOG === "true") {
if (getDebugLog()) {
console.log("🚀 Redux-Event erkannt - Kontextmenü wird geschlossen.");
}
store.dispatch(closePolylineContextMenu());

View File

@@ -113,7 +113,7 @@ export const setupPolylines = async (
.dispatch(updatePolylineCoordinatesThunk(requestData))
.unwrap()
.then(data => {
if (process.env.NEXT_PUBLIC_DEBUG_LOG === "true") {
if (getDebugLog()) {
console.log("Koordinaten erfolgreich aktualisiert:", data);
}
})

View File

@@ -1,17 +1,19 @@
// utils/setupDevices.js
import { setSelectedDevice, clearSelectedDevice } from "../redux/slices/selectedDeviceSlice";
import { getDebugLog } from "./configUtils";
export const setupDevices = async (map, deviceMarkers, dispatch) => {
for (const marker of deviceMarkers) {
marker.on("mouseover", function () {
if (process.env.NEXT_PUBLIC_DEBUG_LOG === "true") {
if (getDebugLog()) {
console.log("✅ Gerät ausgewählt:", marker);
}
dispatch(setSelectedDevice(marker.options)); // Gerät in Redux speichern
});
marker.on("mouseout", function () {
if (process.env.NEXT_PUBLIC_DEBUG_LOG === "true") {
if (getDebugLog()) {
console.log("❌ Gerät abgewählt");
}
dispatch(clearSelectedDevice()); // Gerät aus Redux entfernen