   close: ->
     @server.close()
 
+  createApplicationPool: (config) ->
+    pool = createPool config, size: 3, idle: idle
+
+    pool.on 'spawn', () ->
+      logStream pool.stdout
+      logStream pool.stderr
+
+    pool
+
   applicationForConfig: (config) ->
-    @applications[config] ?= nack.createPool config, size: 3, idle: idle
+    if config
+      @applications[config] ?= @createApplicationPool config
 
   onRequest: (req, res) ->
     reqBuf = new BufferedReadStream req

    @configuration.findPathForHost host, (path) =>
      if app = @applicationForConfig path
        app.proxyRequest reqBuf, res
        reqBuf.flush()
      else
        @respondWithError res, "unknown host #{req.headers.host}"

  respondWithError: (res, err) ->
    res.writeHead 500, "Content-Type": "text/html"

http = require 'http'

{createPool}         = require 'nack/pool'
{logStream}          = require 'nack/logger'
{BufferedReadStream} = require 'nack/buffered'

idle = 1000 * 60 * 15
