Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | INFRASTRUCTURE & AUTOMATION4 * ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project : MacLustr Vision8 * File : server/src/log.ts9 * Module : server10 * Repository : https://git.spboucher.ai/maclustr-vision11 * Project Website : https://camera.spboucher.ai12 * Created : 2026-11-3013 * Last Modified : 2026-11-3014 *15 * Author : Simon-Pierre Boucher16 * Position : Professor of Finance17 * Institution : Université du Québec en Outaouais (UQO)18 * Organization : SP Boucher19 * Website : https://spboucher.ai20 * Git : https://git.spboucher.ai21 *22 * Preferred Contact: admin@spboucher.ai23 * Technical Contact: dev@spboucher.ai24 * Security/Admin : admin@spboucher.ai25 *26 * Copyright (c) 202627 * Simon-Pierre Boucher28 * All rights reserved where applicable. This file is governed by the29 * applicable project license, copyright notices and relevant law.30 * Existing third-party rights and notices remain unaffected.31 *32 * License : None specified (no license file in this repository)33 *34 * Do not embed credentials, private keys, access tokens,35 * certificates or confidential personal information.36 *37 * =============================================================================38 * END OF SP BOUCHER SOURCE HEADER39 * =============================================================================40 */4142// Journal JSON-lignes sur stdout, avec caviardage des secrets (mots de passe caméra, URL RTSP).43const LEVELS = { debug: 10, info: 20, warn: 30, error: 40 } as const;44type Level = keyof typeof LEVELS;45const threshold = LEVELS[(process.env.MLV_LOG_LEVEL as Level) || 'info'] ?? 20;46const secrets = new Set<string>();4748export function registerSecret(s: string | undefined | null): void {49 if (!s || s.length < 4) return;50 secrets.add(s);51 secrets.add(encodeURIComponent(s));52}5354export function redact(text: string): string {55 let out = text;56 for (const s of secrets) if (out.includes(s)) out = out.split(s).join('***');57 // toute URL avec identifiants : on masque la partie utilisateur:motdepasse58 out = out.replace(/([a-z][a-z0-9+.-]*:\/\/)[^\s/@:]+:[^\s/@]+@/gi, '$1***@');59 return out;60}6162function emit(level: Level, scope: string, msg: string, extra?: Record<string, unknown>): void {63 if (LEVELS[level] < threshold) return;64 const line = JSON.stringify({ t: new Date().toISOString(), level, scope, msg, ...(extra || {}) });65 process.stdout.write(redact(line) + '\n');66}6768export function logger(scope: string) {69 return {70 debug: (m: string, e?: Record<string, unknown>) => emit('debug', scope, m, e),71 info: (m: string, e?: Record<string, unknown>) => emit('info', scope, m, e),72 warn: (m: string, e?: Record<string, unknown>) => emit('warn', scope, m, e),73 error: (m: string, e?: Record<string, unknown>) => emit('error', scope, m, e),74 };75}76export type Logger = ReturnType<typeof logger>;77