README
Simple logger for Node.js applications
Do you want to log your Node.js app activity? Simple, let this package know what environment you are working at, and receive your own logs on console, file log or PostgreSQL table!
Installation
npm i winston --save-dev
npm i pg --save-dev
npm i logger-darbeta --save-dev
Usage
Using this package is actually simple. You just have to deconstruct logger
attribute and configLogger
function and use it.
Note: before you can use this package correctly, you must have to be sure of get correct credentials for connecting to DB.
PSQL Table must be have named 'logs' and have three columns: date, level, message an datatypes timestamp, text and text, respectly.
You do not need to create it, package will automatically detects it.
const { configDBConnection, configLogger, log } = require('logger-win-pg');
//Sets connection parameters for connecting to DB.
//configDBConnection(host, port, database, user, password)
configDBConnection('localhost', 5432, 'my_db', 'my_user', 'secret');
const isProduction = true;
const fileSize = 10000000;
const filesCount = 10;
//Sets logger behavior as production environment
configLogger(isProduction, fileSize, filesCount);
/*
Firs argument determines level of log (I: Info, W: Warn, E: Error) and
second argument is the message log.
*/
log('I', 'This is an INFO log recorded in LOGS table and file.');
log('E', 'This is an ERROR log recorded in LOGS table and file.');
log('w', 'This is a WARN log recorded in LOGS table and file.');
//Set logger behavior as local or test environment
configLogger(!isProduction, fileSize, filesCount);
log('i', 'This is an INFO log recorded in LOGS table, file and shown in console.');
log('e', 'This is an ERROR log recorded in LOGS table, file and shown in console.');
log('Q', 'This is a WARN log recorded in LOGS table, file and shown in console.');