// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
import { NoTarget } from "@typespec/compiler";
import { getTracer, reportDiagnostic } from "./lib.js";
import { LoggerLevel } from "./log-level.js";
/**
 * The Logger class for the emitter.
 * @beta
 */
export class Logger {
    static instance;
    initialized = false;
    tracer;
    level;
    program;
    constructor(program, level) {
        this.tracer = getTracer(program);
        this.level = level;
        this.program = program;
    }
    static initialize(program, level) {
        if (!Logger.instance) {
            Logger.instance = new Logger(program, level);
            Logger.instance.initialized = true;
        }
    }
    static getInstance() {
        if (!Logger.instance) {
            throw new Error("Logger is not initialized. Call initialize() first.");
        }
        return Logger.instance;
    }
    info(message) {
        if (!this.initialized) {
            throw new Error("Logger is not initialized. Call initialize() first.");
        }
        if (this.level === LoggerLevel.INFO ||
            this.level === LoggerLevel.DEBUG ||
            this.level === LoggerLevel.VERBOSE) {
            this.tracer.trace(LoggerLevel.INFO, message);
        }
    }
    debug(message) {
        if (!this.initialized) {
            throw new Error("Logger is not initialized. Call initialize() first.");
        }
        if (this.level === LoggerLevel.DEBUG || this.level === LoggerLevel.VERBOSE) {
            this.tracer.trace(LoggerLevel.DEBUG, message);
        }
    }
    verbose(message) {
        if (!this.initialized) {
            throw new Error("Logger is not initialized. Call initialize() first.");
        }
        if (this.level === LoggerLevel.VERBOSE) {
            this.tracer.trace(LoggerLevel.VERBOSE, message);
        }
    }
    warn(message) {
        reportDiagnostic(this.program, {
            code: "general-warning",
            format: { message: message },
            target: NoTarget,
        });
    }
    error(message) {
        reportDiagnostic(this.program, {
            code: "general-error",
            format: { message: message },
            target: NoTarget,
        });
    }
}
//# sourceMappingURL=logger.js.map