@palmares/logging
Version:
Palmares logging interface so you can log it to the console or other places as well
90 lines • 3.68 kB
TypeScript
import type { SavedLoggingMessagesType } from './types';
/**
* This is the main logger class. This is the class that you will use to log messages in the application. You can
* log to the console but you can also log to a file or a database.
* You can add your own custom logger logic.
*
* This also lets you add logging messages that you can use to log messages. This is useful when you want to log
* the same message multiple times. And you don't want to repeat the same text over and over again.
*
* @example
* ```ts
* const logger = new Logger({ name: 'my-logger' });
* logger.log('Hello World!');
* ```
*/
export declare class Logger<TLoggingMessages extends SavedLoggingMessagesType> {
#private;
name: string;
domainName: string;
loggingMessages?: TLoggingMessages;
constructor(args: {
domainName?: string;
name?: string;
}, loggingMessages?: TLoggingMessages);
/**
* Retrieve a child logger from the current logger.
*
* @example
* ```ts
* const logger = new Logger({ domainName: 'my-custom-package' });
* const childLogger = logger.getChildLogger('migrations');
* ```
*
* @param name - The name of the child logger.
*
* @returns A new logger instance with the given name.
*/
getChildLogger<TNewLoggingMessages extends SavedLoggingMessagesType>(name: string, loggingMessages?: TNewLoggingMessages): Logger<TLoggingMessages & TNewLoggingMessages>;
/**
* If you don't use the `loggingMessages` property in the constructor, you can use this method to add logging
* messages to the logger.
*
* On here you are only able to add logging messages one by one. So you need to call this method for each
* logging message you want to add.
* This will work as a builder pattern so you can append as many logging messages as you want.
*
* @example
* ```ts
* const logger = new Logger({ name: 'my-logger' })
* .appendLogMessage('my-logging-message', {
* category: 'debug',
* handler: (args: { databaseName: string }) => `Hello World! ${args.databasename}`,
* });
*
* logger.logMessage('my-logging-message', { databaseName: 'my-database' });
* ```
*
* @param name - The name of the logging message.
* @param log - The logging function that will be called when the `logMessage` method is called.
*
* @returns - The current logger instance.
*/
appendLogMessage<TName extends string, TLog extends SavedLoggingMessagesType[string]>(name: TName, log: TLog): Logger<TLoggingMessages & { [key in TName]: TLog; }>;
/**
* This will log the message that was added to the logger using the `appendLogMessage` method or the
* `loggingMessages` property in the constructor.
*
* @example
* ```ts
* const logger = new Logger({ name: 'my-logger' }, {
* 'my-logging-message': {
* category: 'debug',
* handler: (args: { databaseName: string }) => `Hello World! ${args.databasename}`,
* },
* });
*
* logger.logMessage('my-logging-message', { databaseName: 'my-database' });
* ```
*
* @param name - The name of the logging message.
* @param args - The arguments that will be passed to the handler function.
*/
logMessage<TName extends keyof TLoggingMessages>(name: TName, args: Parameters<TLoggingMessages[TName]['handler']>[0]): void;
log(message: string): void;
info(message: string): void;
debug(message: string): void;
warn(message: string): void;
error(message: string): void;
}
//# sourceMappingURL=logger.d.ts.map