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.

loglevel.js 8.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. /*! loglevel - v1.7.1 - https://github.com/pimterry/loglevel - (c) 2020 Tim Perry - licensed MIT */
  2. (function (root, definition) {
  3. "use strict";
  4. if (typeof define === 'function' && define.amd) {
  5. define(definition);
  6. } else if (typeof module === 'object' && module.exports) {
  7. module.exports = definition();
  8. } else {
  9. root.log = definition();
  10. }
  11. }(this, function () {
  12. "use strict";
  13. // Slightly dubious tricks to cut down minimized file size
  14. var noop = function() {};
  15. var undefinedType = "undefined";
  16. var isIE = (typeof window !== undefinedType) && (typeof window.navigator !== undefinedType) && (
  17. /Trident\/|MSIE /.test(window.navigator.userAgent)
  18. );
  19. var logMethods = [
  20. "trace",
  21. "debug",
  22. "info",
  23. "warn",
  24. "error"
  25. ];
  26. // Cross-browser bind equivalent that works at least back to IE6
  27. function bindMethod(obj, methodName) {
  28. var method = obj[methodName];
  29. if (typeof method.bind === 'function') {
  30. return method.bind(obj);
  31. } else {
  32. try {
  33. return Function.prototype.bind.call(method, obj);
  34. } catch (e) {
  35. // Missing bind shim or IE8 + Modernizr, fallback to wrapping
  36. return function() {
  37. return Function.prototype.apply.apply(method, [obj, arguments]);
  38. };
  39. }
  40. }
  41. }
  42. // Trace() doesn't print the message in IE, so for that case we need to wrap it
  43. function traceForIE() {
  44. if (console.log) {
  45. if (console.log.apply) {
  46. console.log.apply(console, arguments);
  47. } else {
  48. // In old IE, native console methods themselves don't have apply().
  49. Function.prototype.apply.apply(console.log, [console, arguments]);
  50. }
  51. }
  52. if (console.trace) console.trace();
  53. }
  54. // Build the best logging method possible for this env
  55. // Wherever possible we want to bind, not wrap, to preserve stack traces
  56. function realMethod(methodName) {
  57. if (methodName === 'debug') {
  58. methodName = 'log';
  59. }
  60. if (typeof console === undefinedType) {
  61. return false; // No method possible, for now - fixed later by enableLoggingWhenConsoleArrives
  62. } else if (methodName === 'trace' && isIE) {
  63. return traceForIE;
  64. } else if (console[methodName] !== undefined) {
  65. return bindMethod(console, methodName);
  66. } else if (console.log !== undefined) {
  67. return bindMethod(console, 'log');
  68. } else {
  69. return noop;
  70. }
  71. }
  72. // These private functions always need `this` to be set properly
  73. function replaceLoggingMethods(level, loggerName) {
  74. /*jshint validthis:true */
  75. for (var i = 0; i < logMethods.length; i++) {
  76. var methodName = logMethods[i];
  77. this[methodName] = (i < level) ?
  78. noop :
  79. this.methodFactory(methodName, level, loggerName);
  80. }
  81. // Define log.log as an alias for log.debug
  82. this.log = this.debug;
  83. }
  84. // In old IE versions, the console isn't present until you first open it.
  85. // We build realMethod() replacements here that regenerate logging methods
  86. function enableLoggingWhenConsoleArrives(methodName, level, loggerName) {
  87. return function () {
  88. if (typeof console !== undefinedType) {
  89. replaceLoggingMethods.call(this, level, loggerName);
  90. this[methodName].apply(this, arguments);
  91. }
  92. };
  93. }
  94. // By default, we use closely bound real methods wherever possible, and
  95. // otherwise we wait for a console to appear, and then try again.
  96. function defaultMethodFactory(methodName, level, loggerName) {
  97. /*jshint validthis:true */
  98. return realMethod(methodName) ||
  99. enableLoggingWhenConsoleArrives.apply(this, arguments);
  100. }
  101. function Logger(name, defaultLevel, factory) {
  102. var self = this;
  103. var currentLevel;
  104. var storageKey = "loglevel";
  105. if (typeof name === "string") {
  106. storageKey += ":" + name;
  107. } else if (typeof name === "symbol") {
  108. storageKey = undefined;
  109. }
  110. function persistLevelIfPossible(levelNum) {
  111. var levelName = (logMethods[levelNum] || 'silent').toUpperCase();
  112. if (typeof window === undefinedType || !storageKey) return;
  113. // Use localStorage if available
  114. try {
  115. window.localStorage[storageKey] = levelName;
  116. return;
  117. } catch (ignore) {}
  118. // Use session cookie as fallback
  119. try {
  120. window.document.cookie =
  121. encodeURIComponent(storageKey) + "=" + levelName + ";";
  122. } catch (ignore) {}
  123. }
  124. function getPersistedLevel() {
  125. var storedLevel;
  126. if (typeof window === undefinedType || !storageKey) return;
  127. try {
  128. storedLevel = window.localStorage[storageKey];
  129. } catch (ignore) {}
  130. // Fallback to cookies if local storage gives us nothing
  131. if (typeof storedLevel === undefinedType) {
  132. try {
  133. var cookie = window.document.cookie;
  134. var location = cookie.indexOf(
  135. encodeURIComponent(storageKey) + "=");
  136. if (location !== -1) {
  137. storedLevel = /^([^;]+)/.exec(cookie.slice(location))[1];
  138. }
  139. } catch (ignore) {}
  140. }
  141. // If the stored level is not valid, treat it as if nothing was stored.
  142. if (self.levels[storedLevel] === undefined) {
  143. storedLevel = undefined;
  144. }
  145. return storedLevel;
  146. }
  147. /*
  148. *
  149. * Public logger API - see https://github.com/pimterry/loglevel for details
  150. *
  151. */
  152. self.name = name;
  153. self.levels = { "TRACE": 0, "DEBUG": 1, "INFO": 2, "WARN": 3,
  154. "ERROR": 4, "SILENT": 5};
  155. self.methodFactory = factory || defaultMethodFactory;
  156. self.getLevel = function () {
  157. return currentLevel;
  158. };
  159. self.setLevel = function (level, persist) {
  160. if (typeof level === "string" && self.levels[level.toUpperCase()] !== undefined) {
  161. level = self.levels[level.toUpperCase()];
  162. }
  163. if (typeof level === "number" && level >= 0 && level <= self.levels.SILENT) {
  164. currentLevel = level;
  165. if (persist !== false) { // defaults to true
  166. persistLevelIfPossible(level);
  167. }
  168. replaceLoggingMethods.call(self, level, name);
  169. if (typeof console === undefinedType && level < self.levels.SILENT) {
  170. return "No console available for logging";
  171. }
  172. } else {
  173. throw "log.setLevel() called with invalid level: " + level;
  174. }
  175. };
  176. self.setDefaultLevel = function (level) {
  177. if (!getPersistedLevel()) {
  178. self.setLevel(level, false);
  179. }
  180. };
  181. self.enableAll = function(persist) {
  182. self.setLevel(self.levels.TRACE, persist);
  183. };
  184. self.disableAll = function(persist) {
  185. self.setLevel(self.levels.SILENT, persist);
  186. };
  187. // Initialize with the right level
  188. var initialLevel = getPersistedLevel();
  189. if (initialLevel == null) {
  190. initialLevel = defaultLevel == null ? "WARN" : defaultLevel;
  191. }
  192. self.setLevel(initialLevel, false);
  193. }
  194. /*
  195. *
  196. * Top-level API
  197. *
  198. */
  199. var defaultLogger = new Logger();
  200. var _loggersByName = {};
  201. defaultLogger.getLogger = function getLogger(name) {
  202. if ((typeof name !== "symbol" && typeof name !== "string") || name === "") {
  203. throw new TypeError("You must supply a name when creating a logger.");
  204. }
  205. var logger = _loggersByName[name];
  206. if (!logger) {
  207. logger = _loggersByName[name] = new Logger(
  208. name, defaultLogger.getLevel(), defaultLogger.methodFactory);
  209. }
  210. return logger;
  211. };
  212. // Grab the current global log variable in case of overwrite
  213. var _log = (typeof window !== undefinedType) ? window.log : undefined;
  214. defaultLogger.noConflict = function() {
  215. if (typeof window !== undefinedType &&
  216. window.log === defaultLogger) {
  217. window.log = _log;
  218. }
  219. return defaultLogger;
  220. };
  221. defaultLogger.getLoggers = function getLoggers() {
  222. return _loggersByName;
  223. };
  224. // ES6 default export, for compatibility
  225. defaultLogger['default'] = defaultLogger;
  226. return defaultLogger;
  227. }));