"use strict";
/*
 * @adonisjs/logger
 *
 * (c) Harminder Virk <virk@adonisjs.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Logger = void 0;
/// <reference path="../adonis-typings/logger.ts" />
const pino_1 = __importDefault(require("pino"));
const abstract_logging_1 = __importDefault(require("abstract-logging"));
const getPino_1 = require("./getPino");
const STATIC_LEVELS = {
    labels: {
        10: 'trace',
        20: 'debug',
        30: 'info',
        40: 'warn',
        50: 'error',
        60: 'fatal',
    },
    values: {
        fatal: 60,
        error: 50,
        warn: 40,
        info: 30,
        debug: 20,
        trace: 10,
    },
};
/**
 * Logger class built on top of pino with couple of changes in
 * the configuration. You can access the underlying `pino`
 * object using `logger.pino`.
 */
class Logger {
    constructor(config, pino) {
        this.config = config;
        if (!this.config.enabled) {
            this.pino = abstract_logging_1.default;
        }
        else {
            this.pino = pino || (0, getPino_1.getPino)(this.config);
        }
    }
    /**
     * A map of levels
     */
    get levels() {
        if (!this.config.enabled) {
            return STATIC_LEVELS;
        }
        return this.pino.levels;
    }
    /**
     * Returns the current logger level
     */
    get level() {
        if (!this.config.enabled) {
            return this.config.level;
        }
        return this.pino.level;
    }
    /**
     * Update logger level
     */
    set level(level) {
        if (!this.config.enabled) {
            this.config.level = level;
            return;
        }
        this.pino.level = level;
    }
    /**
     * Returns the current logger level number
     */
    get levelNumber() {
        if (!this.config.enabled) {
            return STATIC_LEVELS.values[this.config.level];
        }
        return this.pino.levelVal;
    }
    /**
     * Returns the pino version
     */
    get pinoVersion() {
        return pino_1.default.version;
    }
    /**
     * Returns a boolean telling if level is enabled or
     * not.
     */
    isLevelEnabled(level) {
        if (!this.config.enabled) {
            return false;
        }
        return this.pino.isLevelEnabled(level);
    }
    log(level, mergingObject, message, ...values) {
        if (values.length) {
            this.pino[level](mergingObject, message, ...values);
        }
        else if (message) {
            this.pino[level](mergingObject, message);
        }
        else {
            this.pino[level](mergingObject);
        }
    }
    trace(mergingObject, message, ...values) {
        this.log('trace', mergingObject, message, ...values);
    }
    debug(mergingObject, message, ...values) {
        this.log('debug', mergingObject, message, ...values);
    }
    info(mergingObject, message, ...values) {
        this.log('info', mergingObject, message, ...values);
    }
    warn(mergingObject, message, ...values) {
        this.log('warn', mergingObject, message, ...values);
    }
    error(mergingObject, message, ...values) {
        this.log('error', mergingObject, message, ...values);
    }
    fatal(mergingObject, message, ...values) {
        this.log('fatal', mergingObject, message, ...values);
    }
    /**
     * Returns a child logger instance
     */
    child(bindings, options) {
        if (!this.config.enabled) {
            return this;
        }
        return new Logger(this.config, this.pino.child(bindings, options));
    }
    /**
     * Returns default bindings for the logger
     */
    bindings() {
        if (!this.config.enabled) {
            return {};
        }
        return this.pino.bindings();
    }
}
exports.Logger = Logger;
