Giter VIP home page Giter VIP logo

log4deno's Introduction

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

log4deno's People

Contributors

klimentru1986 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.