All files auditing.js

94.59% Statements 35/37
83.33% Branches 5/6
100% Functions 3/3
94.59% Lines 35/37

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 451x 1x   1x   1x       1x 1x 1x 1x 1x 4x 4x 4x   1x 1x 1x 1x 6x 6x 5x 6x 1x 1x 6x   1x 1x 1x 1x 1x 1x 1x 1x 1x 5x 5x 5x      
import pino from 'pino'
import { auditLoggerConfig } from './audit-logger-config.js'
 
let auditLogger = pino(auditLoggerConfig)
 
if (process.env.CDP_AUDIT_ENABLED === 'false') {
  enableAuditing(false)
}
 
/**
 * Replaces the current audit logger.
 *
 * @param {Logger} logger
 */
function setAuditLogger(logger) {
  auditLogger = logger
}
 
/**
 * Globally enables or disables auditing
 * @param {boolean|null} isEnabled
 */
function enableAuditing(isEnabled = true) {
  if (isEnabled) {
    auditLogger.level = 'audit'
  } else {
    auditLogger.level = 'silent'
  }
}
 
/**
 * Writes an audit message to stdout with a `log.level` of `audit`.
 * API is exactly the same as pino's logger api.
 *
 * @param { ...Object|String|Error } args - Either:
 *   - one String
 *   - one Object or Error
 *   - one Object or Error and one String
 */
function audit(...args) {
  auditLogger.audit.apply(auditLogger, args)
}
 
export { audit, enableAuditing, setAuditLogger }