"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getSessionLog = void 0;
const Logger = require("bunyan");
const dirs = require("../lib/dirs");
const mkdirp = require("mkdirp");
const path = require("path");
const _ = require("underscore");
var appLog = Logger.createLogger({ name: 'app' });
var sessionLogs = {};
function getSessionLog(sessionId) {
    // Ensure the "logs" directory exists
    mkdirp.sync(path.join(dirs.workingDir(), 'logs'));
    let log;
    sessionId = sessionId.toString();
    if (!sessionLogs[sessionId]) {
        log = Logger.createLogger({
            name: sessionId,
            streams: [{
                    level: 'trace',
                    path: path.join(dirs.workingDir(), 'logs', sessionId + '.log')
                }]
        });
        sessionLogs[sessionId] = log;
    }
    else {
        log = sessionLogs[sessionId];
    }
    // Provide a method for clients to flush the write
    // stream to ensure all data was persisted 
    log.flushStreams = _.debounce(log.reopenFileStreams.bind(log), 5000, true);
    return log;
}
exports.getSessionLog = getSessionLog;
//# sourceMappingURL=log-manager.js.map