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

                    callback()
            @readyCallbacks = []

module.exports =
    ServiceManager: ServiceManager
    Service: Service

            @port = port
            processName = "#{@serviceManager.config.dir}/#{@name}"
            @process = childProcess.spawn processName, [@port]
            @log 'starter', "running on #{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) =>
                @log 'stdout', data
                out.write data
            @process.stderr.on 'data', (data) =>
                @log 'stderr', data
                out.write data
            @process.on 'error', (error) =>
                @log 'error', error
                out.write "[poxy] encountered error: #{error}\n"

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