2020-06-06 21:55:47 -04:00
|
|
|
/*
|
|
|
|
* noVNC: HTML5 VNC client
|
2021-11-29 15:08:15 -05:00
|
|
|
* Copyright (C) 2019 The noVNC Authors
|
2020-06-06 21:55:47 -04:00
|
|
|
* Licensed under MPL 2.0 (see LICENSE.txt)
|
|
|
|
*
|
|
|
|
* See README.md for usage and integration instructions.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Logging/debug routines
|
|
|
|
*/
|
|
|
|
|
2021-11-29 15:08:15 -05:00
|
|
|
let _logLevel = 'warn';
|
2020-06-06 21:55:47 -04:00
|
|
|
|
|
|
|
let Debug = () => {};
|
|
|
|
let Info = () => {};
|
|
|
|
let Warn = () => {};
|
|
|
|
let Error = () => {};
|
|
|
|
|
2021-11-29 15:08:15 -05:00
|
|
|
export function initLogging(level) {
|
2020-06-06 21:55:47 -04:00
|
|
|
if (typeof level === 'undefined') {
|
2021-11-29 15:08:15 -05:00
|
|
|
level = _logLevel;
|
2020-06-06 21:55:47 -04:00
|
|
|
} else {
|
2021-11-29 15:08:15 -05:00
|
|
|
_logLevel = level;
|
2020-06-06 21:55:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
Debug = Info = Warn = Error = () => {};
|
|
|
|
|
|
|
|
if (typeof window.console !== "undefined") {
|
|
|
|
/* eslint-disable no-console, no-fallthrough */
|
|
|
|
switch (level) {
|
|
|
|
case 'debug':
|
|
|
|
Debug = console.debug.bind(window.console);
|
|
|
|
case 'info':
|
|
|
|
Info = console.info.bind(window.console);
|
|
|
|
case 'warn':
|
|
|
|
Warn = console.warn.bind(window.console);
|
|
|
|
case 'error':
|
|
|
|
Error = console.error.bind(window.console);
|
|
|
|
case 'none':
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new window.Error("invalid logging type '" + level + "'");
|
|
|
|
}
|
|
|
|
/* eslint-enable no-console, no-fallthrough */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-29 15:08:15 -05:00
|
|
|
export function getLogging() {
|
|
|
|
return _logLevel;
|
2020-06-06 21:55:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export { Debug, Info, Warn, Error };
|
|
|
|
|
|
|
|
// Initialize logging level
|
2021-11-29 15:08:15 -05:00
|
|
|
initLogging();
|