]> git.proxmox.com Git - mirror_novnc.git/blob - core/util/logging.js
8978a07518c1da6d3283212ea4267cc8876f8893
[mirror_novnc.git] / core / util / logging.js
1 /*
2 * noVNC: HTML5 VNC client
3 * Copyright (C) 2019 The noVNC Authors
4 * Licensed under MPL 2.0 (see LICENSE.txt)
5 *
6 * See README.md for usage and integration instructions.
7 */
8
9 /*
10 * Logging/debug routines
11 */
12
13 let _log_level = 'warn';
14
15 let Debug = () => {};
16 let Info = () => {};
17 let Warn = () => {};
18 let Error = () => {};
19
20 export function init_logging(level) {
21 if (typeof level === 'undefined') {
22 level = _log_level;
23 } else {
24 _log_level = level;
25 }
26
27 Debug = Info = Warn = Error = () => {};
28
29 if (typeof window.console !== "undefined") {
30 /* eslint-disable no-console, no-fallthrough */
31 switch (level) {
32 case 'debug':
33 Debug = console.debug.bind(window.console);
34 case 'info':
35 Info = console.info.bind(window.console);
36 case 'warn':
37 Warn = console.warn.bind(window.console);
38 case 'error':
39 Error = console.error.bind(window.console);
40 case 'none':
41 break;
42 default:
43 throw new window.Error("invalid logging type '" + level + "'");
44 }
45 /* eslint-enable no-console, no-fallthrough */
46 }
47 }
48
49 export function get_logging() {
50 return _log_level;
51 }
52
53 export { Debug, Info, Warn, Error };
54
55 // Initialize logging level
56 init_logging();