<commit_before>var logger = require("lib/logger");
var app = require('express')();
var server = require('http').Server(app);
var io = require('socket.io')(server);
var path = require('path');

var PropertiesReader = require('properties-reader');

var express = require('express');
var compression = require('compression');
var serveIndex = require('serve-index'); // directory listings middleware
var _ = require('lodash');

var listFiles = require('./lib/helpers').listFiles;
var fileExists = require('./lib/helpers').exists;
var config = PropertiesReader('./conf/tailgate.ini');

var FileTail = require('./lib/FileTail.js');

var HashTable = require('hashtable');
var tails = new HashTable();
var clients = new HashTable();


// Configure Winston logging for Express
app.use(require('morgan')({ "stream": logger.stream }));

// Serving the client app
//
app.use('/', express.static(path.resolve(config.get('main.server.webroot'))));

// Setup static file serving and file browsing of the monitored folder
//
app.use('/tailfiles', express.static(path.resolve(config.get('disk.tail.dir'))));
app.use('/tailfiles', serveIndex(path.resolve(config.get('disk.tail.dir')), {'icons': true, view: 'details'}));
app.use(compression()); // Compress responses of all requests


// Setup websocket event handlers for connecting clients
//
io.on('connection', function (socket) {

    listFiles(config.get('disk.tail.dir'), function (err, files) {
        if (!err) {
            socket.emit('files', {files: files}); // Send available files to client
            console.log('a user connected id: ' + socket.id);
            //clients.put(socket.id, socket);
        }
    });

    socket.on('disconnect', function () {
        console.log('user disconnected');
        tails.forEach(function(fileName, fileTail) {
            fileTail.removeListener('change', clients.get(''+socket.id));
        });
        clients.remove(''+socket.id);
    });

    socket.on('tail', function (msg) {
        console.log('tail: ' + msg);
        if (_.has(msg, 'fileName') && fileExists(msg.fileName)) {
            if(tails.get(msg.fileName) == null)
                tails.put(msg.fileName, new FileTail(msg.fileName));

            var notifyClient = function notifyClient(data) {
                socket.emit('data', data);
            };

            clients.put(''+socket.id, notifyClient);
            tails.get(msg.fileName).on('change', notifyClient);
        }

    });
});

// Start the server
//
server.listen(config.get('main.server.port'), function () {
    console.log('Listening on *:' + config.get('main.server.port'));
    console.log('Client webroot: ' + path.resolve(config.get('main.server.webroot')));
    console.log('Tailing dir: ' + path.resolve(config.get('disk.tail.dir')));
});<commit_msg>Removed console logging<commit_after>var logger = require('./lib/logger.js');
var app = require('express')();
var server = require('http').Server(app);
var io = require('socket.io')(server);
var path = require('path');

var PropertiesReader = require('properties-reader');

var express = require('express');
var compression = require('compression');
var serveIndex = require('serve-index'); // directory listings middleware
var _ = require('lodash');

var listFiles = require('./lib/helpers').listFiles;
var fileExists = require('./lib/helpers').exists;
var config = PropertiesReader('./conf/tailgate.ini');

var FileTail = require('./lib/FileTail.js');

var HashTable = require('hashtable');
var tails = new HashTable();
var clients = new HashTable();

logger.info('Initializing server.');


// Configure Winston logging for Express
app.use(require('morgan')('combined',{ "stream": logger.stream }));

// Serving the client app
//
app.use('/', express.static(path.resolve(config.get('main.server.webroot'))));

// Setup static file serving and file browsing of the monitored folder
//
app.use('/tailfiles', express.static(path.resolve(config.get('disk.tail.dir'))));
app.use('/tailfiles', serveIndex(path.resolve(config.get('disk.tail.dir')), {'icons': true, view: 'details'}));
app.use(compression()); // Compress responses of all requests


// Setup websocket event handlers for connecting clients
//
io.on('connection', function (socket) {

    listFiles(config.get('disk.tail.dir'), function (err, files) {
        if (!err) {
            socket.emit('files', {files: files}); // Send available files to client
            logger.debug('a user connected id: ' + socket.id);
            //clients.put(socket.id, socket);
        }
    });

    socket.on('disconnect', function () {
        logger.debug('user disconnected');
        tails.forEach(function(fileName, fileTail) {
            fileTail.removeListener('change', clients.get(''+socket.id));
        });
        clients.remove(''+socket.id);
    });

    socket.on('tail', function (msg) {
        logger.debug('tail: ' + msg);
        if (_.has(msg, 'fileName') && fileExists(msg.fileName)) {
            if(tails.get(msg.fileName) == null)
                tails.put(msg.fileName, new FileTail(msg.fileName));

            var notifyClient = function notifyClient(data) {
                socket.emit('data', data);
            };

            clients.put(''+socket.id, notifyClient);
            tails.get(msg.fileName).on('change', notifyClient);
        }

    });
});

// Start the server
//
server.listen(config.get('main.server.port'), function () {
    logger.info('Listening on *:' + config.get('main.server.port'));
    logger.info('Client webroot: ' + path.resolve(config.get('main.server.webroot')));
    logger.info('Tailing dir: ' + path.resolve(config.get('disk.tail.dir')));
});
{'fraction_non_alphanumeric': 0.18115813706392775, 'fraction_numerical': 0.0, 'mean_word_length': 3.507581803671189, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '182726', 'n_tokens_mistral': 1652, 'n_tokens_neox': 1631, 'n_words': 348}