Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

logger.js 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* Magic Mirror
  2. * Log
  3. *
  4. * This logger is very simple, but needs to be extended.
  5. * This system can eventually be used to push the log messages to an external target.
  6. *
  7. * By Michael Teeuw https://michaelteeuw.nl
  8. * MIT Licensed.
  9. */
  10. (function (root, factory) {
  11. if (typeof exports === "object") {
  12. if (process.env.JEST_WORKER_ID === undefined) {
  13. // add timestamps in front of log messages
  14. require("console-stamp")(console, {
  15. pattern: "yyyy-mm-dd HH:MM:ss.l",
  16. include: ["debug", "log", "info", "warn", "error"]
  17. });
  18. }
  19. // Node, CommonJS-like
  20. module.exports = factory(root.config);
  21. } else {
  22. // Browser globals (root is window)
  23. root.Log = factory(root.config);
  24. }
  25. })(this, function (config) {
  26. let logLevel;
  27. let enableLog;
  28. if (typeof exports === "object") {
  29. // in nodejs and not running with jest
  30. enableLog = process.env.JEST_WORKER_ID === undefined;
  31. } else {
  32. // in browser and not running with jsdom
  33. enableLog = typeof window === "object" && window.name !== "jsdom";
  34. }
  35. if (enableLog) {
  36. logLevel = {
  37. debug: Function.prototype.bind.call(console.debug, console),
  38. log: Function.prototype.bind.call(console.log, console),
  39. info: Function.prototype.bind.call(console.info, console),
  40. warn: Function.prototype.bind.call(console.warn, console),
  41. error: Function.prototype.bind.call(console.error, console),
  42. group: Function.prototype.bind.call(console.group, console),
  43. groupCollapsed: Function.prototype.bind.call(console.groupCollapsed, console),
  44. groupEnd: Function.prototype.bind.call(console.groupEnd, console),
  45. time: Function.prototype.bind.call(console.time, console),
  46. timeEnd: Function.prototype.bind.call(console.timeEnd, console),
  47. timeStamp: Function.prototype.bind.call(console.timeStamp, console)
  48. };
  49. logLevel.setLogLevel = function (newLevel) {
  50. if (newLevel) {
  51. Object.keys(logLevel).forEach(function (key, index) {
  52. if (!newLevel.includes(key.toLocaleUpperCase())) {
  53. logLevel[key] = function () {};
  54. }
  55. });
  56. }
  57. };
  58. } else {
  59. logLevel = {
  60. debug: function () {},
  61. log: function () {},
  62. info: function () {},
  63. warn: function () {},
  64. error: function () {},
  65. group: function () {},
  66. groupCollapsed: function () {},
  67. groupEnd: function () {},
  68. time: function () {},
  69. timeEnd: function () {},
  70. timeStamp: function () {}
  71. };
  72. logLevel.setLogLevel = function () {};
  73. }
  74. return logLevel;
  75. });