2018-08-14 12:11:49 +00:00
|
|
|
/*
|
|
|
|
* noVNC: HTML5 VNC client
|
2019-06-24 11:26:25 +00:00
|
|
|
* Copyright (C) 2018 The noVNC Authors
|
2018-08-14 12:11:49 +00:00
|
|
|
* Licensed under MPL 2.0 (see LICENSE.txt)
|
|
|
|
*
|
|
|
|
* See README.md for usage and integration instructions.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Logging/debug routines
|
|
|
|
*/
|
|
|
|
|
2019-06-24 11:26:25 +00:00
|
|
|
let _log_level = 'warn';
|
2018-08-14 12:11:49 +00:00
|
|
|
|
2019-06-24 11:26:25 +00:00
|
|
|
let Debug = () => {};
|
|
|
|
let Info = () => {};
|
|
|
|
let Warn = () => {};
|
|
|
|
let Error = () => {};
|
2018-08-14 12:11:49 +00:00
|
|
|
|
2019-06-24 11:26:25 +00:00
|
|
|
export function init_logging(level) {
|
2018-08-14 12:11:49 +00:00
|
|
|
if (typeof level === 'undefined') {
|
|
|
|
level = _log_level;
|
|
|
|
} else {
|
|
|
|
_log_level = level;
|
|
|
|
}
|
|
|
|
|
2019-06-24 11:26:25 +00:00
|
|
|
Debug = Info = Warn = Error = () => {};
|
|
|
|
|
2018-08-14 12:11:49 +00:00
|
|
|
if (typeof window.console !== "undefined") {
|
2019-06-24 11:26:25 +00:00
|
|
|
/* eslint-disable no-console, no-fallthrough */
|
2018-08-14 12:11:49 +00:00
|
|
|
switch (level) {
|
|
|
|
case 'debug':
|
2018-08-27 12:30:50 +00:00
|
|
|
Debug = console.debug.bind(window.console);
|
2018-08-14 12:11:49 +00:00
|
|
|
case 'info':
|
2018-08-27 12:30:50 +00:00
|
|
|
Info = console.info.bind(window.console);
|
2018-08-14 12:11:49 +00:00
|
|
|
case 'warn':
|
2018-08-27 12:30:50 +00:00
|
|
|
Warn = console.warn.bind(window.console);
|
2018-08-14 12:11:49 +00:00
|
|
|
case 'error':
|
2018-08-27 12:30:50 +00:00
|
|
|
Error = console.error.bind(window.console);
|
2018-08-14 12:11:49 +00:00
|
|
|
case 'none':
|
|
|
|
break;
|
|
|
|
default:
|
2019-06-24 11:26:25 +00:00
|
|
|
throw new window.Error("invalid logging type '" + level + "'");
|
2018-08-14 12:11:49 +00:00
|
|
|
}
|
2019-06-24 11:26:25 +00:00
|
|
|
/* eslint-enable no-console, no-fallthrough */
|
2018-08-14 12:11:49 +00:00
|
|
|
}
|
2019-06-24 11:26:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function get_logging() {
|
2018-08-14 12:11:49 +00:00
|
|
|
return _log_level;
|
2019-06-24 11:26:25 +00:00
|
|
|
}
|
|
|
|
|
2018-08-27 12:30:50 +00:00
|
|
|
export { Debug, Info, Warn, Error };
|
2018-08-14 12:11:49 +00:00
|
|
|
|
|
|
|
// Initialize logging level
|
2018-08-27 12:30:50 +00:00
|
|
|
init_logging();
|