UNPKG

@freemework/common

Version:

Common library of the Freemework Project.

87 lines (86 loc) 5.08 kB
import { FException } from "../exception/f_exception.js"; import { FLoggerLevel } from "./f_logger_level.js"; import { FExecutionContext } from "../execution_context/f_execution_context.js"; import { FLoggerLabelValue } from "./f_logger_labels.js"; export interface LoggerFactory { (loggerName: string): FLogger; } export interface FLoggerMessageFactory { (): string; } export declare abstract class FLogger { private static _loggerFactory; private static get loggerFactory(); static setLoggerFactory(factory: LoggerFactory): void; /** * Factory constructor */ static create(loggerName: string): FLogger; abstract get isTraceEnabled(): boolean; abstract get isDebugEnabled(): boolean; abstract get isInfoEnabled(): boolean; abstract get isWarnEnabled(): boolean; abstract get isErrorEnabled(): boolean; abstract get isFatalEnabled(): boolean; abstract get name(): string | null; abstract trace(executionContext: FExecutionContext, message: string, ex?: FException): void; abstract trace(executionContext: FExecutionContext, messageFactory: FLoggerMessageFactory, ex?: FException): void; abstract debug(executionContext: FExecutionContext, message: string, ex?: FException): void; abstract debug(executionContext: FExecutionContext, messageFactory: FLoggerMessageFactory, ex?: FException): void; abstract info(executionContext: FExecutionContext, message: string): void; abstract info(executionContext: FExecutionContext, messageFactory: FLoggerMessageFactory): void; abstract warn(executionContext: FExecutionContext, message: string): void; abstract warn(executionContext: FExecutionContext, messageFactory: FLoggerMessageFactory): void; abstract error(executionContext: FExecutionContext, message: string): void; abstract error(executionContext: FExecutionContext, messageFactory: FLoggerMessageFactory): void; abstract fatal(executionContext: FExecutionContext, message: string): void; abstract fatal(executionContext: FExecutionContext, messageFactory: FLoggerMessageFactory): void; abstract log(executionContextOrLabels: FExecutionContext | ReadonlyArray<FLoggerLabelValue>, level: FLoggerLevel, messageOrMessageFactory: string | FLoggerMessageFactory, ex?: FException): void; } export declare abstract class FLoggerBase extends FLogger { get isTraceEnabled(): boolean; get isDebugEnabled(): boolean; get isInfoEnabled(): boolean; get isWarnEnabled(): boolean; get isErrorEnabled(): boolean; get isFatalEnabled(): boolean; get name(): string; trace(variant: FExecutionContext | ReadonlyArray<FLoggerLabelValue>, messageOrMessageFactory: string | FLoggerMessageFactory, ex?: FException): void; debug(variant: FExecutionContext | ReadonlyArray<FLoggerLabelValue>, messageOrMessageFactory: string | FLoggerMessageFactory, ex?: FException): void; info(variant: FExecutionContext | ReadonlyArray<FLoggerLabelValue>, messageOrMessageFactory: string | FLoggerMessageFactory): void; warn(variant: FExecutionContext | ReadonlyArray<FLoggerLabelValue>, messageOrMessageFactory: string | FLoggerMessageFactory): void; error(variant: FExecutionContext | ReadonlyArray<FLoggerLabelValue>, messageOrMessageFactory: string | FLoggerMessageFactory): void; fatal(variant: FExecutionContext | ReadonlyArray<FLoggerLabelValue>, messageOrMessageFactory: string | FLoggerMessageFactory): void; log(executionContextOrLabels: FExecutionContext | ReadonlyArray<FLoggerLabelValue>, level: FLoggerLevel, messageOrMessageFactory: string | FLoggerMessageFactory, ex?: FException): void; protected constructor(loggerName: string); protected abstract isLevelEnabled(level: FLoggerLevel): boolean; /** * Unconditionally(without check logLevel settings) write message to logger output. * * Override this method to implement custom logger. */ protected abstract writeToOutput(level: FLoggerLevel, labelValues: ReadonlyArray<FLoggerLabelValue>, message: string, ex?: FException): void; private readonly _name; static _resolveLoggerLabels(variant: FExecutionContext | ReadonlyArray<FLoggerLabelValue>): ReadonlyArray<FLoggerLabelValue>; static _resolveMessage(messageOrMessageFactory: string | FLoggerMessageFactory): string; private static readonly _emptyLabelValues; } export declare abstract class FLoggerBaseWithLevel extends FLoggerBase { static buildLoggerLevelsMap(level: FLoggerLevel | null): Map<FLoggerLevel, boolean>; constructor(loggerName: string, level: FLoggerLevel); protected isLevelEnabled(level: FLoggerLevel): boolean; private readonly levels; } export declare abstract class FLoggerConsole extends FLoggerBaseWithLevel { /** * Factory constructor */ static create(loggerName: string, opts?: { readonly level?: FLoggerLevel; readonly format?: FLoggerConsole.Format; readonly output?: "stdout" | "stderr"; }): FLogger; } export declare namespace FLoggerConsole { type Format = "text" | "json"; }