Skip to content
This repository has been archived by the owner on Jul 12, 2019. It is now read-only.

Commit

Permalink
Removed notifier from custom console logger
Browse files Browse the repository at this point in the history
  • Loading branch information
AnaghaMurtarkar committed Oct 12, 2018
1 parent 0bab7fb commit 05f164d
Showing 1 changed file with 4 additions and 70 deletions.
74 changes: 4 additions & 70 deletions helpers/custom_console_logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,77 +6,11 @@
* @module helpers/custom_console_logger
*/

const getNamespace = require('continuation-local-storage').getNamespace,
// Get common local storage namespace to read
// request identifiers for debugging and logging
openSTNotification = require('@openstfoundation/openst-notification'),
OSTBase = require('@openstfoundation/openst-base'),
requestNamespace = getNamespace('openST-Platform-NameSpace');

const rootPrefix = '..',
packageFile = require(rootPrefix + '/package.json');
// Get common local storage namespace to read
// request identifiers for debugging and logging
const OSTBase = require('@openstfoundation/openst-base');

const Logger = OSTBase.Logger,
loggerLevel = process.env.OST_DEBUG_ENABLED == '1' ? Logger.LOG_LEVELS.TRACE : Logger.LOG_LEVELS.INFO,
packageName = packageFile.name;

/**
* Method to convert Process hrTime to Milliseconds
*
* @param {number} hrTime - this is the time in hours
*
* @return {number} - returns time in milli seconds
*/
const timeInMilli = function(hrTime) {
return hrTime[0] * 1000 + hrTime[1] / 1000000;
};

/**
* Method to append Request in each log line.
*
* @param {string} message
*/
const appendRequest = function(message) {
var newMessage = '';
if (requestNamespace) {
if (requestNamespace.get('reqId')) {
newMessage += '[' + requestNamespace.get('reqId') + ']';
}
if (requestNamespace.get('workerId')) {
newMessage += '[Worker - ' + requestNamespace.get('workerId') + ']';
}
const hrTime = process.hrtime();
newMessage += '[' + timeInMilli(hrTime) + ']';
}
newMessage += message;
return newMessage;
};

Logger.prototype.notify = function(code, msg, data, backtrace) {
var args = [appendRequest(this.NOTE_PRE)];
args = args.concat(Array.prototype.slice.call(arguments));
args.push(this.CONSOLE_RESET);
console.log.apply(console, args);

var bodyData = null;

try {
bodyData = JSON.stringify(data);
} catch (err) {
bodyData = data;
}

openSTNotification.publishEvent.perform({
topics: ['email_error.' + packageName],
publisher: 'OST',
message: {
kind: 'email',
payload: {
subject: packageName + ' ::' + code,
body: ' Message: ' + msg + ' \n\n Data: ' + bodyData + ' \n\n backtrace: ' + backtrace
}
}
});
};
loggerLevel = process.env.OST_DEBUG_ENABLED == '1' ? Logger.LOG_LEVELS.TRACE : Logger.LOG_LEVELS.INFO;

module.exports = new Logger('openst-platform', loggerLevel);

0 comments on commit 05f164d

Please sign in to comment.