Permalink
Browse files

Initial commit

  • Loading branch information...
tj committed Sep 10, 2012
0 parents commit a83944659c3a8114aa6d3179f208b8f219b81e52
Showing with 143 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +4 −0 .npmignore
  3. +5 −0 History.md
  4. +7 −0 Makefile
  5. +55 −0 Readme.md
  6. +21 −0 example.js
  7. +37 −0 index.js
  8. +13 −0 package.json
@@ -0,0 +1 @@
+node_modules
@@ -0,0 +1,4 @@
+support
+test
+examples
+*.sock
@@ -0,0 +1,5 @@
+
+0.0.1 / 2010-01-03
+==================
+
+ * Initial release
@@ -0,0 +1,7 @@
+
+test:
+ @./node_modules/.bin/mocha \
+ --require should \
+ --reporter spec
+
+.PHONY: test
@@ -0,0 +1,55 @@
+
+# jog-middleware
+
+ jog json logger middleware for Connect / Express
+
+## Installation
+
+ $ npm install jog-middleware
+
+## Example
+
+```js
+var connect = require('connect');
+var logger = require('./index');
+var jog = require('jog');
+var log = jog(new jog.FileStore('/tmp/log'));
+

This comment has been minimized.

Show comment Hide comment
@drudge

drudge Sep 10, 2012

Where is FileStore defined?

@drudge

drudge Sep 10, 2012

Where is FileStore defined?

This comment has been minimized.

Show comment Hide comment
+var app = connect();
+
+app.use(logger(log));
+
+app.use(function(req, res){
+ res.statusCode = 200;
+ res.setHeader('Content-Type', 'application/json');
+ res.end(JSON.stringify({ message: 'Hello' }));
+});
+
+app.listen(3000);
+
+```
+
+## License
+
+(The MIT License)
+
+Copyright (c) 2012 TJ Holowaychuk <tj@vision-media.ca>
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,21 @@
+
+/**
+ * Module dependencies.
+ */
+
+var connect = require('connect');
+var logger = require('./index');
+var jog = require('jog');
+var log = jog(new jog.FileStore('/tmp/log'));
+
+var app = connect();
+
+app.use(logger(log));
+
+app.use(function(req, res){
+ res.statusCode = 200;
+ res.setHeader('Content-Type', 'application/json');
+ res.end(JSON.stringify({ message: 'Hello' }));
+});
+
+app.listen(3000);
@@ -0,0 +1,37 @@
+
+/**
+ * Log incoming requests and responses with the given `log` instance.
+ *
+ * @param {Object} log
+ * @return {Function}
+ * @api public
+ */
+
+module.exports = function(log){
+ var ids = 0;
+
+ return function(req, res, next){
+ var id = ids++;
+ var start = new Date;
+
+ log.info('request', {
+ url: req.url,
+ method: req.method,
+ header: req.headers,
+ id: id
+ });
+
+ res.on('finish', function(){
+ log.info('response', {
+ url: req.url,
+ method: req.method,
+ status: res.statusCode,
+ header: res._headers,
+ duration: new Date - start,
+ id: id
+ })
+ });
+
+ next();
+ }
+};
@@ -0,0 +1,13 @@
+{
+ "name": "jog-middleware",
+ "version": "0.0.1",
+ "description": "jog json logger middleware for Connect / Express",
+ "keywords": ["jog", "json", "logger", "logging", "connect", "express", "middleware"],
+ "author": "TJ Holowaychuk <tj@vision-media.ca>",
+ "dependencies": {},
+ "devDependencies": {
+ "mocha": "*",
+ "should": "*"
+ },
+ "main": "index"
+}

0 comments on commit a839446

Please sign in to comment.