UNPKG

strogger

Version:

📊 A modern structured logging library with functional programming, duck-typing, and comprehensive third-party integrations

39 lines • 1.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getEnvironment = void 0; const zod_1 = require("zod"); const LoggerEnvironmentSchema = zod_1.z.object({ LOG_LEVEL: zod_1.z.enum(["DEBUG", "INFO", "WARN", "ERROR", "FATAL"]).optional(), STAGE: zod_1.z.enum(["dev", "prod", "test"]).default("dev"), SERVICE_NAME: zod_1.z.string().optional(), ENABLE_STRUCTURED_LOGGING: zod_1.z .string() .transform((val) => val === "true") .optional(), CLOUDWATCH_LOG_GROUP: zod_1.z.string().optional(), CLOUDWATCH_LOG_STREAM: zod_1.z.string().optional(), AWS_REGION: zod_1.z.string().optional(), }); const getEnvironment = (env = process.env) => { let config; try { config = LoggerEnvironmentSchema.parse(env); } catch (error) { if (error instanceof zod_1.z.ZodError) { console.warn("Environment validation failed, using defaults:", error.errors); } config = { STAGE: "dev" }; } return { ...config, isProduction: config.STAGE === "prod", isDevelopment: config.STAGE === "dev", logLevel: config.LOG_LEVEL ?? undefined, serviceName: config.SERVICE_NAME ?? undefined, enableStructuredLogging: config.ENABLE_STRUCTURED_LOGGING ?? true, stage: config.STAGE, }; }; exports.getEnvironment = getEnvironment; //# sourceMappingURL=environment.js.map