Skip to content
This repository was archived by the owner on Apr 21, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@
"no-useless-constructor": "error",
"no-useless-rename": "error",
"no-useless-return": "error",
"no-var": "off",
"no-var": "error",
"no-void": "error",
"no-warning-comments": "error",
"no-whitespace-before-property": "error",
Expand Down
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
var logger = require('./lib/logger');
const logger = require('./lib/logger');

var __singleton;
let __singleton;

var setupDefaultLogger = function(key, opts) {
const setupDefaultLogger = function(key, opts) {
if (!(__singleton instanceof logger.Logger)) {
__singleton = logger.createLogger(key, opts);
}
Expand Down
11 changes: 5 additions & 6 deletions lib/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const validUrl = require('valid-url');
const configs = require('./configs');

// Variables
var loggers = [];
let loggers = [];

const isInt = (value) => !isNaN(value) && ((parseFloat(value) | 0) === parseFloat(value));

Expand All @@ -34,7 +34,7 @@ const checkStringParam = (param, name, optional) => {
};

const isValidTimestamp = (timestamp) => {
var valid = (new Date(timestamp)).getTime() > 0;
const valid = (new Date(timestamp)).getTime() > 0;
if (!valid || Math.abs(timestamp - Date.now()) > configs.MS_IN_A_DAY) {
debug('Error: The timestamp used is either invalid or not within one day. Date.now() will be used in its place.');
return false;
Expand Down Expand Up @@ -140,7 +140,7 @@ function Logger(key, options) {
, tags: options.tags || undefined
};

var useHttps = configs.AGENT_PROTOCOL === 'https';
const useHttps = configs.AGENT_PROTOCOL === 'https';

this._req = {
auth: { username: key }
Expand Down Expand Up @@ -170,7 +170,7 @@ Logger.prototype.log = function(statement, opts, callback) {
statement = stringify(statement, null, 2);
}

var message = {
const message = {
timestamp: Date.now()
, line: statement
, level: this.source.level
Expand Down Expand Up @@ -402,8 +402,7 @@ const flushAll = function(cb) {
exports.Logger = Logger;

exports.createLogger = function(key, options) {
var next = new Logger(key, options);
return next;
return new Logger(key, options);
};

exports.flushAll = flushAll;
Expand Down
81 changes: 39 additions & 42 deletions test/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ const testHelper = require('./testHelper');
const configs = require('../lib/configs');

// Variables
var logger = Logger.createLogger(testHelper.apikey, testHelper.options);
var testLength = testHelper.testLength;
var testStr = 'ESOTERIC ';
var sentMeta = [];
var body = '';
var testServer;
var testServer2;
const logger = Logger.createLogger(testHelper.apikey, testHelper.options);
const testLength = testHelper.testLength;
const testStr = 'ESOTERIC ';
let sentMeta = [];
let body = '';
let testServer;
let testServer2;

describe('Test all Levels', function() {
const allLevelsPort = 8080;
Expand All @@ -41,7 +41,7 @@ describe('Test all Levels', function() {
});
req.on('end', function() {
body = JSON.parse(body);
for (var i = 0; i < body.ls.length; i++) {
for (let i = 0; i < body.ls.length; i++) {
sentLines.push(body.ls[i].line);
sentLevels.push(body.ls[i].level);
}
Expand Down Expand Up @@ -161,20 +161,20 @@ describe('Testing for Correctness', function() {
let sentLines = [];
const ordered = [];

for (var i = 0; i < testLength; ++i) {
for (let i = 0; i < testLength; ++i) {
ordered.push(testStr);
}

const sendLogs = function() {
var rssProfile = [];
var base = process.memoryUsage().rss / 1000000.0;
const rssProfile = [];
const base = process.memoryUsage().rss / 1000000.0;
rssProfile.push(process.memoryUsage().rss / (1000000.0) - base);
var start = process.hrtime();
const start = process.hrtime();
for (let i = 0; i < testLength; ++i) {
correctnesLogger.log(testStr);
}
var elapsed = (process.hrtime(start)[0] * 1000) + process.hrtime(start)[1] / 1000000;
var throughput = testLength / (elapsed / 1000);
const elapsed = (process.hrtime(start)[0] * 1000) + process.hrtime(start)[1] / 1000000;
let throughput = testLength / (elapsed / 1000);
throughput = Math.round(throughput * 100) / 100;
console.log(' ********************\n Here\'s the throughput: %j lines/sec', throughput);
return delay(configs.FLUSH_INTERVAL + 200);
Expand All @@ -188,7 +188,7 @@ describe('Testing for Correctness', function() {
});
req.on('end', function() {
body = JSON.parse(body);
for (var i = 0; i < body.ls.length; i++) {
for (let i = 0; i < body.ls.length; i++) {
sentLines.push(body.ls[i].line);
}
res.end('Hello, world!\n');
Expand Down Expand Up @@ -226,7 +226,7 @@ describe('Index meta', function() {
});
req.on('end', function() {
body = JSON.parse(body);
for (var i = 0; i < body.ls.length; i++) {
for (let i = 0; i < body.ls.length; i++) {
sentMeta.push(body.ls[i].meta);
}
body = '';
Expand All @@ -253,8 +253,8 @@ describe('Index meta', function() {
}, configs.FLUSH_INTERVAL + 200);
});
it('Index meta if specified in logger options', function(done) {
var opts = { index_meta: true, ...testHelper.options};
var indexMetaLogger = Logger.createLogger(testHelper.apikey, opts);
const opts = { index_meta: true, ...testHelper.options};
const indexMetaLogger = Logger.createLogger(testHelper.apikey, opts);

indexMetaLogger.debug('Sent a log', { meta: { extra_info: 'extra info' }});
setTimeout(function() {
Expand All @@ -273,8 +273,8 @@ describe('Index meta', function() {
}, configs.FLUSH_INTERVAL + 200);
});
it('Doesn\'t index meta if specified in message even if logger option is true', function(done) {
var opts = { index_meta: true, ...testHelper.options};
var indexMetaLogger = Logger.createLogger(testHelper.apikey, opts);
const opts = { index_meta: true, ...testHelper.options};
const indexMetaLogger = Logger.createLogger(testHelper.apikey, opts);

indexMetaLogger.debug('Sent a log', {
index_meta: false
Expand All @@ -288,30 +288,23 @@ describe('Index meta', function() {
});

describe('Input validation', function() {
var bogusKeys;
var options;
var noOptions;
beforeEach(function() {
bogusKeys = [
afterEach(function(done) {
Logger.flushAll(done);
});
it('Sanity checks for Ingestion Key', function(done) {
const bogusKeys = [
'THIS KEY IS TOO LONG THIS KEY IS TOO LONG THIS KEY IS TOO LONG THIS KEY IS TOO LONG THIS KEY IS TOO LONG THIS KEY IS TOO LONG'
, 1234
, { key: 'fail fail' }
, 12.123
];
options = {

const options = {
hostname: 'Valid Hostname'
, mac: 'C0:FF:EE:C0:FF:EE'
, ip: '10.0.1.101'
};
noOptions = {
status: 'ok'
};
});
afterEach(function(done) {
Logger.flushAll(done);
});
it('Sanity checks for Ingestion Key', function(done) {
for (var i = 0; i < bogusKeys.length; i++) {
for (let i = 0; i < bogusKeys.length; i++) {
assert.throws(function() { Logger.createLogger(bogusKeys[i], options); }, Error, 'Invalid Keys');
}
done();
Expand All @@ -337,6 +330,9 @@ describe('Input validation', function() {
done();
});
it('Sanity checks for no options', function(done) {
const noOptions = {
status: 'ok'
};
assert(Logger.createLogger(testHelper.apikey, noOptions));
done();
});
Expand All @@ -348,19 +344,20 @@ describe('Input validation', function() {
});

describe('Multiple loggers', function() {
var logger1 = Logger.createLogger(testHelper.apikey3, testHelper.options3);
var logger2 = Logger.createLogger(testHelper.apikey2, testHelper.options2);
var sentLines1 = [];
var sentLines2 = [];
const logger1 = Logger.createLogger(testHelper.apikey3, testHelper.options3);
const logger2 = Logger.createLogger(testHelper.apikey2, testHelper.options2);
let sentLines1 = [];
let sentLines2 = [];
let testServer3;

beforeEach(function(done) {
testServer3 = http.createServer(function(req, res) {
req.on('data', function(data) {
body += data;
});
req.on('end', function() {
body = JSON.parse(body);
for (var i = 0; i < body.ls.length; i++) {
for (let i = 0; i < body.ls.length; i++) {
sentLines1.push(body.ls[i].line);
}
body = '';
Expand All @@ -374,7 +371,7 @@ describe('Multiple loggers', function() {
});
req.on('end', function() {
body = JSON.parse(body);
for (var i = 0; i < body.ls.length; i++) {
for (let i = 0; i < body.ls.length; i++) {
sentLines2.push(body.ls[i].line);
}
body = '';
Expand Down Expand Up @@ -667,7 +664,7 @@ describe('Test shimProperties which support customized properties in log', funct
});
req.on('end', function() {
body = JSON.parse(body);
for (var i = 0; i < body.ls.length; i++) {
for (let i = 0; i < body.ls.length; i++) {
sentMessages.push(body.ls[i]);
}
body = '';
Expand Down
8 changes: 4 additions & 4 deletions test/testHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ module.exports = {
};

module.exports.memoryChecker = function(func) {
var m1 = process.memoryUsage();
const m1 = process.memoryUsage();

console.time(' sendLogz');
var p = func();
const p = func();
console.timeEnd(' sendLogz');
var m2 = process.memoryUsage();
const m2 = process.memoryUsage();
console.log(' Diff (MB) = rss: %j, heapTotal: %j, heapUsed: %j \n', (m2.rss - m1.rss) / 1000000, (m2.heapTotal - m1.heapTotal) / 1000000, (m2.heapUsed - m1.heapUsed) / 1000000);
return p;
};
Expand All @@ -83,7 +83,7 @@ module.exports.arraysEqual = function(a, b) {
if (a === b) return true;
if (a == null || b == null) return false;
if (a.length !== b.length) return false;
for (var i = 0; i < a.length; ++i) {
for (let i = 0; i < a.length; ++i) {
if (a[i] !== b[i]) {
console.log('FAIL a: %j, b: %j', a[i], b[i]);
return false;
Expand Down