1.0.1 • Published 4 years ago

@psteh/es-log v1.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
4 years ago

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

PropertyTypeDefaultDescription
pathstring./Path to log file
filenamestringlog.logFile name
levelstringDEBUGLog levelAccepts one of following level:- DEBUG- INFO- WARN- ERROR- FATAL
sizeinteger50Maximum size of log (mb)
transactionIdLengthinteger10Length of transactionIdNote: transactionId will get truncate if ID provided is longer than set
logToConsolebooleantruePrint log to console
datetimeobject{}Options for datetime (refer below)
datetime.formatstringYYYYMMDD HH:mm:ss.SSSDatetime format
datetime.timezonestringUTCTimezone 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!