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

Commit

Permalink
Merge pull request #254 from lirantal/enhancement-logger-config
Browse files Browse the repository at this point in the history
Enhancing application logger configuration
  • Loading branch information
lirantal committed Nov 7, 2014
2 parents 24d449c + 5598caf commit ad87029
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 3 deletions.
9 changes: 9 additions & 0 deletions config/env/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ module.exports = {
templateEngine: 'swig',
sessionSecret: 'MEAN',
sessionCollection: 'sessions',
log: {
// Can specify one of 'combined', 'common', 'dev', 'short', 'tiny'
format: 'combined',
// Stream defaults to process.stdout
// Uncomment to enable logging to a log on the file system
options: {
stream: 'access.log'
}
},
assets: {
lib: {
css: [
Expand Down
9 changes: 9 additions & 0 deletions config/env/development.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

module.exports = {
db: 'mongodb://localhost/mean-dev',
log: {
// Can specify one of 'combined', 'common', 'dev', 'short', 'tiny'
format: 'dev',
// Stream defaults to process.stdout
// Uncomment to enable logging to a log on the file system
options: {
//stream: 'access.log'
}
},
app: {
title: 'MEAN.JS - Development Environment'
},
Expand Down
9 changes: 9 additions & 0 deletions config/env/production.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

module.exports = {
db: process.env.MONGOHQ_URL || process.env.MONGOLAB_URI || 'mongodb://' + (process.env.DB_1_PORT_27017_TCP_ADDR || 'localhost') + '/mean',
log: {
// Can specify one of 'combined', 'common', 'dev', 'short', 'tiny'
format: 'combined',
// Stream defaults to process.stdout
// Uncomment to enable logging to a log on the file system
options: {
stream: 'access.log'
}
},
assets: {
lib: {
css: [
Expand Down
9 changes: 9 additions & 0 deletions config/env/secure.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
module.exports = {
port: 443,
db: process.env.MONGOHQ_URL || process.env.MONGOLAB_URI || 'mongodb://localhost/mean',
log: {
// Can specify one of 'combined', 'common', 'dev', 'short', 'tiny'
format: 'combined',
// Stream defaults to process.stdout
// Uncomment to enable logging to a log on the file system
options: {
stream: 'access.log'
}
},
assets: {
lib: {
css: [
Expand Down
9 changes: 9 additions & 0 deletions config/env/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
module.exports = {
db: 'mongodb://localhost/mean-test',
port: 3001,
log: {
// Can specify one of 'combined', 'common', 'dev', 'short', 'tiny'
format: 'dev',
// Stream defaults to process.stdout
// Uncomment to enable logging to a log on the file system
options: {
//stream: 'access.log'
}
},
app: {
title: 'MEAN.JS - Test Environment'
},
Expand Down
7 changes: 4 additions & 3 deletions config/express.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var fs = require('fs'),
https = require('https'),
express = require('express'),
morgan = require('morgan'),
logger = require('./logger'),
bodyParser = require('body-parser'),
session = require('express-session'),
compress = require('compression'),
Expand Down Expand Up @@ -64,11 +65,11 @@ module.exports = function(db) {
app.set('view engine', 'server.view.html');
app.set('views', './app/views');

// Enable logger (morgan)
app.use(morgan(logger.getLogFormat(), logger.getLogOptions()));

// Environment dependent middleware
if (process.env.NODE_ENV === 'development') {
// Enable logger (morgan)
app.use(morgan('dev'));

// Disable views cache
app.set('view cache', false);
} else if (process.env.NODE_ENV === 'production') {
Expand Down
36 changes: 36 additions & 0 deletions config/logger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use strict';

/**
* Module dependencies.
*/

var morgan = require('morgan');
var config = require('./config');
var fs = require('fs');

/**
* Module init function.
*/
module.exports = {

getLogFormat: function() {
return config.log.format;
},

getLogOptions: function() {
var options = {};

try {
if ('stream' in config.log.options) {
options = {
stream: fs.createWriteStream(process.cwd() + '/' + config.log.options.stream, {flags: 'a'})
};
}
} catch (e) {
options = {};
}

return options;
}

};

0 comments on commit ad87029

Please sign in to comment.