"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
    return function (target, key) { decorator(target, key, paramIndex); }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.WinstonTypeORMLogger = exports.WinstonLoggerConfig = exports.createWinstonLoggerConfig = void 0;
const winston_1 = require("winston");
const common_1 = require("@nestjs/common");
const nest_winston_1 = require("nest-winston");
const winston = __importStar(require("winston"));
const disallow_in_production_decorator_1 = require("./decorators/disallow-in-production.decorator");
const createWinstonLoggerConfig = () => ({
    level: process.env.LOG_LEVEL || (process.env.ENV === disallow_in_production_decorator_1.Environment.Production ? 'warn' : 'info'),
    format: winston.format.combine(winston.format.timestamp(), winston.format.errors({ stack: true }), winston.format.printf(({ level, message, timestamp }) => {
        if (!message) {
            return `[${timestamp}] ${level.toUpperCase()}: (No message provided)`;
        }
        return `[${timestamp}] ${level.toUpperCase()}: ${message}`;
    })),
    transports: [
        new winston.transports.Console({
            format: winston.format.combine(winston.format.printf(({ level, message, timestamp }) => {
                return `[${timestamp}] ${level.toUpperCase()}: ${message}`;
            })),
        }),
        new winston.transports.File({
            filename: 'logs/application.log',
        }),
        new winston.transports.File({
            filename: 'logs/error.log',
            level: 'error',
        }),
    ],
});
exports.createWinstonLoggerConfig = createWinstonLoggerConfig;
exports.WinstonLoggerConfig = (0, exports.createWinstonLoggerConfig)();
let WinstonTypeORMLogger = class WinstonTypeORMLogger {
    constructor(logger) {
        this.logger = logger;
    }
    logQuery(query, parameters, queryRunner) {
        if (Boolean(process.env.DEFAULT_DATABASE_LOGGING)) {
            this.logger.info(`Query: ${query} Parameters: ${parameters}`);
        }
    }
    logQueryError(error, query, parameters, queryRunner) {
        this.logger.error(`Query failed: ${error} | Query: ${query} | Parameters: ${parameters}`);
    }
    logQuerySlow(time, query, parameters, queryRunner) {
        this.logger.warn(`Slow query: ${time}ms | Query: ${query} | Parameters: ${parameters}`);
    }
    logSchemaBuild(message, queryRunner) {
        this.logger.info(`Schema Build: ${message}`);
    }
    logMigration(message, queryRunner) {
        this.logger.info(`Migration: ${message}`);
    }
    log(level, message) {
        this.logger[level](message);
    }
};
exports.WinstonTypeORMLogger = WinstonTypeORMLogger;
exports.WinstonTypeORMLogger = WinstonTypeORMLogger = __decorate([
    __param(0, (0, common_1.Inject)(nest_winston_1.WINSTON_MODULE_PROVIDER)),
    __metadata("design:paramtypes", [winston_1.Logger])
], WinstonTypeORMLogger);
//# sourceMappingURL=winston.logger.js.map