Skip to content

klimentru1986/log4deno

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

log4deno

Overview

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.

Features

  • Multipe configurations
  • Console output
  • Files output
  • Configure
  • Colors
  • Custom templates
  • Set avaliable levels
  • Reverse logs list
  • Max file size
  • Dynamic configuration

Usage

/** 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);

Configuration

  • 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

Default configuration

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',
    }
}

Custom format

Log format

Config parametr: logFormat

Default value: '[$date] [$level] [$name]'

Params:

  • $date - log date
  • $level - log level
  • $name - log config name

Date format

Config parametr: dateFormat

Default value: 'yyyy-MM-dd HH:mm:ss'

Avaliable params

Releases

No releases published

Packages

No packages published