Skip to content

Commit

Permalink
tidy log service
Browse files Browse the repository at this point in the history
  • Loading branch information
nomilous committed Sep 11, 2017
1 parent a3d7098 commit 6c38e61
Showing 1 changed file with 31 additions and 29 deletions.
60 changes: 31 additions & 29 deletions lib/services/log/service.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,21 @@
module.exports = LogService;

var util = require('util'),
Promise = require('bluebird'),
Logger = require('happn-logger'),
CONSTANTS = require('../../constants');

module.exports = LogService;

function LogService() {

}

LogService.prototype.processMessage = Promise.promisify(function (message, callback) {
try {

return callback(null, message);

} catch (e) {
callback(e);
}
});

LogService.prototype.stats = function () {
return this.__stats;
};
LogService.prototype.initialize = initialize;
LogService.prototype.error = Promise.promisify(error);
LogService.prototype.info = Promise.promisify(info);
LogService.prototype.warn = Promise.promisify(warn);
LogService.prototype.write = Promise.promisify(write);
LogService.prototype.processMessage = Promise.promisify(processMessage);
LogService.prototype.stats = stats;

LogService.prototype.initialize = function (config, callback) {
function LogService() {}

function initialize(config, callback) {
this.__stats = {
errors: {

Expand All @@ -38,20 +29,19 @@ LogService.prototype.initialize = function (config, callback) {
callback();
};

LogService.prototype.error = Promise.promisify(function (message, data, area, callback) {
function error(message, data, area, callback) {
return this.write(message, 'error', data, area, callback);
});
};

LogService.prototype.info = Promise.promisify(function (message, data, area, callback) {
function info(message, data, area, callback) {
return this.write(message, 'info', data, area);
});
};

LogService.prototype.warn = Promise.promisify(function (message, data, area, callback) {
function warn(message, data, area, callback) {
return this.write(message, 'warn', data, area);
});

LogService.prototype.write = Promise.promisify(function (message, type, data, area, severity, callback) {
};

function write(message, type, data, area, severity, callback) {
if (!area) area = 'System';

if (!type) type = 'info';
Expand All @@ -77,4 +67,16 @@ LogService.prototype.write = Promise.promisify(function (message, type, data, ar
this.__logs[area][type](message, data);

if (callback) return callback();
});
};

function processMessage(message, callback) {
try {
return callback(null, message);
} catch (e) {
callback(e);
}
};

function stats() {
return this.__stats;
};

0 comments on commit 6c38e61

Please sign in to comment.