import { SafeEventEmitter } from "./utils/event-emitter.js";
export class Logger2 {
    #emitter = new SafeEventEmitter();
    log(msg, ...data) {
        const obj = Object.assign({}, ...data);
        const logData = Object.assign(obj, { msg });
        this.#emitter.emit('log', logData);
    }
    warn(msg, ...data) {
        const obj = Object.assign({}, ...data);
        const warnData = Object.assign(obj, { msg });
        this.#emitter.emit('warn', warnData);
    }
    error(err, ...data) {
        const error = typeof err === 'string' ? Error(err) : err;
        const obj = Object.assign({}, ...data);
        const errorData = Object.assign(obj, { error });
        this.#emitter.emit('error', errorData);
    }
    action(data) {
        this.#emitter.emit('action', data);
    }
    metrics(data) {
        this.#emitter.emit('metrics', data);
    }
    event(data) {
        this.#emitter.emit('event', data);
    }
    nested(params) {
        const self = this;
        const paramsKey = Symbol();
        const logger = {
            [paramsKey]: params,
            log(msg, ...data) {
                if (self.#emitter.countOf('log'))
                    self.log(msg, this[paramsKey], ...data);
            },
            warn(msg, ...data) {
                if (self.#emitter.countOf('warn'))
                    self.warn(msg, this[paramsKey], ...data);
            },
            error(err, ...data) {
                if (self.#emitter.countOf('error'))
                    self.error(err, this[paramsKey], ...data);
            },
            action(data) {
                if (self.#emitter.countOf('action'))
                    self.action({ ...this[paramsKey], ...data });
            },
            metrics(data) {
                if (self.#emitter.countOf('metrics'))
                    self.metrics({ ...this[paramsKey], ...data });
            },
            event(data) {
                if (self.#emitter.countOf('event'))
                    self.event({ ...this[paramsKey], ...data });
            },
            nested(nestedParams) {
                return {
                    ...this,
                    [paramsKey]: {
                        ...this[paramsKey],
                        ...nestedParams,
                    },
                };
            },
            on: self.on.bind(self),
            off: self.off.bind(self),
        };
        return logger;
    }
    on(type, listener) {
        this.#emitter.on(type, listener);
    }
    off(type, listener) {
        this.#emitter.off(type, listener);
    }
}
// MAJOR: remove old logger implementation
const noop = () => { };
/** @deprecated */
class Logger {
    #logger = this.createLogger({});
    get log() {
        return this.#logger.log;
    }
    get info() {
        return this.#logger.info;
    }
    get error() {
        return this.#logger.error;
    }
    get warn() {
        return this.#logger.warn;
    }
    get metrics() {
        return this.#logger.metrics;
    }
    get action() {
        return this.#logger.action;
    }
    setLogger(settings = {}) {
        this.#logger = this.createLogger(settings);
    }
    /**
     * @inner
     *
     * To override the default logger, use setLogger
     */
    createLogger(settings) {
        return {
            log: settings.log ?? noop,
            info: settings.info ?? noop,
            warn: settings.warn ?? noop,
            error: settings.error ?? noop,
            metrics: settings.metrics ?? noop,
            action: settings.action ?? noop,
        };
    }
}
/** @deprecated */
export const logger = new Logger();
/**
 * Alias for global singleton logger instance
 *
 * @deprecated
 */
export const globalLogger = logger;
//# sourceMappingURL=logger.js.map
