All files / src/utils loggerInstance.js

100% Statements 20/20
100% Branches 8/8
75% Functions 6/8
100% Lines 19/19

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53                20x 2x 2x 2x     18x 18x     111x 111x 2x 2x       18x   100x 97x 97x     14x 14x     8x     4x                 1x        
/**
 * Logger singleton.
 *
 * In production, logs are written to Firestore via createLogger().
 * In non-production (dev/test), logs go to console only — no Firestore
 * writes — saving thousands of write ops per day on the free tier.
 */
 
if (process.env.NODE_ENV === 'production') {
  const { db } = require('./firebase');
  const { createLogger } = require('./logger');
  module.exports = createLogger(db);
} else {
  // Console-only logger with the same interface — zero Firestore writes
  let dailyCount = 0;
  let currentDay = new Date().toISOString().split('T')[0];
 
  function resetIfNewDay() {
    const today = new Date().toISOString().split('T')[0];
    if (today !== currentDay) {
      dailyCount = 0;
      currentDay = today;
    }
  }
 
  module.exports = {
    async log(entry) {
      if (!entry || typeof entry !== 'object') return;
      resetIfNewDay();
      dailyCount++;
    },
    getDailyStats() {
      resetIfNewDay();
      return { count: dailyCount, hardCap: Infinity };
    },
    _resetDailyCount() {
      dailyCount = 0;
    },
    _setDailyCount(n) {
      dailyCount = n;
    },
    _setHardCap() {
      /* no-op on dev */
    },
    _resetCircuitBreaker() {
      /* no-op on dev */
    },
    _getConsecutiveFailures() {
      return 0;
    },
  };
}