Skip to content

Instantly share code, notes, and snippets.

@geshan
Created March 14, 2021 04:29
Show Gist options
  • Save geshan/ec307d0797fcd06e201a463919546c58 to your computer and use it in GitHub Desktop.
Save geshan/ec307d0797fcd06e201a463919546c58 to your computer and use it in GitHub Desktop.
Markdium-5 Node.js Logging libraries compared for you to make the optimal choice
const winston = require('winston');
const expressWinston = require('express-winston');
const express = require('express');
const app = express();
const port = 3001;
//more options here - https://github.com/bithavoc/express-winston#request-logging
app.use(expressWinston.logger({
transports: [
new winston.transports.Console()
],
format: winston.format.combine(
winston.format.colorize(),
winston.format.json()
),
meta: false,
msg: "HTTP {{req.method}} {{req.url}}",
expressFormat: true,
colorize: false,
ignoreRoute: function (req, res) { return false; }
}));
app.get('/', (req, res) => {
res.send('Hello World! - Winston logged');
});
app.get('/api/test', (req, res) => {
res.json({'message': 'Hello winston!'});
});
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment