Skip to content
This repository was archived by the owner on Aug 30, 2021. It is now read-only.

Commit bf7bcc6

Browse files
committed
adding support for logger handling which allows for saving the requests to a logfile, useful for production systems
1 parent 0f4a585 commit bf7bcc6

File tree

6 files changed

+41
-3
lines changed

6 files changed

+41
-3
lines changed

config/env/all.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ module.exports = {
1212
sessionCollection: 'sessions',
1313
log: {
1414
// Can specify one of 'combined', 'common', 'dev', 'short', 'tiny'
15-
format: 'combined'
15+
format: 'combined',
16+
// Stream defaults to process.stdout
17+
// Uncomment to enable logging to a log on the file system
18+
options: {
19+
stream: 'access.log'
20+
}
1621
},
1722
assets: {
1823
lib: {

config/env/development.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ module.exports = {
44
db: 'mongodb://localhost/mean-dev',
55
log: {
66
// Can specify one of 'combined', 'common', 'dev', 'short', 'tiny'
7-
format: 'dev'
7+
format: 'dev',
8+
// Stream defaults to process.stdout
9+
// Uncomment to enable logging to a log on the file system
10+
options: {
11+
//stream: 'access.log'
12+
}
813
},
914
app: {
1015
title: 'MEAN.JS - Development Environment'

config/env/production.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
module.exports = {
44
db: process.env.MONGOHQ_URL || process.env.MONGOLAB_URI || 'mongodb://' + (process.env.DB_1_PORT_27017_TCP_ADDR || 'localhost') + '/mean',
5+
log: {
6+
// Can specify one of 'combined', 'common', 'dev', 'short', 'tiny'
7+
format: 'combined',
8+
// Stream defaults to process.stdout
9+
// Uncomment to enable logging to a log on the file system
10+
options: {
11+
stream: 'access.log'
12+
}
13+
},
514
assets: {
615
lib: {
716
css: [

config/env/secure.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@
33
module.exports = {
44
port: 443,
55
db: process.env.MONGOHQ_URL || process.env.MONGOLAB_URI || 'mongodb://localhost/mean',
6+
log: {
7+
// Can specify one of 'combined', 'common', 'dev', 'short', 'tiny'
8+
format: 'combined',
9+
// Stream defaults to process.stdout
10+
// Uncomment to enable logging to a log on the file system
11+
options: {
12+
stream: 'access.log'
13+
}
14+
},
615
assets: {
716
lib: {
817
css: [

config/env/test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@
33
module.exports = {
44
db: 'mongodb://localhost/mean-test',
55
port: 3001,
6+
log: {
7+
// Can specify one of 'combined', 'common', 'dev', 'short', 'tiny'
8+
format: 'dev',
9+
// Stream defaults to process.stdout
10+
// Uncomment to enable logging to a log on the file system
11+
options: {
12+
//stream: 'access.log'
13+
}
14+
},
615
app: {
716
title: 'MEAN.JS - Test Environment'
817
},

config/express.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ var fs = require('fs'),
88
https = require('https'),
99
express = require('express'),
1010
morgan = require('morgan'),
11+
logger = require('./logger'),
1112
bodyParser = require('body-parser'),
1213
session = require('express-session'),
1314
compress = require('compression'),
@@ -65,7 +66,7 @@ module.exports = function(db) {
6566
app.set('views', './app/views');
6667

6768
// Enable logger (morgan)
68-
app.use(morgan(config.log.format));
69+
app.use(morgan(logger.getLogFormat(), logger.getLogOptions()));
6970

7071
// Environment dependent middleware
7172
if (process.env.NODE_ENV === 'development') {

0 commit comments

Comments
 (0)