Improve mpv error logging

This commit is contained in:
jeffvli 2024-02-12 20:11:55 -08:00
parent ff4ce89bc9
commit 60105103f3
4 changed files with 178 additions and 131 deletions

View file

@ -52,7 +52,7 @@ export const hotkeyToElectronAccelerator = (hotkey: string) => {
return accelerator;
};
const logInstance = {
const logMethod = {
debug: log.debug,
error: log.error,
info: log.info,
@ -61,9 +61,36 @@ const logInstance = {
warning: log.warn,
};
const logColor = {
debug: 'blue',
error: 'red',
info: 'blue',
success: 'green',
verbose: 'blue',
warning: 'yellow',
};
export const createLog = (data: {
message: string;
type: 'debug' | 'verbose' | 'success' | 'error' | 'warning' | 'info';
}) => {
logInstance[data.type](data.message);
logMethod[data.type](`%c${data.message}`, `color: ${logColor[data.type]}`);
};
export const autoUpdaterLogInterface = {
debug: (message: string) => {
createLog({ message: `[SYSTEM] ${message}`, type: 'debug' });
},
error: (message: string) => {
createLog({ message: `[SYSTEM] ${message}`, type: 'error' });
},
info: (message: string) => {
createLog({ message: `[SYSTEM] ${message}`, type: 'info' });
},
warn: (message: string) => {
createLog({ message: `[SYSTEM] ${message}`, type: 'warning' });
},
};