Add control to enable debug logging in production
This commit is contained in:
@@ -5,6 +5,7 @@ import { createAction } from "~/actions";
|
||||
import { DeveloperSection } from "~/actions/sections";
|
||||
import env from "~/env";
|
||||
import { client } from "~/utils/ApiClient";
|
||||
import Logger from "~/utils/Logger";
|
||||
import { deleteAllDatabases } from "~/utils/developer";
|
||||
|
||||
export const clearIndexedDB = createAction({
|
||||
@@ -35,16 +36,27 @@ export const createTestUsers = createAction({
|
||||
},
|
||||
});
|
||||
|
||||
export const toggleDebugLogging = createAction({
|
||||
name: ({ t }) => t("Toggle debug logging"),
|
||||
icon: <ToolsIcon />,
|
||||
section: DeveloperSection,
|
||||
perform: async ({ t }) => {
|
||||
Logger.debugLoggingEnabled = !Logger.debugLoggingEnabled;
|
||||
stores.toasts.showToast(
|
||||
Logger.debugLoggingEnabled
|
||||
? t("Debug logging enabled")
|
||||
: t("Debug logging disabled")
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
export const developer = createAction({
|
||||
name: ({ t }) => t("Developer"),
|
||||
name: ({ t }) => t("Development"),
|
||||
keywords: "debug",
|
||||
icon: <ToolsIcon />,
|
||||
iconInContextMenu: false,
|
||||
section: DeveloperSection,
|
||||
visible: ({ event }) =>
|
||||
env.ENVIRONMENT === "development" ||
|
||||
(event instanceof KeyboardEvent && event.altKey),
|
||||
children: [clearIndexedDB, createTestUsers],
|
||||
children: [clearIndexedDB, toggleDebugLogging, createTestUsers],
|
||||
});
|
||||
|
||||
export const rootDeveloperActions = [developer];
|
||||
|
||||
@@ -30,7 +30,7 @@ class Logger {
|
||||
* @param extra Arbitrary data to be logged
|
||||
*/
|
||||
debug(label: LogCategory, message: string, extra?: Extra) {
|
||||
if (env.ENVIRONMENT === "development") {
|
||||
if (env.ENVIRONMENT === "development" || this.debugLoggingEnabled) {
|
||||
console.debug(`[${label}] ${message}`, extra);
|
||||
}
|
||||
}
|
||||
@@ -82,6 +82,11 @@ class Logger {
|
||||
extra,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether additional debug logging is shown in the console or not.
|
||||
*/
|
||||
public debugLoggingEnabled = false;
|
||||
}
|
||||
|
||||
export default new Logger();
|
||||
|
||||
@@ -12,7 +12,10 @@
|
||||
"Delete collection": "Delete collection",
|
||||
"Delete IndexedDB cache": "Delete IndexedDB cache",
|
||||
"IndexedDB cache deleted": "IndexedDB cache deleted",
|
||||
"Developer": "Developer",
|
||||
"Toggle debug logging": "Toggle debug logging",
|
||||
"Debug logging enabled": "Debug logging enabled",
|
||||
"Debug logging disabled": "Debug logging disabled",
|
||||
"Development": "Development",
|
||||
"Open document": "Open document",
|
||||
"New document": "New document",
|
||||
"Publish": "Publish",
|
||||
|
||||
Reference in New Issue
Block a user