Skip to content
Open
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
56 changes: 26 additions & 30 deletions lib/loggly/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
var arrSize = 100,
arrMsg = [],
timerFunction = null,
sendBulkInMs = 5000;
sendBulkInMs = 5000,
maxSerializeDepth = 10;

//
// Variables for buffer array
Expand Down Expand Up @@ -384,7 +385,7 @@ common.loggly = function () {
// Performs simple comma-separated, `key=value` serialization for Loggly when
// logging for non-JSON values.
//
common.serialize = function (obj, key) {
common.serialize = function (obj, key, depth) {
if (obj === null) {
obj = 'null';
}
Expand All @@ -395,6 +396,13 @@ common.serialize = function (obj, key) {
obj = 'false';
}

if (typeof depth === 'number') {
depth++;
}
else {
depth = 1;
}

if (typeof obj !== 'object') {
return key ? key + '=' + obj : obj;
}
Expand All @@ -403,22 +411,24 @@ common.serialize = function (obj, key) {
keys = Object.keys(obj),
length = keys.length;

for (var i = 0; i < length; i++) {
if (Array.isArray(obj[keys[i]])) {
msg += keys[i] + '=[';

for (var j = 0, l = obj[keys[i]].length; j < l; j++) {
msg += common.serialize(obj[keys[i]][j]);
if (j < l - 1) {
msg += ', ';
if (depth < maxSerializeDepth) {
for (var i = 0; i < length; i++) {
if (Array.isArray(obj[keys[i]])) {
msg += keys[i] + '=[';

for (var j = 0, l = obj[keys[i]].length; j < l; j++) {
msg += common.serialize(obj[keys[i]][j], depth);
if (j < l - 1) {
msg += ', ';
}
}

msg += ']';
}

msg += ']';
}
else {
msg += common.serialize(obj[keys[i]], keys[i]);
}
else {
msg += common.serialize(obj[keys[i]], keys[i], depth);
}
}

if (i < length - 1) {
msg += ', ';
Expand All @@ -427,17 +437,3 @@ common.serialize = function (obj, key) {

return msg;
};

//
// function clone (obj)
// Helper method for deep cloning pure JSON objects
// i.e. JSON objects that are either literals or objects (no Arrays, etc)
//
common.clone = function (obj) {
var clone = {};
for (var i in obj) {
clone[i] = obj[i] instanceof Object ? common.clone(obj[i]) : obj[i];
}

return clone;
};