logger.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. "use strict";
  2. /**
  3. * @fileOverview The logging system for papyrus is based on [http://pimterry.github.io/loglevel/](loglevel) and slightly decorated
  4. * @module utils/logger
  5. * @requires dcl
  6. * @requires loglevel
  7. */
  8. var dcl = require( "dcl" );
  9. var log = require( 'loglevel' );
  10. /**
  11. * A logger class that you can mix into your classes to handle logging settings and state at an object level.
  12. * See {@link utils/logger} for the members of this class
  13. *
  14. * @exports utils/logger.Logger
  15. * @class
  16. * @see utils/logger
  17. */
  18. var Logger = dcl( null, /** @lends utils/logger.Logger# */{
  19. declaredClass : "utils/Logger",
  20. /**
  21. * Turn off all logging. If you log something, it will not error, but will not do anything either
  22. * and the cycles are minimal.
  23. *
  24. */
  25. silent : function () {
  26. log.disableAll();
  27. },
  28. /**
  29. * Turns on all logging levels
  30. *
  31. */
  32. all : function () {
  33. log.enableAll();
  34. },
  35. /**
  36. * Sets the logging level to one of `trace`, `debug`, `info`, `warn`, `error`.
  37. * @param {string} lvl The level to set it to. Can be one of `trace`, `debug`, `info`, `warn`, `error`.
  38. *
  39. */
  40. level : function ( lvl ) {
  41. if ( lvl.toLowerCase() === "none" ) {
  42. log.disableAll();
  43. } else {
  44. log.setLevel( lvl );
  45. }
  46. },
  47. /**
  48. * Log a `trace` call
  49. * @method
  50. * @param {string} The value to log
  51. */
  52. trace : log.trace,
  53. /**
  54. * Log a `debug` call
  55. * @method
  56. * @param {string} The value to log
  57. */
  58. debug : log.debug,
  59. /**
  60. * Log a `info` call
  61. * @method
  62. * @param {string} The value to log
  63. */
  64. info : log.info,
  65. /**
  66. * Log a `warn` call
  67. * @method
  68. * @param {string} The value to log
  69. */
  70. warn : log.warn,
  71. /**
  72. * Log a `error` call
  73. * @method
  74. * @param {string} The value to log
  75. */
  76. error : log.error
  77. } );
  78. module.exports = new Logger();
  79. /**
  80. * The system global, cross-platform logger
  81. * @name utils/logger
  82. * @static
  83. * @type {utils/logger.Logger}
  84. */
  85. module.exports.Logger = Logger;