"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Logger = void 0;
class Logger {
    native;
    errorSerializer;
    constructor(native, errorSerializer) {
        this.native = native;
        this.errorSerializer = errorSerializer;
    }
    log(level, message) {
        this.native.log(level, message);
    }
    debug(message) {
        this.log('debug', message);
    }
    info(message) {
        this.log('info', message);
    }
    error(message, scope) {
        scope = scope ? scope + ' - ' : '';
        if (message instanceof Error) {
            const res = this.errorSerializer ? this.errorSerializer(message) : message;
            this.log('error', scope + (typeof res === 'string' ? res : String(res.stack)));
            return;
        }
        this.log('error', scope + message);
    }
    wrap(method, onError = () => { }) {
        try {
            return method();
        }
        catch (error) {
            this.error(error);
            if (onError) {
                onError(error);
            }
        }
    }
    wrapEventEmitter(emitter) {
        emitter.on('error', this.error.bind(this));
    }
}
exports.Logger = Logger;
