файл пакета→ .shtukbase/packages/std-twelve-factor/checks/tf03_logs.ts
checks/tf03_logs.ts
27 строк, 1.8 КБ.
Файл как есть в пакете: код и комментарии в нём не переводятся.
- // TF-R03 (XI Logs, observe): the app writes its log as an event stream to stdout; it does not route or store log
- // files itself. A heuristic over code files: file log handlers, appenders and writes to *.log.
- import { codeFiles, COMMENT, PKG } from './tflib.ts';
- import { finish, norm, readTextFile } from './lib/std.ts';
- const n = norm(PKG, 'TF-R03', 'observe');
- const out: string[] = [];
- const PATTERNS: { what: string; re: RegExp }[] = [
- { what: 'a log handler writing to a file (Python logging)', re: /\b(?:logging\.)?(?:FileHandler|RotatingFileHandler|TimedRotatingFileHandler|WatchedFileHandler)\s*\(|basicConfig\([^)]*filename\s*=/ },
- { 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)["'`]/ },
- { 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/ },
- { 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/ },
- ];
- if (n.active)
- for (const f of codeFiles()) {
- const text = readTextFile(f);
- if (text === null) continue;
- text.split('\n').forEach((l, i) => {
- if (l.length > 2000 || COMMENT.test(l) || /12factor:allow/.test(l)) return;
- for (const p of PATTERNS)
- if (p.re.test(l)) {
- out.push(`${f}:${i + 1}: ${p.what} → write the log to stdout as an event stream, and leave storage and rotation to the environment`);
- break;
- }
- });
- }
- finish(n, out);