// SPDX-License-Identifier: Apache-2.0
// Copyright 2024-2026 Vorion LLC
/**
 * Logging configuration for Vorion
 *
 * Uses pino for structured logging with W3C TraceContext support.
 */
import pino from 'pino';
import { getTraceLogContext } from './trace.js';
const level = process.env['VORION_LOG_LEVEL'] ?? 'info';
/**
 * Custom log method that automatically includes trace context
 */
function createTracingMixin() {
    return () => {
        const traceContext = getTraceLogContext();
        if (traceContext) {
            return traceContext;
        }
        return {};
    };
}
const pinoOptions = {
    level,
    base: {
        service: 'vorion',
        version: process.env['npm_package_version'],
    },
    mixin: createTracingMixin(),
    // Redact sensitive fields
    redact: {
        paths: [
            'password',
            'secret',
            'apiKey',
            'token',
            'authorization',
            'context.password',
            'context.apiKey',
            'context.secret',
            'metadata.password',
            'metadata.apiKey',
            'metadata.secret',
        ],
        censor: '[REDACTED]',
    },
};
// Add pretty printing in development
if (process.env['NODE_ENV'] !== 'production') {
    pinoOptions.transport = {
        target: 'pino-pretty',
        options: {
            colorize: true,
            translateTime: 'SYS:standard',
            ignore: 'pid,hostname',
        },
    };
}
export const logger = pino(pinoOptions);
/**
 * Create a child logger with context
 * Trace context is automatically included via mixin
 */
export function createLogger(context) {
    return logger.child(context);
}
/**
 * Create a child logger with explicit trace context override
 * Use this when trace context needs to be manually specified
 * (e.g., when processing jobs from a queue)
 */
export function createTracedLogger(context, traceId, spanId) {
    const traceContext = {};
    if (traceId) {
        traceContext.traceId = traceId;
    }
    if (spanId) {
        traceContext.spanId = spanId;
    }
    return logger.child({ ...context, ...traceContext });
}
//# sourceMappingURL=logger.js.map