1
0
Fork 0
mirror of https://github.com/mmumshad/ansible-playable.git synced 2025-03-09 23:38:54 +00:00

Implement Express server logging

This commit is contained in:
Mumshad Mannambeth 2017-07-08 20:32:46 -04:00
parent 14e0c77521
commit 49c56d65d6
4 changed files with 30 additions and 1 deletions

View file

@ -37,6 +37,7 @@
"express": "^4.13.3",
"express-jwt": "^5.0.0",
"express-session": "^1.11.3",
"express-winston": "^2.4.0",
"fast-json-patch": "^1.0.0",
"filendir": "^1.0.0",
"font-awesome": ">=4.1.0",

View file

@ -4,6 +4,14 @@
var winston = require('winston');
winston.add(winston.transports.File, {filename: './logs/server.log', json: false, colorize: true});
import config from '../../config/environment';
winston.add(winston.transports.File, {
filename: config.paths.local_server_logfile,
json: false,
colorize: true,
maxsize: '10485760',
maxFiles: '10'
});
module.exports = winston;

View file

@ -12,6 +12,8 @@ exports = module.exports = {
},
paths: {
local_server_logfile: './logs/server.log',
local_express_server_logfile: './logs/server-api.log',
ansible_projects: '/opt/ansible-projects',
ansible_projects_arhive: '/archive', // relative to projects folder
ansible_custom_api_local: './helpers/AnsibleAPI.py',

View file

@ -20,6 +20,8 @@ import session from 'express-session';
import connectMongo from 'connect-mongo';
import mongoose from 'mongoose';
var MongoStore = connectMongo(session);
var winston = require('winston'),
expressWinston = require('express-winston');
export default function(app) {
var env = app.get('env');
@ -46,6 +48,22 @@ export default function(app) {
app.use(cookieParser());
app.use(passport.initialize());
app.use(expressWinston.logger({
transports: [
new winston.transports.File({
json: false,
colorize: true,
filename: config.paths.local_express_server_logfile,
maxsize: '10485760',
maxFiles: '10'
})
],
meta: true, // optional: control whether you want to log the meta data about the request (default to true)
msg: "HTTP {{req.method}} {{req.url}}", // optional: customize the default logging message. E.g. "{{res.statusCode}} {{req.method}} {{res.responseTime}}ms {{req.url}}"
expressFormat: true, // Use the default Express/morgan request formatting. Enabling this will override any msg if true. Will only output colors with colorize set to true
colorize: true, // Color the text and status code, using the Express/morgan color palette (text: gray, status: default green, 3XX cyan, 4XX yellow, 5XX red).
ignoreRoute: function (req, res) { return false; } // optional: allows to skip some log messages based on request and/or response
}));
// Persist sessions with MongoStore / sequelizeStore
// We need to enable sessions for passport-twitter because it's an