Skip to content

xfxstudios/node_smart_logger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Node Smart Logger

A library that allows you to keep better control of your daily logs in Node


Install

npm i node_smart_logger

Start it

import SmartLogger from 'node_smart_logger';

const _logger = new SmartLogger();

By default logger will create a logs folder in the root of your project, but you can also indicate the path and name of the logs folder when you initialize it:

const config = {
    logs_folder_path: "./someDir/anotherDir",
    logs_folder_name: "anotherLogsFolderName"
}
const _logger = new SmartLogger(config);

logs

These logs are saved to a file in your directory

// Info log
_logger.setInfo("message");
//[2022-5-28 9:21:6] - [info] - message | [data]: {}

// Error log
_logger.setError("message");
//[2022-5-28 9:21:6] - [error] - message | [data]: {}

// Alert log
_logger.setAlert("message");
//[2022-5-28 9:21:6] - [alert] - message | [data]: {}

// Debug log
_logger.setDebug("message");
//[2022-5-28 9:21:6] - [debug] - message | [data]: {}

// Critical log
_logger.setCritical("message");
//[2022-5-28 9:21:6] - [critical] - message | [data]: {}

// Warning log
_logger.setWarning("message");
//[2022-5-28 9:21:6] - [warning] - message | [data]: {}

// Success log
_logger.setSuccess("message");
//[2022-5-28 9:21:6] - [success] - message | [data]: {}

Logs agree to receive a data object

const dataToLog = {
    error: false,
    message: 'some message'
}

_logger.setCritical("log message", dataToLog);
//[2022-5-28 9:21:6] - [critical]  - log message | [data]: {"error":false,"message":"some message"}

Logs only for terminal

Steep

_logger.setSteep({message: 'some message',number: 5});
//[ steep 5 ] :::: some message

Cantity

_logger.setCantity({message: 'Total Records', total: 100});
//Total Records [100]

Interval

_logger.setInterval({message: 'Record Processed', actual: 5, total: 100});
//Record Processed [5] of [100]

You can create titles with background according to the level of the log

Title

_logger.setTitle({message: "This is a error tittle", level: "error"});

Title levels available

  • info
  • warning
  • error
  • alert
  • critical
  • success
  • degub

Express Log Middleware

_logger.logExpressRequest(req:Request, res:Response, next:NextFunction);

//[2022-5-28 22:5:49] - [info]-[express] | [endpoint] [GET] /process-file/icbc_test |  [headers] {"content-type":"application/json","host":"localhost:3000"} | [params] {"param1":"value1"} | [body] {}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published