Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 148fa03

Browse files
committed
Revert "Update logging."
This reverts commit 1ab0857.
1 parent ecc0f5b commit 148fa03

File tree

5 files changed

+7
-102
lines changed

5 files changed

+7
-102
lines changed

app.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010
'use strict';
1111
const express = require('express');
12+
// const logger = require('morgan');
1213
const cookieParser = require('cookie-parser');
1314
const bodyParser = require('body-parser');
1415
const healthcheck = require('topcoder-healthcheck-dropin');
@@ -60,16 +61,20 @@ app.use((err, req, res, next) => { // eslint-disable-line no-unused-vars
6061
});
6162

6263
process.on('uncaughtException', (err) => {
64+
// logger.error('Exception: ', err);
6365
// Check if error related to Dynamodb conn
6466
if (err.code === 'NetworkingError' && err.region) {
6567
logger.error('DynamoDB connection failed.');
6668
}
6769
logger.logFullError(err, 'system');
70+
// console.log(err);
6871
});
6972

7073
// handle and log unhanled rejection
7174
process.on('unhandledRejection', (err) => {
75+
// logger.error('Rejection: ', err);
7276
logger.logFullError(err, 'system');
77+
// console.log(err);
7378
});
7479

7580
module.exports = app;

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@
1616
"debug": "^2.6.9",
1717
"dynamoose": "^1.1.0",
1818
"express": "^4.17.1",
19-
"get-parameter-names": "^0.3.0",
20-
"global-request-logger": "^0.1.1",
2119
"joi": "^11.4.0",
20+
"morgan": "^1.9.1",
2221
"no-kafka": "^3.4.3",
2322
"topcoder-healthcheck-dropin": "^1.0.3",
24-
"winston": "^2.4.3"
23+
"winston": "^2.4.2"
2524
},
2625
"devDependencies": {
2726
"eslint-config-topcoder": "^2.0.0",

utils/GithubEventDetector.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ const Joi = require('joi');
1515
const _ = require('lodash');
1616

1717
const models = require('../models');
18-
const logger = require('./logger');
1918
const EventDetector = require('./EventDetector');
2019

2120
/**
@@ -241,5 +240,3 @@ module.exports = new EventDetector('github', [
241240
PullRequestCreatedEvent,
242241
PullRequestClosedEvent
243242
]);
244-
245-
logger.buildService(module.exports);

utils/GitlabEventDetector.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ const Joi = require('joi');
1414
const _ = require('lodash');
1515

1616
const models = require('../models');
17-
const logger = require('./logger');
1817
const EventDetector = require('./EventDetector');
1918

2019
/**
@@ -273,5 +272,3 @@ module.exports = new EventDetector('gitlab', [
273272
PullRequestCreatedEvent,
274273
PullRequestClosedEvent
275274
]);
276-
277-
logger.buildService(module.exports);

utils/logger.js

Lines changed: 0 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@
1010
*/
1111
'use strict';
1212
const config = require('config');
13-
const util = require('util');
14-
const _ = require('lodash');
1513
const winston = require('winston');
16-
const getParams = require('get-parameter-names');
17-
const globalLog = require('global-request-logger');
1814

1915
const logger = new winston.Logger({
2016
transports: [
@@ -37,94 +33,5 @@ logger.logFullError = function logFullError(err, signature) {
3733
err.logged = true;
3834
};
3935

40-
/**
41-
* Remove invalid properties from the object and hide long arrays
42-
* @param {Object} obj the object
43-
* @returns {Object} the new object with removed properties
44-
* @private
45-
*/
46-
function sanitizeObject(obj) {
47-
try {
48-
return JSON.parse(JSON.stringify(obj, (name, value) => {
49-
// Array of field names that should not be logged
50-
const removeFields = ['refreshToken', 'accessToken', 'access_token', 'authorization'];
51-
if (_.includes(removeFields, name)) {
52-
return '<removed>';
53-
}
54-
if (_.isArray(value) && value.length > 30) { // eslint-disable-line
55-
return `Array(${value.length}`;
56-
}
57-
return value;
58-
}));
59-
} catch (e) {
60-
return obj;
61-
}
62-
}
63-
64-
/**
65-
* Convert array with arguments to object
66-
* @param {Array} params the name of parameters
67-
* @param {Array} arr the array with values
68-
* @returns {Object} converted object
69-
* @private
70-
*/
71-
function combineObject(params, arr) {
72-
const ret = {};
73-
_.forEach(arr, (arg, i) => {
74-
ret[params[i]] = arg;
75-
});
76-
return ret;
77-
}
78-
79-
/**
80-
* Decorate all functions of a service and log debug information if DEBUG is enabled
81-
* @param {Object} service the service
82-
*/
83-
logger.decorateWithLogging = function decorateWithLogging(service) {
84-
if (config.LOG_LEVEL !== 'debug') {
85-
return;
86-
}
87-
_.forEach(service, (method, name) => {
88-
const params = method.params || getParams(method);
89-
service[name] = async function serviceMethodWithLogging() {
90-
logger.debug(`ENTER ${name}`);
91-
logger.debug('input arguments');
92-
const args = Array.prototype.slice.call(arguments); // eslint-disable-line
93-
logger.debug(util.inspect(sanitizeObject(combineObject(params, args))));
94-
try {
95-
const result = await method.apply(this, arguments); // eslint-disable-line
96-
logger.debug(`EXIT ${name}`);
97-
logger.debug('output arguments');
98-
logger.debug(util.inspect(sanitizeObject(result)));
99-
return result;
100-
} catch (e) {
101-
logger.logFullError(e, name);
102-
throw e;
103-
}
104-
};
105-
});
106-
};
107-
108-
/**
109-
* Apply logger and validation decorators
110-
* @param {Object} service the service to wrap
111-
*/
112-
logger.buildService = function buildService(service) {
113-
logger.decorateWithLogging(service);
114-
};
115-
116-
// globalLog.initialize();
117-
118-
// global any http success request interceptor
119-
globalLog.on('success', (request, response) => {
120-
logger.debug('Request', util.inspect(sanitizeObject(request)));
121-
logger.debug('Response', util.inspect(sanitizeObject(response)));
122-
});
123-
124-
// global any http error request interceptor
125-
globalLog.on('error', (request, response) => {
126-
logger.error('Request', util.inspect(sanitizeObject(request)));
127-
logger.error('Response', util.inspect(sanitizeObject(response)));
128-
});
12936

13037
module.exports = logger;

0 commit comments

Comments
 (0)