Giter Club home page Giter Club logo

log's Introduction

es-log

Easy and Simple Logging to use.

This package provides an easy and simple to use logging to your application.

const log = require('@psteh/es-log');
 
log.init();
 
log.debug('Yep, this line here...');
log.info('Nothing to see here folks...');
log.warn('This line looks sus');
log.error('Line just got serious');
log.fatal('EMERGENCY MEETING!');

Options

Property Type Default Description
path string ./ Path to log file
filename string log.log File name
level string DEBUG Log level
Accepts one of following level:
- DEBUG
- INFO
- WARN
- ERROR
- FATAL
size integer 50 Maximum size of log (mb)
transactionIdLength integer 10 Length of transactionId
Note: transactionId will get truncate if ID provided is longer than set
logToConsole boolean true Print log to console
datetime object {} Options for datetime (refer below)
datetime.format string YYYYMMDD HH:mm:ss.SSS Datetime format
datetime.timezone string UTC Timezone for datetime

How to use

const log = require('@psteh/es-log');
 
log.init({
    path: './logs',
    filename: 'log.log',
    level: 'DEBUG',
    size: 50,
    transactionIdLength: 10,
    logToConsole: false,
    datetime: {
        format: 'YYYYMMDD HH:mm:ss.SSS',
        timezone: 'UTC'
    }
});
 
log.debug('Yep, this line here...');
log.info('Nothing to see here folks...');
log.warn('This line looks sus');
log.error('Line just got serious');
log.fatal('EMERGENCY MEETING!');

// prints
// [20200101 000123.360][          ] Yep, this line here
// [20200101 000123.369][          ] Nothing to see here folks...
// [20200101 000123.372][          ] This line looks sus
// [20200101 000123.376][          ] Line just got serious
// [20200101 000123.380][          ] EMERGENCY MEETING!

You can pass in transactionId to note the whole transaction of a process.

Note: transactionId takes in maximum length of 10 characters

log.debug({ transactionId: 'AU2020', message: 'Yep, this line here...'});
log.info({ transactionId: 'AU2020', message: 'Nothing to see here folks...'});
log.warn({ transactionId: 'AU2020', message: 'This line looks sus'});
log.error({ transactionId: 'AU2020', message: 'Line just got serious'});
log.fatal({ transactionId: 'AU2020', message: 'EMERGENCY MEETING!'});

// prints
// [20200101 000123.360][AU2020    ] Yep, this line here
// [20200101 000123.369][AU2020    ] Nothing to see here folks...
// [20200101 000123.372][AU2020    ] This line looks sus
// [20200101 000123.376][AU2020    ] Line just got serious
// [20200101 000123.380][AU2020    ] EMERGENCY MEETING!

log's People

Watchers

 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.