logger-middleware
Logger middleware using Winston and file daily rotate strategy. Create folder via path provided, log all Express requests and expose logger instance to be used in your application.
Installation
$ npm install loggerx
Usage
- Load the module
- Pass configuration options(folder path, file name)
- Apply middleware to express server(all express request are logged to file)
- Use logger into your application
Example
/* index.js */ const express = ; const app = ; const fs = ; const path = ; const logDirectory = path; //logDirectory=C:/Development/loggerProject/logs/fileLog.log const logger = path:logDirectoryfileName:'fileLog.log'; app; logger; logger; logger; logger; logger; const route = ; app; const server = app; moduleexports = express: server
/* fileLog.log */2018-01-20T19:10:20.861Z [INFO] Log through info2018-01-20T19:10:20.862Z [INFO] info2018-01-20T19:10:20.862Z [WARN] warn2018-01-20T19:10:20.862Z [ERROR] error2018-01-20T19:10:25.852Z [INFO] Request protocol:[http], request type:[POST], request path:[/api/helloworld], request headers:[{"cache-control":"no-cache","user-agent":"PostmanRuntime/x.x.x","accept":"*/*","host":"localhost:3000","accept-encoding":"gzip, deflate","content-length":"0","connection":"keep-alive"}]