log4deno is a tool to help the programmer output log statements to a variety of output targets. In case of problems with an application, it is helpful to enable logging so that the problem can be located.
- Multipe configurations
- Console output
- Files output
- Configure
- Colors
- Custom templates
- Set avaliable levels
- Reverse logs list
- Max file size
- Dynamic configuration
/** Create instance */
export const logger = new Logger();
/** Usage */
logger.debug('debug message');
logger.info('info');
/** Usage with chain */
logger
.warn('warn message')
.error(new Error('error message'))
.critical(new Error('critical message'));
/** Write to file only error and critical */
const logger = new Logger();
const config: LoggerConfig = {
error: {
types: 'file',
fileName: 'Error.log',
logFolder: './Logs/Errors',
logLevel: ['ERROR', 'CRITICAL']
}
}
logger.configure(config);
const logger = new Logger();
const config: LoggerConfig = {
formattedLogs: {
logFormat: '$level - $date',
dateFormat: 'dd.MMMM.yyyy',
}
};
logger.configure(config);
const logger = new Logger();
/** Static config */
const config: LoggerConfig = {
default: {
types: ['console', 'file'],
fileName: 'LogFile.log',
logLevel: ['INFO', 'WARN', 'ERROR', 'CRITICAL']
},
error: {
types: 'file',
fileName: 'Error.log',
logFolder: './Logs/Errors',
logLevel: ['ERROR', 'CRITICAL']
}
};
/** Enabled only in debug mode */
isDebug && (config.debug = {
types: 'console',
logLevel: ['DEBUG']
})
logger.configure(config);
- types: Array<'console' | 'file'>
- logFolder: folder for logs
- fileName: log file name
- logLevel: Array<'DEBUG' | 'INFO' | 'WARN' | 'ERROR' | 'CRITICAL'>
- logFormat: log info output format
- dateFormat: date output format
export const defaultConfig: LoggerConfig = {
default: {
types: ['console', 'file'],
logFolder: './Logs',
fileName: 'LogFile.log',
logLevel: ['DEBUG', 'INFO', 'WARN', 'ERROR', 'CRITICAL']
logFormat: '[$date] [$level] [$name]',
dateFormat: 'yyyy-MM-dd HH:mm:ss',
}
}
Config parametr: logFormat
Default value: '[$date] [$level] [$name]'
Params:
- $date - log date
- $level - log level
- $name - log config name
Config parametr: dateFormat
Default value: 'yyyy-MM-dd HH:mm:ss'