dash-core
Version:
A foundational toolkit of types, collections, services, and architectural patterns designed to accelerate application development.
64 lines (63 loc) • 2.88 kB
TypeScript
export declare enum LogLevel {
DEBUG = "debug",
INFO = "info",
WARNING = "warn",
ERROR = "error"
}
/** Encapsulates service logging with configurable options. */
export declare class ServiceLogger {
private readonly logger;
private readonly options;
private get isObservable();
/**
* Creates a new instance of the ServiceLogger class with specified options.
* If no options are provided, defaults are used.
* @param {ServiceOptions} [options={}] - Configuration options for the logger.
* @param {string} options.serviceName - The name of the service (default is "nameless-service").
* @param {LogLevel} options.logLevel - The default log level (default is LogLevel.DEBUG).
* @param {boolean} options.verbose - Indicates whether verbose logging is enabled (default is true).
* @param {string} options.logPath - The directory where logs will be stored (default is the current working directory).
* @param {LogLevel} options.globalLogLevel - The global log level for the service (default is LogLevel.DEBUG).
* @param {string} options.globalFilter - A filter string for global logging configuration.
*/
constructor(options?: ServiceOptions);
/**
* Logs an informational message if the service is observable.
* @param {string} message - The message to log.
* @param {...unknown[]} meta - Additional metadata to log alongside the message.
*/
info(message: string, ...meta: unknown[]): void;
/**
* Logs a warning message.
* @param {string} message - The message to log.
* @param {...unknown[]} meta - Additional metadata to log alongside the message.
*/
warning(message: string, ...meta: unknown[]): void;
/**
* Logs a debug message if the service is observable.
* @param {string} message - The message to log.
* @param {...unknown[]} meta - Additional metadata to log alongside the message.
*/
debug(message: string, ...meta: unknown[]): void;
/**
* Logs an error message and returns an Error object.
* @param {string} message - The error message.
* @param {...unknown[]} meta - Additional metadata to log alongside the message.
* @returns {Error} The created error.
*/
error(message: string, ...meta: unknown[]): Error;
/**
* Adds transport to the logger to write logs to a specified file.
* @param {string} relativePath - The relative path where the log file will be stored.
* @param {LogLevel} [logLevel] - The log level for this transport. If not provided, all logs will be written.
*/
addTransport(relativePath: string, logLevel?: LogLevel): void;
}
export type ServiceOptions = {
serviceName?: string;
logLevel?: LogLevel;
verbose?: boolean;
logPath?: string;
globalLogLevel?: LogLevel | string;
globalFilter?: string;
};