Created
October 17, 2012 00:30
-
-
Save ephekt/3903011 to your computer and use it in GitHub Desktop.
loggly nodejs code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = require('http'), | |
director = require('director'), | |
loggly = require('loggly'); | |
var loggly_client = loggly.createClient({ | |
subdomain: "delphi", | |
json: true | |
}); | |
var send_to_loggly = function(json_package) { | |
loggly_client.log('d5843569-aad0-49b3-9994-384549783147', json_package, function (err, result) { | |
if(err) { | |
console.log(err); | |
console.log(result); | |
} | |
}); | |
} | |
var router = new director.http.Router({ | |
'/add_log': { | |
post: function () { | |
send_to_loggly(this.req.body); | |
this.res.writeHead(200, { 'Content-Type': 'application/json' }); | |
this.res.end(); | |
} | |
} | |
}); | |
var server = http.createServer(function (req, res) { | |
req.chunks = []; | |
req.on('data', function (chunk) { | |
req.chunks.push(chunk.toString()); | |
}); | |
router.dispatch(req, res, function (err) { | |
if (err) { | |
console.log(err); | |
res.writeHead(err.status, { 'Content-Type': 'application/json' }); | |
res.end(JSON.stringify(err)); | |
} | |
}); | |
}); | |
server.on('error',function(error){ | |
send_to_loggly({'application':'miyagi','error':error}); | |
console.log('Error caught in createServer: '+error); | |
}); | |
server.listen('9090','localhost'); | |
console.log('Server running at http://127.0.0.1:9090/'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment