UNPKG

@wgtechlabs/log-engine

Version:

A lightweight, security-first logging utility with automatic data redaction for Node.js applications - the first logging library with built-in PII protection.

62 lines 2.24 kB
"use strict"; /** * Environment detection utilities for logging configuration * Handles automatic environment-based configuration */ Object.defineProperty(exports, "__esModule", { value: true }); exports.EnvironmentDetector = void 0; const types_1 = require("../types/index.cjs"); /** * Environment detection and configuration utilities */ class EnvironmentDetector { /** * Get the normalized NODE_ENV value * @returns Normalized NODE_ENV (trimmed and lowercase) */ static getNormalizedNodeEnv() { return (process.env.NODE_ENV || '').trim().toLowerCase(); } /** * Determines the appropriate log mode based on NODE_ENV * @returns LogMode appropriate for current environment */ static getEnvironmentMode() { const nodeEnv = EnvironmentDetector.getNormalizedNodeEnv(); switch (nodeEnv) { case 'development': return types_1.LogMode.DEBUG; // Verbose logging for development case 'production': return types_1.LogMode.INFO; // Important info and above for production case 'staging': return types_1.LogMode.WARN; // Focused logging for staging case 'test': return types_1.LogMode.ERROR; // Minimal logging during tests default: return types_1.LogMode.INFO; // Default fallback for unknown environments } } /** * Check if we're in a test environment * @returns true if NODE_ENV is 'test' */ static isTestEnvironment() { return EnvironmentDetector.getNormalizedNodeEnv() === 'test'; } /** * Check if we're in a development environment * @returns true if NODE_ENV is 'development' */ static isDevelopmentEnvironment() { return EnvironmentDetector.getNormalizedNodeEnv() === 'development'; } /** * Check if we're in a production environment * @returns true if NODE_ENV is 'production' */ static isProductionEnvironment() { return EnvironmentDetector.getNormalizedNodeEnv() === 'production'; } } exports.EnvironmentDetector = EnvironmentDetector; //# sourceMappingURL=environment.js.map