Chore: Improve EchoSrv logging (#76385)

* Chore: Allow frontend logging to be logged via localStorage

* improve echo srv logging
This commit is contained in:
Josh Hunt 2023-10-12 09:00:32 +00:00 committed by GitHub
parent 2771fb9403
commit 46b0066644
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 7 deletions

View File

@ -19,17 +19,22 @@ export interface Logger {
/** @internal */
export const createLogger = (name: string): Logger => {
let LOGGIN_ENABLED = false;
let loggingEnabled = false;
if (typeof window !== 'undefined') {
loggingEnabled = window.localStorage.getItem('grafana.debug') === 'true';
}
return {
logger: (id: string, throttle = false, ...t: any[]) => {
if (process.env.NODE_ENV === 'production' || process.env.NODE_ENV === 'test' || !LOGGIN_ENABLED) {
if (process.env.NODE_ENV === 'production' || process.env.NODE_ENV === 'test' || !loggingEnabled) {
return;
}
const fn = throttle ? throttledLog : console.log;
fn(`[${name}: ${id}]: `, ...t);
fn(`[${name}: ${id}]:`, ...t);
},
enable: () => (LOGGIN_ENABLED = true),
disable: () => (LOGGIN_ENABLED = false),
isEnabled: () => LOGGIN_ENABLED,
enable: () => (loggingEnabled = true),
disable: () => (loggingEnabled = false),
isEnabled: () => loggingEnabled,
};
};

View File

@ -59,7 +59,11 @@ export class Echo implements EchoSrv {
backend.addEvent(_event);
}
}
echoLog('Reporting event', false, _event);
echoLog(`${event.type} event`, false, {
...event.payload,
meta: _event.meta,
});
};
getMeta = (): EchoMeta => {