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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. "use strict";
  2. var __importDefault = (this && this.__importDefault) || function (mod) {
  3. return (mod && mod.__esModule) ? mod : { "default": mod };
  4. };
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. const fs_1 = __importDefault(require("fs"));
  7. const loglevel_1 = __importDefault(require("loglevel"));
  8. const util_1 = __importDefault(require("util"));
  9. const chalk_1 = __importDefault(require("chalk"));
  10. const loglevel_plugin_prefix_1 = __importDefault(require("loglevel-plugin-prefix"));
  11. const strip_ansi_1 = __importDefault(require("strip-ansi"));
  12. loglevel_plugin_prefix_1.default.reg(loglevel_1.default);
  13. const DEFAULT_LEVEL = 'trace';
  14. const COLORS = {
  15. error: 'red',
  16. warn: 'yellow',
  17. info: 'cyanBright',
  18. debug: 'green',
  19. trace: 'cyan'
  20. };
  21. const matches = {
  22. COMMAND: 'COMMAND',
  23. DATA: 'DATA',
  24. RESULT: 'RESULT'
  25. };
  26. const SERIALIZERS = [{
  27. matches: (err) => err instanceof Error,
  28. serialize: (err) => err.stack
  29. }, {
  30. matches: (log) => log === matches.COMMAND,
  31. serialize: (log) => chalk_1.default.magenta(log)
  32. }, {
  33. matches: (log) => log === matches.DATA,
  34. serialize: (log) => chalk_1.default.yellow(log)
  35. }, {
  36. matches: (log) => log === matches.RESULT,
  37. serialize: (log) => chalk_1.default.cyan(log)
  38. }];
  39. const loggers = loglevel_1.default.getLoggers();
  40. let logLevelsConfig = {};
  41. const logCache = new Set();
  42. let logFile;
  43. const originalFactory = loglevel_1.default.methodFactory;
  44. const wdioLoggerMethodFactory = function (methodName, logLevel, loggerName) {
  45. const rawMethod = originalFactory(methodName, logLevel, loggerName);
  46. return (...args) => {
  47. if (!logFile && process.env.WDIO_LOG_PATH) {
  48. logFile = fs_1.default.createWriteStream(process.env.WDIO_LOG_PATH);
  49. }
  50. const match = Object.values(matches).filter(x => args[0].endsWith(`: ${x}`))[0];
  51. if (match) {
  52. const prefixStr = args.shift().slice(0, -match.length - 1);
  53. args.unshift(prefixStr, match);
  54. }
  55. args = args.map((arg) => {
  56. for (const s of SERIALIZERS) {
  57. if (s.matches(arg)) {
  58. return s.serialize(arg);
  59. }
  60. }
  61. return arg;
  62. });
  63. const logText = strip_ansi_1.default(`${util_1.default.format.apply(this, args)}\n`);
  64. if (logFile && logFile.writable) {
  65. if (logCache.size) {
  66. logCache.forEach((log) => {
  67. if (logFile) {
  68. logFile.write(log);
  69. }
  70. });
  71. logCache.clear();
  72. }
  73. return logFile.write(logText);
  74. }
  75. logCache.add(logText);
  76. rawMethod(...args);
  77. };
  78. };
  79. function getLogger(name) {
  80. if (loggers[name]) {
  81. return loggers[name];
  82. }
  83. let logLevel = (process.env.WDIO_LOG_LEVEL || DEFAULT_LEVEL);
  84. const logLevelName = getLogLevelName(name);
  85. if (logLevelsConfig[logLevelName]) {
  86. logLevel = logLevelsConfig[logLevelName];
  87. }
  88. loggers[name] = loglevel_1.default.getLogger(name);
  89. loggers[name].setLevel(logLevel);
  90. loggers[name].methodFactory = wdioLoggerMethodFactory;
  91. loglevel_plugin_prefix_1.default.apply(loggers[name], {
  92. template: '%t %l %n:',
  93. timestampFormatter: (date) => chalk_1.default.gray(date.toISOString()),
  94. levelFormatter: (level) => chalk_1.default[COLORS[level]](level.toUpperCase()),
  95. nameFormatter: (name) => chalk_1.default.whiteBright(name)
  96. });
  97. return loggers[name];
  98. }
  99. exports.default = getLogger;
  100. getLogger.waitForBuffer = async () => new Promise(resolve => {
  101. if (logFile && Array.isArray(logFile.writableBuffer) && logFile.writableBuffer.length !== 0) {
  102. return setTimeout(async () => {
  103. await getLogger.waitForBuffer();
  104. resolve();
  105. }, 20);
  106. }
  107. resolve();
  108. });
  109. getLogger.setLevel = (name, level) => loggers[name].setLevel(level);
  110. getLogger.clearLogger = () => {
  111. if (logFile) {
  112. logFile.end();
  113. }
  114. logFile = null;
  115. };
  116. getLogger.setLogLevelsConfig = (logLevels = {}, wdioLogLevel = DEFAULT_LEVEL) => {
  117. if (process.env.WDIO_LOG_LEVEL === undefined) {
  118. process.env.WDIO_LOG_LEVEL = wdioLogLevel;
  119. }
  120. logLevelsConfig = {};
  121. Object.entries(logLevels).forEach(([logName, logLevel]) => {
  122. const logLevelName = getLogLevelName(logName);
  123. logLevelsConfig[logLevelName] = logLevel;
  124. });
  125. Object.keys(loggers).forEach(logName => {
  126. const logLevelName = getLogLevelName(logName);
  127. const logLevel = typeof logLevelsConfig[logLevelName] !== 'undefined' ? logLevelsConfig[logLevelName] : process.env.WDIO_LOG_LEVEL;
  128. loggers[logName].setLevel(logLevel);
  129. });
  130. };
  131. const getLogLevelName = (logName) => logName.split(':').shift();