                     callback()
             @readyCallbacks = []
 
+    log: (feature, msg) ->
+        console.log "[#{@name} #{feature}] #{msg}"
+
 module.exports =
     ServiceManager: ServiceManager
     Service: Service

            @port = port
            processName = "#{@serviceManager.config.dir}/#{@name}"
            @process = childProcess.spawn processName, [@port]
            console.log "#{@name}: running on port #{port}, PID #{@process.pid}"

            # Redirect stdout and stderr to a file
            out = fs.createWriteStream path.join(@serviceManager.config.logdir, @name), {flags: 'a', encoding: 'utf8'}
            @process.stdout.on 'data', (data) =>
                console.log "#{@name} stdout: #{data}"
                out.write data
            @process.stderr.on 'data', (data) =>
                console.log "#{@name} stderr: #{data}"
                out.write data
            @process.on 'error', (error) =>
                console.log "#{@name} error: #{error}"
                out.write "[poxy] encountered error: #{error}\n"

            # handle the server closing down
            @process.on 'close', (code, signal) =>
                console.log "#{@name}: stopped, code #{code}, signal #{signal}"
                @port = null
                @process = null
                @state 'stopped'

        # Keeps track of state and runs certain state-transition tasks
        oldState = @__state
        if not newState?
            return oldState
        if newState not in ['stopped', 'starting', 'running']
            throw new Error("Invalid state #{newState}")
        @log 'state', "#{oldState} -> #{newState}"
        @__state = newState

        # state-transition tasks
