Merge pull request #42 from mailvelope/dev/papertrail

Dev/papertrail
This commit is contained in:
Tankred Hase 2017-08-18 18:25:10 +08:00 committed by GitHub
commit 80c760681c
14 changed files with 59 additions and 15 deletions

View File

@ -3,7 +3,12 @@
module.exports = { module.exports = {
log: { log: {
level: 'silly' level: process.env.LOG_LEVEL || 'silly'
},
papertrail: {
host: process.env.PAPERTRAIL_HOST,
port: process.env.PAPERTRAIL_PORT
}, },
server: { server: {

View File

@ -20,9 +20,11 @@
const cluster = require('cluster'); const cluster = require('cluster');
const numCPUs = require('os').cpus().length; const numCPUs = require('os').cpus().length;
const config = require('config'); const config = require('config');
const log = require('npmlog'); const log = require('winston');
const papertrail = require('./src/dao/papertrail');
log.level = config.log.level; log.level = config.log.level;
papertrail.init(config.papertrail);
// //
// Start worker cluster depending on number of CPUs // Start worker cluster depending on number of CPUs

View File

@ -29,8 +29,9 @@
"mongodb": "^2.2.31", "mongodb": "^2.2.31",
"nodemailer": "^2.4.2", "nodemailer": "^2.4.2",
"nodemailer-openpgp": "^1.0.2", "nodemailer-openpgp": "^1.0.2",
"npmlog": "^4.0.2", "openpgp": "^2.3.0",
"openpgp": "^2.3.0" "winston": "^2.3.1",
"winston-papertrail": "^1.0.5"
}, },
"devDependencies": { "devDependencies": {
"chai": "^4.1.1", "chai": "^4.1.1",

View File

@ -17,7 +17,7 @@
'use strict'; 'use strict';
const log = require('npmlog'); const log = require('winston');
const config = require('config'); const config = require('config');
const koaBody = require('koa-body'); const koaBody = require('koa-body');
const util = require('../service/util'); const util = require('../service/util');
@ -58,7 +58,7 @@ exports.parseBody = () => koaBody({
exports.logUnknownError = function(error, ctx) { exports.logUnknownError = function(error, ctx) {
if (error.status) { if (error.status) {
log.verbose('middleware', 'Request faild: %s, %s', error.status, error.message); log.verbose('middleware', `Request failed: ${error.status} ${error.message}`);
} else { } else {
log.error('middleware', 'Unknown error', error, ctx); log.error('middleware', 'Unknown error', error, ctx);
} }

View File

@ -17,7 +17,7 @@
'use strict'; 'use strict';
const log = require('npmlog'); const log = require('winston');
const MongoClient = require('mongodb').MongoClient; const MongoClient = require('mongodb').MongoClient;
/** /**

36
src/dao/papertrail.js Normal file
View File

@ -0,0 +1,36 @@
/**
* Mailvelope - secure email with OpenPGP encryption for Webmail
* Copyright (C) 2016 Mailvelope GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License version 3
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
'use strict';
const log = require('winston');
const config = require('config');
require('winston-papertrail');
log.exitOnError = false;
log.level = config.log.level;
exports.init = function({host, port}) {
if (!host || !port) {
return;
}
log.add(log.transports.Papertrail, {
level: config.log.level,
host,
port
});
};

View File

@ -17,7 +17,7 @@
'use strict'; 'use strict';
const log = require('npmlog'); const log = require('winston');
const util = require('../service/util'); const util = require('../service/util');
const nodemailer = require('nodemailer'); const nodemailer = require('nodemailer');
const openpgpEncrypt = require('nodemailer-openpgp').openpgpEncrypt; const openpgpEncrypt = require('nodemailer-openpgp').openpgpEncrypt;

View File

@ -17,7 +17,7 @@
'use strict'; 'use strict';
const log = require('npmlog'); const log = require('winston');
const config = require('config'); const config = require('config');
const init = require('./app'); const init = require('./app');

View File

@ -17,7 +17,7 @@
'use strict'; 'use strict';
const log = require('npmlog'); const log = require('winston');
const util = require('./util'); const util = require('./util');
const openpgp = require('openpgp'); const openpgp = require('openpgp');
const addressparser = require('addressparser'); const addressparser = require('addressparser');

View File

@ -5,7 +5,7 @@ const Mongo = require('../../src/dao/mongo');
const nodemailer = require('nodemailer'); const nodemailer = require('nodemailer');
const config = require('config'); const config = require('config');
const fs = require('fs'); const fs = require('fs');
const log = require('npmlog'); const log = require('winston');
describe('Koa App (HTTP Server) Integration Tests', function() { describe('Koa App (HTTP Server) Integration Tests', function() {
this.timeout(20000); this.timeout(20000);

View File

@ -1,6 +1,6 @@
'use strict'; 'use strict';
const log = require('npmlog'); const log = require('winston');
const config = require('config'); const config = require('config');
const Mongo = require('../../src/dao/mongo'); const Mongo = require('../../src/dao/mongo');

View File

@ -1,6 +1,6 @@
'use strict'; 'use strict';
const log = require('npmlog'); const log = require('winston');
const config = require('config'); const config = require('config');
const nodemailer = require('nodemailer'); const nodemailer = require('nodemailer');
const Email = require('../../src/email/email'); const Email = require('../../src/email/email');

View File

@ -1,6 +1,6 @@
'use strict'; 'use strict';
const log = require('npmlog'); const log = require('winston');
const Email = require('../../src/email/email'); const Email = require('../../src/email/email');
const nodemailer = require('nodemailer'); const nodemailer = require('nodemailer');

View File

@ -1,7 +1,7 @@
'use strict'; 'use strict';
const fs = require('fs'); const fs = require('fs');
const log = require('npmlog'); const log = require('winston');
const openpgp = require('openpgp'); const openpgp = require('openpgp');
const PGP = require('../../src/service/pgp'); const PGP = require('../../src/service/pgp');