Skip to content

shams-nahid/Node-Application-Logger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Step by Step Guideline

Objective

  • logging activity in node app.
  • Create specific log file every hour
  • Easy configure log file round (Hourly, daily)
  • Easy configure log file size
  • Delete log files after specific days
  • Environment specific log structure

Run application

Clone the repository

git clone https://github.com/bmshamsnahid/Manage-Node-App-Environment

Install dependencies

npm i

Import the logger.js file in your desired place, in my case example.js and invoke it.

const logger = require('./logger');
logger.info('Info log example');

Now run example.js

node example.js

Stream

To integrate with morgan

const express = require('express');
const morgan = require('morgan');

const logger = require('./logger');
const app = express();

app.use(morgan('tiny', { stream: logger.stream }));

Now morgan will put each route information in log file.

Configure

Go to logger.js file and update configurations.

License

MIT