Comparing version 0.5.2 to 0.5.3
@@ -11,5 +11,9 @@ # Change log | ||
#### Bug Fix: remote logging now supports cluster. | ||
Refer to github commit log: https://github.com/voltrue2/gracelog/commit/3280a91e71ac292b3887c3a0b564b776278aa78a | ||
#### Bug Fix: remote logging was broken | ||
Refer to github commit log:7bd47c92d1afb332869c7ae3f72d1656e6971ccf | ||
Refer to github commit log: https://github.com/voltrue2/gracelog/commit/549bf4113170f18fd68d6a0c1515472e758a16ac | ||
@@ -16,0 +20,0 @@ ## Deprecated |
@@ -0,1 +1,2 @@ | ||
var async = require('async'); | ||
var dgram = require('dgram'); | ||
@@ -5,5 +6,6 @@ | ||
var address = null; | ||
var config = null; | ||
var client; | ||
module.exports.setup = function (configIn) { | ||
@@ -16,35 +18,20 @@ | ||
address = ip.get(); | ||
if (!configIn.port || !configIn.host) { | ||
console.error('Error: missing remoteServer configurations'); | ||
console.error(configIn); | ||
return; | ||
} | ||
config = configIn; | ||
client = dgram.createSocket('udp4'); | ||
}; | ||
// cb is optional for auto buffer flushing | ||
module.exports.log = function (levelName, msg, cb) { | ||
// check config | ||
if (!config || !config.port || !config.host) { | ||
console.error('Error: missing remoteServer configurations'); | ||
console.error(config); | ||
return; | ||
} | ||
var data = { | ||
address: address, | ||
name: levelName, | ||
message: msg, | ||
}; | ||
data = new Buffer(JSON.stringify(data)); | ||
// set up UDP sender | ||
var client = dgram.createSocket('udp4'); | ||
var offset = 0; | ||
// send | ||
client.send(data, offset, data.length, config.port, config.host, function (error) { | ||
if (error) { | ||
console.error(error); | ||
} | ||
// close socket | ||
client.close(); | ||
if (cb) { | ||
cb(); | ||
} | ||
}); | ||
module.exports.log = function (levelName, msgData, cb) { | ||
async.forEach(msgData, function (item, next) { | ||
client.send(item.msg, 0, item.msg.length, config.port, config.host, next); | ||
}, cb || function () {}); | ||
}; | ||
{ | ||
"name": "gracelog", | ||
"description": "Log management module", | ||
"version": "0.5.2", | ||
"version": "0.5.3", | ||
"author": "Nobuyori Takahashi <voltrue2@yahoo.com>", | ||
@@ -6,0 +6,0 @@ "repository": { |
46192
1008