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.

index.js 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. "use strict";
  2. // cache a reference to setTimeout, so that our reference won't be stubbed out
  3. // when using fake timers and errors will still get logged
  4. // https://github.com/cjohansen/Sinon.JS/issues/381
  5. var realSetTimeout = setTimeout;
  6. function configureLogger(config) {
  7. // eslint-disable-next-line no-param-reassign
  8. config = config || {};
  9. // Function which prints errors.
  10. if (!config.hasOwnProperty("logger")) {
  11. // eslint-disable-next-line no-empty-function
  12. config.logger = function() {};
  13. }
  14. // When set to true, any errors logged will be thrown immediately;
  15. // If set to false, the errors will be thrown in separate execution frame.
  16. if (!config.hasOwnProperty("useImmediateExceptions")) {
  17. config.useImmediateExceptions = true;
  18. }
  19. // wrap realSetTimeout with something we can stub in tests
  20. if (!config.hasOwnProperty("setTimeout")) {
  21. config.setTimeout = realSetTimeout;
  22. }
  23. return function logError(label, e) {
  24. var msg = `${label} threw exception: `;
  25. var err = {
  26. name: e.name || label,
  27. message: e.message || e.toString(),
  28. stack: e.stack
  29. };
  30. function throwLoggedError() {
  31. err.message = msg + err.message;
  32. throw err;
  33. }
  34. config.logger(`${msg}[${err.name}] ${err.message}`);
  35. if (err.stack) {
  36. config.logger(err.stack);
  37. }
  38. if (config.useImmediateExceptions) {
  39. throwLoggedError();
  40. } else {
  41. config.setTimeout(throwLoggedError, 0);
  42. }
  43. };
  44. }
  45. module.exports = configureLogger;