Skip to content

Commit

Permalink
Added configurable log path. Splitted send email logic into two indep…
Browse files Browse the repository at this point in the history
…endent functions for clarity.
  • Loading branch information
igznicolasjaremek committed Sep 25, 2015
1 parent 0fa1096 commit 8eddffb
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 50 deletions.
3 changes: 2 additions & 1 deletion config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"port": 3000,
"log": {
"level": "debug",
"path": "/tmp/resonator.log"
"directory": "./logs/",
"filename": "resonator.log"
},
"db": {
"conn": "mongodb://localhost:27017/resonator-backend"
Expand Down
31 changes: 0 additions & 31 deletions config/development.json

This file was deleted.

5 changes: 5 additions & 0 deletions config/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
"db": {
"conn": "mongodb://localhost:27017/resonator-test"
},
"log": {
"level": "debug",
"directory": "./logs/",
"filename": "resonator-test.log"
},
"mongoose": {
"debug": false
},
Expand Down
2 changes: 1 addition & 1 deletion examples/dockerized-service/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ resonator:
links:
- mongodb
volumes:
- ./production.json:/app/config/production.json
- ./development.json:/app/config/development.json
- /tmp:/tmp
environment:
- NODE_ENV=development
Expand Down
42 changes: 31 additions & 11 deletions lib/platforms/email.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,10 @@ function sendEmailNotification(identities, body, callback) {

var emails, content;

if (!identities) {
emails = body.to;
content = body;
content.subject = body.subject;
content.message = content.html;
} else {
emails = _.flatten(_.map(identities, function(identity) {
return identity.devices.email;
}));
content = body.content;
}
emails = _.flatten(_.map(identities, function(identity) {
return identity.devices.email;
}));
content = body.content;

log.info('Sending request to send emails', emails, content);

Expand All @@ -41,6 +34,32 @@ function sendEmailNotification(identities, body, callback) {
});
}

function sendSingleEmail(body, callback) {

var emails = body.to;
var content = body;
content.subject = body.subject;
content.message = content.html;

log.info('Sending request to sendSingleEmail', emails, content);

transport.send(emails, content, function (err, response, body) {
if (err) {
return callback(err);
}

var output = {
response: response,
body: body
};

log.info('Receiving response from email request');
log.debug('Receiving response from email request', body);

return callback(null, output);
});
}

var emailOptions = {
resourceName: 'devices.email',
batchLimit: _.min([BATCH_LIMIT, CUSTOM_BATCH_LIMIT]),
Expand All @@ -49,5 +68,6 @@ var emailOptions = {

module.exports = {
send: sendEmailNotification,
sendSingleEmail: sendSingleEmail,
options: emailOptions
};
2 changes: 1 addition & 1 deletion lib/routes/email.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ routes.sendEmailNotification = function(req, res, next) {

routes.sendSingleEmail = function(req, res, next) {

emailPlatform.send(undefined, req.body, function(err) {
emailPlatform.sendSingleEmail(req.body, function(err) {
if (err) {
return next(err);
}
Expand Down
16 changes: 13 additions & 3 deletions lib/util/logger.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
var config = require('config'),
bunyan = require('bunyan'),
fs = require('fs'),
logger, options, streams,
defaultStreams = [{ stream: process.stdout }, { path: config.get('log.path') }];
logDirectory = config.get('log.directory'),
logFullPath = logDirectory + config.get('log.filename'),
defaultStreams = [{ stream: process.stdout }, { path: logFullPath }]
;

var dir = logDirectory;
if (!fs.existsSync(dir)){
fs.mkdirSync(dir);
}


switch (process.env.NODE_ENV) {
case 'production':
streams = [{ path: config.get('log.path') }];
streams = [{ path: logFullPath }];
break;
case 'test':
case 'test_ci':
streams = [{ path: config.get('log.path') }];
streams = [{ path: logFullPath }];
break;

default:
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"start": "node ./bin/server.js",
"start-mock": "node ./bin/mocked-server.js",
"fixtures": "node scripts/load_fixtures",
"fixtures": "node ./scripts/load_fixtures",
"test": "npm run test-cucumber && npm run test-mocha",
"test-cucumber": "NODE_ENV=test npm run fixtures && NODE_ENV=test cucumber-js cucumber/features/ --tags ~@ignore -r cucumber/features/support -r cucumber/features/",
"test-mocha": "NODE_ENV=test npm run fixtures && NODE_ENV=test ./node_modules/.bin/mocha --reporter nyan",
Expand Down Expand Up @@ -40,7 +40,7 @@
"license": "ISC",
"dependencies": {
"apn": "^1.7.4",
"async": "^0.9.0",
"async": "^1.4.2",
"body-parser": "^1.13.3",
"bson": "^0.4.11",
"bunyan": "^1.3.5",
Expand Down

0 comments on commit 8eddffb

Please sign in to comment.