ShtukbaseStandard
archivo del paquete→ .shtukbase/packages/std-twelve-factor/checks/tf03_logs.ts

checks/tf03_logs.ts

27 líneas, 1.8 KB.

El archivo tal como está en el paquete: el código y sus comentarios no se traducen.

  1. // TF-R03 (XI Logs, observe): the app writes its log as an event stream to stdout; it does not route or store log
  2. // files itself. A heuristic over code files: file log handlers, appenders and writes to *.log.
  3. import { codeFiles, COMMENT, PKG } from './tflib.ts';
  4. import { finish, norm, readTextFile } from './lib/std.ts';
  5. const n = norm(PKG, 'TF-R03', 'observe');
  6. const out: string[] = [];
  7. const PATTERNS: { what: string; re: RegExp }[] = [
  8. { what: 'a log handler writing to a file (Python logging)', re: /\b(?:logging\.)?(?:FileHandler|RotatingFileHandler|TimedRotatingFileHandler|WatchedFileHandler)\s*\(|basicConfig\([^)]*filename\s*=/ },
  9. { what: 'a log transport to a file (winston, pino, bunyan, log4js)', re: /transports\.File\s*\(|pino\.destination\(\s*["'`][^"'`]+\.log|type\s*:\s*["'`](?:file|dateFile|rotating-file)["'`]/ },
  10. { what: 'a file appender for logs (tracing, log4rs, flexi_logger, logrus, zap)', re: /tracing_appender::[r]olling|rolling::(?:daily|hourly|never|minutely)\s*\(|FileAppender::[b]uilder|Logger::try_with_\w*\(\)[\s\S]{0,40}log_to_file|lumberjack\.Logger/ },
  11. { what: 'appending to a *.log file', re: /\bopen\([^)]*\.log["'`][^)]*,\s*["'`]a\+?b?["'`]|appendFileSync\([^,]*\.log["'`]|createWriteStream\([^)]*\.log["'`][^)]*flags\s*:\s*["'`]a|OpenOptions::new\(\)\.append\(true\)[^;]*\.log/ },
  12. ];
  13. if (n.active)
  14. for (const f of codeFiles()) {
  15. const text = readTextFile(f);
  16. if (text === null) continue;
  17. text.split('\n').forEach((l, i) => {
  18. if (l.length > 2000 || COMMENT.test(l) || /12factor:allow/.test(l)) return;
  19. for (const p of PATTERNS)
  20. if (p.re.test(l)) {
  21. out.push(`${f}:${i + 1}: ${p.what} → write the log to stdout as an event stream, and leave storage and rotation to the environment`);
  22. break;
  23. }
  24. });
  25. }
  26. finish(n, out);