main
Raw Download raw file
 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
13let _logLevel = 'warn';
14
15let Debug = () => {};
16let Info = () => {};
17let Warn = () => {};
18let Error = () => {};
19
20export function initLogging(level) {
21    if (typeof level === 'undefined') {
22        level = _logLevel;
23    } else {
24        _logLevel = 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
49export function getLogging() {
50    return _logLevel;
51}
52
53export { Debug, Info, Warn, Error };
54
55// Initialize logging level
56initLogging();