Skip to content

Commit 6fbe620

Browse files
committed
debug: Show debug logs in prod
1 parent e722d1a commit 6fbe620

File tree

2 files changed

+56
-44
lines changed

2 files changed

+56
-44
lines changed
+50-44
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,76 @@
1-
import log from 'loglevel';
1+
import log from "loglevel";
22

3-
log.setLevel(process.env.NODE_ENV === 'production' ? 'error' : 'debug');
3+
log.setLevel(process.env.NODE_ENV === "production" ? "debug" : "debug");
44

55
function getCallerInfo() {
6-
const stack = new Error().stack;
7-
if (!stack) {
8-
return '';
9-
}
6+
const stack = new Error().stack;
7+
if (!stack) {
8+
return "";
9+
}
1010

11-
const stackLines = stack.split('\n');
12-
const callerLine = stackLines[3] || '';
13-
const matchResult = callerLine.match(/\((.*):(\d+):(\d+)\)$/);
11+
const stackLines = stack.split("\n");
12+
const callerLine = stackLines[3] || "";
13+
const matchResult = callerLine.match(/\((.*):(\d+):(\d+)\)$/);
1414

15-
if (matchResult && matchResult.length === 4) {
16-
const file = matchResult[1];
17-
const line = matchResult[2];
18-
const column = matchResult[3];
19-
return `${file}:${line}:${column}`;
20-
}
21-
return '';
15+
if (matchResult && matchResult.length === 4) {
16+
const file = matchResult[1];
17+
const line = matchResult[2];
18+
const column = matchResult[3];
19+
return `${file}:${line}:${column}`;
20+
}
21+
return "";
2222
}
2323

2424
const createLoggerFunction =
25-
(logFunction: (...args: any[]) => void) =>
26-
(message: string, ...args: any[]) => {
27-
const callerInfo = getCallerInfo();
28-
logFunction(`${message} (${callerInfo})`, ...args);
29-
};
25+
(logFunction: (...args: any[]) => void) =>
26+
(message: string, ...args: any[]) => {
27+
const callerInfo = getCallerInfo();
28+
logFunction(`${message} (${callerInfo})`, ...args);
29+
};
3030

3131
// Function to start a log group
3232
const startGroup = (groupName: string) => {
33-
const callerInfo = getCallerInfo();
34-
console.group(`${groupName} (${callerInfo})`);
33+
const callerInfo = getCallerInfo();
34+
console.group(`${groupName} (${callerInfo})`);
3535
};
3636

3737
// Function to end a log group
3838
const endGroup = () => {
39-
console.groupEnd();
39+
console.groupEnd();
4040
};
4141

4242
// Helper function to log multiple messages within a group
43-
const logGroup = (groupName: string, messages: { level: keyof typeof log; message: string; args?: any[] }[]) => {
44-
startGroup(groupName);
45-
messages.forEach(({ level, message, args }) => {
46-
if (typeof log[level] === 'function') {
47-
createLoggerFunction(log[level] as (...args: any[]) => void)(message, ...(args || []));
48-
}
49-
});
50-
endGroup();
43+
const logGroup = (
44+
groupName: string,
45+
messages: { level: keyof typeof log; message: string; args?: any[] }[],
46+
) => {
47+
startGroup(groupName);
48+
messages.forEach(({ level, message, args }) => {
49+
if (typeof log[level] === "function") {
50+
createLoggerFunction(log[level] as (...args: any[]) => void)(
51+
message,
52+
...(args || []),
53+
);
54+
}
55+
});
56+
endGroup();
5157
};
5258

5359
// Custom FetchDebug logger
5460
const fetchDebug = createLoggerFunction((...args: any[]) => {
55-
const a = log.getLevel();
56-
if (a <= log.levels.DEBUG) {
57-
console.debug(...args);
58-
}
61+
const a = log.getLevel();
62+
if (a <= log.levels.DEBUG) {
63+
console.debug(...args);
64+
}
5965
});
6066

6167
export const Logger = {
62-
debug: createLoggerFunction(log.debug),
63-
endGroup,
64-
error: createLoggerFunction(log.error),
65-
fetchDebug,
66-
info: createLoggerFunction(log.info),
67-
logGroup,
68-
startGroup,
69-
warn: createLoggerFunction(log.warn)
68+
debug: createLoggerFunction(log.debug),
69+
endGroup,
70+
error: createLoggerFunction(log.error),
71+
fetchDebug,
72+
info: createLoggerFunction(log.info),
73+
logGroup,
74+
startGroup,
75+
warn: createLoggerFunction(log.warn),
7076
};

src/StreamMaster.WebUI/lib/settings.ts

+6
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ export const getBasePath = () => {
2727
// https://vite.dev/guide/assets#new-url-url-import-meta-url
2828
const currentUrl = new URL(import.meta.url);
2929

30+
Logger.debug("Using Module URL of:", currentUrl);
31+
3032
// Module URL typically points to /assets/[hash].js
3133
// We need to go up to the root directory...
3234
const pathParts = currentUrl.pathname.split("/");
@@ -37,6 +39,8 @@ export const getBasePath = () => {
3739
if (assetsIndex !== -1) {
3840
// Remove everything from assets onwards to get the app's root path
3941
const basePath = `${pathParts.slice(0, assetsIndex).join("/")}/`;
42+
43+
Logger.debug("Base Path resolved to:", basePath);
4044
return basePath;
4145
}
4246

@@ -86,6 +90,8 @@ export const loadConfig = async (): Promise<AppConfig> => {
8690
...defaultConfig,
8791
...data,
8892
};
93+
94+
Logger.debug("Config loaded:", configData);
8995
return configData;
9096
} catch (error) {
9197
Logger.error("Config loading error:", error);

0 commit comments

Comments
 (0)