From 3fa325d4fc0dc6de11b161cfbc5b0d4ede5b9ee7 Mon Sep 17 00:00:00 2001 From: Esther Date: Mon, 22 Jun 2020 22:03:28 +0100 Subject: [PATCH] Please please work --- app.js | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/app.js b/app.js index 13733a4..9334cb0 100644 --- a/app.js +++ b/app.js @@ -2,9 +2,7 @@ var createError = require('http-errors'); var express = require('express'); var path = require('path'); var cookieParser = require('cookie-parser'); -var logger = require('morgan'); var sassMiddleware = require('node-sass-middleware'); -var winston = require('./config/winston'); var indexRouter = require('./routes/index'); var aboutRouter = require('./routes/about'); @@ -18,10 +16,37 @@ app.disable('x-powered-by'); app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'pug'); +var logger = new winston.Logger({ + transports: [ + new winston.transports.File({ + level: 'info', + filename: './logs/all-logs.log', + handleExceptions: true, + json: true, + maxsize: 5242880, //5MB + maxFiles: 5, + colorize: false + }), + new ston.transportswin.Console({ + level: 'debug', + handleExceptions: true, + json: false, + colorize: true + }) + ], + exitOnError: false +}); + +logger.stream = { + write: function(message, encoding){ + logger.info(message); + } +}; + if (process.env.NODE_ENV === 'production') { - app.use(logger('combined', { stream: winston.stream })); + app.use(require("morgan")("common", { "stream": logger.stream })); } else { - app.use(logger('dev')); + app.use(require(morgan)('dev')); } app.use(express.json()); @@ -49,8 +74,6 @@ app.use(function(err, req, res, next) { res.locals.message = err.message; res.locals.error = req.app.get('env') === 'development' ? err : {}; - winston.error(`${err.status || 500} - ${err.message} - ${req.originalUrl} - ${req.method} - ${req.ip}`); - // render the error page res.status(err.status || 500); res.render('error', { title: 'Error', description: "Error" });