import { AbstractService } from './service'; /** * Syslog Levels * @see http://tools.ietf.org/html/rfc5424 */ export declare type LogLevel = 'emergency' | 'alert' | 'critical' | 'error' | 'warning' | 'notice' | 'info' | 'debug'; export declare type LogVerbosityType = 'silly' | 'verbose' | 'info' | 'error' | 'none'; export declare enum LogVerbosity { none = 0, error = 1, info = 2, verbose = 3, silly = 4, } export interface LoggerConstructor { new (): T; } /** * Abstract Logger class that should be used as the DI token for any logging. The implementation * should be defined by the provider definition * * Example * * main.ts * ```typescript * let providers: ProviderDefinition[] = [ * {provide: Logger, useClass: ConsoleLogger}, * ]; * ``` * someService.service.ts * ```typescript * @Injectable() * @Service() * export class SomeService extends AbstractService { * constructor(protected logger: Logger) { * logger.source('Some Service').debug('constructor initialized') * } * } * ``` * * Logger provides methods for all log types defined by * [The Syslog Protocol (RFC 5424)](http://tools.ietf.org/html/rfc5424) * */ export declare abstract class Logger extends AbstractService { protected impl: LoggerConstructor; protected sourceName: string; protected verbosityLevel: LogVerbosity; constructor(impl: LoggerConstructor); /** * Log emergency message(s) to the log output * * Example: * ```typescript * try { * // something that might throw Error * catch(e){ * logger.emergency(e.message).debug(e.stack); * } * ``` * @param args * @returns {Logger} */ emergency(...args: any[]): this; /** * Log alert message(s) to the log output * @param args * @returns {any} */ alert(...args: any[]): this; /** * Log critical message(s) to the log output * @param args * @returns {any} */ critical(...args: any[]): this; /** * Log error message(s) to the log output * @param args * @returns {any} */ error(...args: any[]): this; /** * Log warning message(s) to the log output * @param args * @returns {any} */ warning(...args: any[]): this; /** * Log notice message(s) to the log output * @param args * @returns {any} */ notice(...args: any[]): this; /** * Log info message(s) to the log output * @param args * @returns {any} */ info(...args: any[]): this; /** * Log debug message(s) to the log output * @param args * @returns {Logger} */ debug(...args: any[]): this; /** * Given the log level and list of messages, and if the global verbosity level is satisified, * invoke the persist log method. * @param logLevel * @param verbosity * @param messages * @returns {any} */ protected log(logLevel: LogLevel, verbosity: LogVerbosity, ...messages: any[]): this; /** * Set a string to denote the source of the log. The effect this has on the log output is up * to the implementing class. * @param sourceName * @returns {Logger} */ protected setSource(sourceName: string): this; /** * Sets the current log verbosity level, used to compare against the global value to determine * whether or not to persist the log. If a verbosity is already set, don't force unless requested. * to, as * @param level * @param force * @returns {Logger} */ protected setVerbosity(level: LogVerbosity, force?: boolean): this; /** * Chainable method to allow forcing the log level to only show when log verbosity level is 'silly' * * Example: * ```typescript * try { * //do something that throws error * } catch (e) { * this.logger.error(e.message).silly.debug(e.stack); * } * ``` * This will only log the stack trace if the global `process.env.LOG_LEVEL` is `'silly'` * @returns {Logger} */ readonly silly: this; /** * Chainable method to allow forcing the log level to only show when log verbosity level is 'verbose' * @returns {Logger} */ readonly verbose: this; /** * Creates a new instance of the logger class with the source set. This allows the use of * passing around log instances to avoid having to set source each time. * * Example: * * example.service.ts * ```typescript * export class ExampleService extends AbstractService { * protected logger: Logger; * constructor(loggerBase:Logger){ * this.logger = loggerBase.source(this.constructor.name); * } * * public logExample():void { * this.logger.info('Log message'); * } * ``` * * When the `(new ExampleService).logExample()` method is called, the logger implementation will * have the source defined as `ExampleService`. * @param source * @returns {any} */ source(source: string): Logger; /** * Outputs the log message(s) to the implementation's destination. * * For example if the implementation is a Loggly logger, it should post the logs to Loggly. * @param logLevel * @param messages */ abstract persistLog(logLevel: LogLevel, messages: any[]): this; }