WhatsApp-Logger-Self-Hosted-

A privacy-focused, self-hosted...
Log | Files | Refs | Activity | README | LICENSE

root / src / logger.js

logger.js (708B)


      1 const { MAX_LOGS } = require('./config');
      2 
      3 // --- IN-MEMORY LOGGING BUFFER ---
      4 const logBuffer = [];
      5 
      6 const originalLog = console.log;
      7 const originalError = console.error;
      8 
      9 function teeLog(level, originalFn, ...args) {
     10     const message = args.map(arg =>
     11         typeof arg === 'object' ? JSON.stringify(arg) : String(arg)
     12     ).join(' ');
     13 
     14     logBuffer.push({ timestamp: Date.now(), level, message });
     15     if (logBuffer.length > MAX_LOGS) logBuffer.shift();
     16 
     17     originalFn.apply(console, args);
     18 }
     19 
     20 function install() {
     21     console.log = (...args) => teeLog('log', originalLog, ...args);
     22     console.error = (...args) => teeLog('error', originalError, ...args);
     23 }
     24 
     25 module.exports = { install, logBuffer };
© notamitgamer • Site Built: 2026-09-05 01:53:16 UTC • git-mirror commit: c170d72 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror