2018-08-14 12:11:49 +00:00
|
|
|
/*
|
|
|
|
* noVNC: HTML5 VNC client
|
|
|
|
* Copyright (C) 2012 Joel Martin
|
|
|
|
* Licensed under MPL 2.0 (see LICENSE.txt)
|
|
|
|
*
|
|
|
|
* See README.md for usage and integration instructions.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Logging/debug routines
|
|
|
|
*/
|
|
|
|
|
|
|
|
var _log_level = 'warn';
|
|
|
|
|
|
|
|
var Debug = function (msg) {};
|
|
|
|
var Info = function (msg) {};
|
|
|
|
var Warn = function (msg) {};
|
|
|
|
var Error = function (msg) {};
|
|
|
|
|
2018-08-27 12:30:50 +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;
|
|
|
|
}
|
|
|
|
|
2018-08-27 12:30:50 +00:00
|
|
|
Debug = Info = Warn = Error = function (msg) {};
|
2018-08-14 12:11:49 +00:00
|
|
|
if (typeof window.console !== "undefined") {
|
|
|
|
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:
|
|
|
|
throw new Error("invalid logging type '" + level + "'");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2018-08-27 12:30:50 +00:00
|
|
|
export function get_logging () {
|
2018-08-14 12:11:49 +00:00
|
|
|
return _log_level;
|
|
|
|
};
|
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();
|