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:
26
utils/configUtils.js
Normal file
26
utils/configUtils.js
Normal 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;
|
||||
}
|
||||
@@ -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.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
})
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user