+fs = require "fs"
+spawn = require('child_process').spawn
 connect = require "connect"
+
+config = require './config'
+
 app = connect.createServer(connect.static('public')).listen(9099)
-
-io = require("socket.io").listen(app)
+io = require("socket.io").listen app
 io.set 'log level', 2 # disable heartbeat debug output
 
-fs = require "fs"
-config = require './config'
-spawn = require('child_process').spawn
 
 commands = []
 
+# Send data to connected client.
 sendData = (socket, data, fileName, fileSlug, channel) ->
     data = "#{data}"
     socket.emit 'new-data',


    commands[fileName] = command

io.sockets.on "connection", (socket) ->

    fs.readdir config.logPath, (err, files) ->

        'channel': channel
        'value': data.replace /(\[[0-9]+m)*/g, ""


# Stop given commands by sending them a SIGTERM signal.
killCommands = (commands) ->
    for fileName, command of commands
        console.log "Killing process for #{fileName}..."
        command.kill 'SIGTERM'


# Start process run a tail -f command on given file and redirect output to
# given socket.
startProcess = (socket, fileName) ->

    args = ['-f', "#{config.logPath}/#{fileName}"]
