winston logger | Log into MongoDB | File | Console | nodejs tutorial

Published: 07 December 2019
on channel: Technical Babaji (Tarique Akhtar)
43,537
551

github link : https://github.com/Tariqu/winston_log...
```
const {

createLogger,
format,
transports
} = require("winston");
require('winston-mongodb').MongoDB;
const logger = createLogger({
transports: [
new transports.MongoDB({
db: process.env.MONGODB_URI,
level: 'silly',
options: {
useUnifiedTopology: true
}
}),
new transports.File({
filename: "error.log",
level: "error",
format: format.combine(format.timestamp(), format.json())
}),
new transports.File({
filename: "info.log",
level: "info",
format: format.combine(format.timestamp(), format.json())
}),
]
});
module.exports = logger;
```

Hello friends its me tarique akhtar ansari in this video I am going to show you how to log properly into console,
into file and into the database using winston don't worry guyyz I have given github link in the discription,

you can checkout and get get the source code of this video.



let me tell you the to most importent reason of doing log



1. first thing as a developer point of view

-------------------------------------------

when we work on development we normally use console to see application log

but once your application moved into the production server and users are started using your application

then if somthing went wrong like application crashed or giving wrong output then you can't check into the console

but if you have log into file or into the database then you can check and identify the mistakes ok



2. sencond thing

----------------

if you have log of every activity happening in your application then you can process that log and generate some useful information

Just take an example of facebook. Facebook has billions of users and they have log of every activity of the users



1. just imagine how many different types of information can generate from that log

even we can't imagine how much information we can generate from log



ok so lets jump into the coding



install

--------

1. npm install winston

2. npm install winston-mongodb



then create winston logger object inside that object define transports then use that object to log into console | file | mongodb


Watch video winston logger | Log into MongoDB | File | Console | nodejs tutorial online without registration, duration hours minute second in high quality. This video was added by user Technical Babaji (Tarique Akhtar) 07 December 2019, don't forget to share it with your friends and acquaintances, it has been viewed on our site 43,537 once and liked it 551 people.