-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 16ad6c5
Showing
3 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
*.swp | ||
*.swo |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// See also: <https://github.com/darwin/firelogger/wiki> | ||
module.exports = function (options) { | ||
|
||
options = options || {}; | ||
var levels = options.levels || | ||
['debug', 'info', 'warning', 'error', 'critical']; | ||
|
||
return function (req, res, mw_next) { | ||
var messages = [], | ||
orig_writeHead = res.writeHead; | ||
|
||
res.log = function (data) { | ||
var now = new Date(); | ||
data = data || {}; | ||
data.time = now.toTimeString(); | ||
data.timestamp = now.getTime() * 1000; | ||
messages.push(data); | ||
}; | ||
|
||
levels.forEach(function (level) { | ||
res.log[level] = function (msg, data) { | ||
data = data || {}; | ||
data.level = level; | ||
data.message = msg; | ||
res.log(data); | ||
}; | ||
}); | ||
|
||
res.writeHead = function (status, headers) { | ||
|
||
function wh_next() { | ||
res.writeHead = orig_writeHead; | ||
res.writeHead(status, headers); | ||
} | ||
|
||
var fl_ver = req.header('X-FireLogger'); | ||
if (!fl_ver) { return wh_next(); } | ||
|
||
var d_logs = { logs: messages }, | ||
d_json = JSON.stringify(d_logs), | ||
d_b64 = (new Buffer(d_json, 'utf-8')).toString('base64'), | ||
d_lines = d_b64.match(/(.{1,75})/g), | ||
uid = parseInt(Math.random() * 1000000, 16); | ||
|
||
for (var i=0; i<d_lines.length; i++) { | ||
res.header('FireLogger-' + uid + '-' + i, d_lines[i]); | ||
} | ||
|
||
wh_next(); | ||
}; | ||
|
||
mw_next(); | ||
}; | ||
|
||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"author": "Les Orchard <me@lmorchard.com> (http://lmorchard.com/)", | ||
"name": "firelogger", | ||
"description": "Middleware for express/connect that supports the FireLogger protocol", | ||
"version": "0.0.1", | ||
"homepage": "http://github.com/lmorchard/node-firelogger/", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/lmorchard/node-firelogger.git" | ||
}, | ||
"main": "firelogger.js", | ||
"engines": { | ||
"node": "~0.6.10" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": {} | ||
} |