Comparing version 0.3.6 to 0.3.8
@@ -15,2 +15,3 @@ /* | ||
loggly.createClient = require('./loggly/core').createClient; | ||
loggly.serialize = require('./loggly/common').serialize; | ||
loggly.Loggly = require('./loggly/core').Loggly; | ||
@@ -17,0 +18,0 @@ loggly.Config = require('./loggly/config').Config; |
@@ -9,3 +9,4 @@ /* | ||
var request = require('request'), | ||
var util = require('util'), | ||
request = require('request'), | ||
loggly = require('../loggly'); | ||
@@ -142,2 +143,53 @@ | ||
// | ||
// ### function serialize (obj, key) | ||
// #### @obj {Object|literal} Object to serialize | ||
// #### @key {string} **Optional** Optional key represented by obj in a larger object | ||
// Performs simple comma-separated, `key=value` serialization for Loggly when | ||
// logging to non-JSON inputs. | ||
// | ||
common.serialize = function (obj, key) { | ||
if (obj === null) { | ||
obj = 'null'; | ||
} | ||
else if (obj === undefined) { | ||
obj = 'undefined'; | ||
} | ||
else if (obj === false) { | ||
obj = 'false'; | ||
} | ||
if (typeof obj !== 'object') { | ||
return key ? key + '=' + obj : obj; | ||
} | ||
var msg = '', | ||
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 += ', '; | ||
} | ||
} | ||
msg += ']'; | ||
} | ||
else { | ||
msg += common.serialize(obj[keys[i]], keys[i]); | ||
} | ||
if (i < length - 1) { | ||
msg += ', '; | ||
} | ||
} | ||
return msg; | ||
}; | ||
// | ||
// function clone (obj) | ||
@@ -144,0 +196,0 @@ // Helper method for deep cloning pure JSON objects |
@@ -42,4 +42,5 @@ /* | ||
if (msg instanceof Object) { | ||
message = this.config.json ? JSON.stringify(msg) : qs.unescape(qs.stringify(msg, ',')); | ||
} else { | ||
message = this.config.json ? JSON.stringify(msg) : common.serialize(msg); | ||
} | ||
else { | ||
message = this.config.json ? JSON.stringify({ message : msg }) : msg; | ||
@@ -46,0 +47,0 @@ } |
{ | ||
"name": "loggly", | ||
"description": "A client implementation for Loggly cloud Logging-as-a-Service API", | ||
"version": "0.3.6", | ||
"version": "0.3.8", | ||
"author": "Charlie Robbins <charlie.robbins@gmail.com>", | ||
@@ -6,0 +6,0 @@ "contributors": [ |
153536
1298