logging.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * noVNC: HTML5 VNC client
  3. * Copyright (C) 2012 Joel Martin
  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. var _log_level = 'warn';
  12. var Debug = function (msg) {};
  13. var Info = function (msg) {};
  14. var Warn = function (msg) {};
  15. var Error = function (msg) {};
  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 = function (msg) {};
  23. if (typeof window.console !== "undefined") {
  24. /* jshint -W086 */
  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 Error("invalid logging type '" + level + "'");
  38. }
  39. /* jshint +W086 */
  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();