@nestjs-labs/nestjs-pino-extra
Version:
Enhanced nestjs-pino with OpenTelemetry, Loki, file rotation and enterprise features
53 lines • 1.92 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.extractLogConfig = extractLogConfig;
exports.getPinoHttpFromConfig = getPinoHttpFromConfig;
exports.getParamsFromConfig = getParamsFromConfig;
exports.getNestjsPinoModuleOptions = getNestjsPinoModuleOptions;
const pino_http_extra_1 = require("@nestjs-labs/pino-http-extra");
function extractLogConfig(configService) {
const app = configService.get('OTLP_SERVICE_NAME') ?? 'app';
const level = configService.get('LOG_LEVEL') ?? 'info';
const filename = configService.get('LOG_FILE');
const loki = configService.get('LOG_LOKI');
const spanIdKey = configService.get('OTEL_SPAN_ID_KEY') ?? 'spanId';
const traceIdKey = configService.get('OTEL_TRACE_ID_KEY') ?? 'traceId';
const validLevels = [
'fatal',
'error',
'warn',
'info',
'debug',
'trace',
];
if (!validLevels.includes(level)) {
throw new Error(`Invalid LOG_LEVEL: ${level}. Must be one of: ${validLevels.join(', ')}`);
}
return {
app,
filename,
level,
loki,
spanIdKey,
traceIdKey,
};
}
function getPinoHttpFromConfig(config) {
return [
(0, pino_http_extra_1.getPinoHttpOption)(config.level, config.spanIdKey, config.traceIdKey),
(0, pino_http_extra_1.getMultiDestinationStream)(config.app, config.level, config.filename, config.loki),
];
}
function getParamsFromConfig(config, overrides) {
const pinoHttp = getPinoHttpFromConfig(config);
const params = {
pinoHttp,
exclude: [{ method: 0, path: '/health' }],
};
return Object.assign(params, overrides);
}
function getNestjsPinoModuleOptions(configService, overrides = {}) {
const config = extractLogConfig(configService);
return getParamsFromConfig(config, overrides);
}
//# sourceMappingURL=module-option.js.map