logging.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * noVNC: HTML5 VNC client
  3. * Copyright (C) 2018 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. * Logging/debug routines
  10. */
  11. let _log_level = 'warn';
  12. let Debug = () => {};
  13. let Info = () => {};
  14. let Warn = () => {};
  15. let Error = () => {};
  16. export function init_logging(level) {
  17. if (typeof level === 'undefined') {
  18. level = _log_level;
  19. } else {
  20. _log_level = level;
  21. }
  22. Debug = Info = Warn = Error = () => {};
  23. if (typeof window.console !== "undefined") {
  24. /* eslint-disable no-console, no-fallthrough */
  25. switch (level) {
  26. case 'debug':
  27. Debug = console.debug.bind(window.console);
  28. case 'info':
  29. Info = console.info.bind(window.console);
  30. case 'warn':
  31. Warn = console.warn.bind(window.console);
  32. case 'error':
  33. Error = console.error.bind(window.console);
  34. case 'none':
  35. break;
  36. default:
  37. throw new window.Error("invalid logging type '" + level + "'");
  38. }
  39. /* eslint-enable no-console, no-fallthrough */
  40. }
  41. }
  42. export function get_logging() {
  43. return _log_level;
  44. }
  45. export { Debug, Info, Warn, Error };
  46. // Initialize logging level
  47. init_logging();