Skip to content
  • 2 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Showing with 43 additions and 1 deletion.
  1. +31 −0 lib/logger.coffee
  2. +12 −1 web.coffee
View
31 lib/logger.coffee
@@ -0,0 +1,31 @@
+coffee = require("coffee-script")
+
+class Logger
+
+ constructor: (@subject, @options={}) ->
+
+ write: (subject, options={}) ->
+ message = subject
+ message = "foo #{message} #{key}=\"#{val}\"" for key, val of options
+ console.log message
+
+ log: (opts={}, cb) ->
+ options = coffee.helpers.merge(@options, opts)
+ if cb?
+ logger = new Logger(@subject, options)
+ start = new Date().getTime()
+ write @subject, coffee.helpers.merge(options, start:start)
+ cb(logger.log)
+ finish = new Date().getTime()
+ elapsed = (finish - start)
+ write subject, coffee.helpers.merge(options, finish:finish, elapsed:elapsed)
+ else
+ write subject, options
+
+log = (subject, options={}) ->
+ message = subject
+ message = "#{message} #{key}=\"#{val}\"" for key, val of options
+ console.log message
+
+module.exports = (subject, options={}, cb=null) ->
+ new Logger(subject).log(options, cb)
View
13 web.coffee
@@ -7,8 +7,19 @@ manifest = require("manifest")
storage = require("storage").init()
util = require("util")
+express.logger.format "method", (req, res) ->
+ req.method.toLowerCase()
+
+express.logger.format "url", (req, res) ->
+ req.url.replace('"', '&quot')
+
+express.logger.format "user-agent", (req, res) ->
+ (req.headers["user-agent"] || "").replace('"', '')
+
app = express.createServer(
- express.logger(),
+ express.logger
+ buffer: false
+ format: "http method=\":method\" url=\":url\" status=\":status\" elapsed=\":response-time\" from=\":remote-addr\" agent=\":user-agent\""
express.bodyParser())
app.get "/", (req, res) ->

No commit comments for this range

Something went wrong with that request. Please try again.