"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
let assert = require('assert');
const logger_1 = require("../logger");
const utils_1 = require("../utils");
const settings_1 = require("../settings");
let config = {
    outputFile: "output",
    errorFile: "errors",
    logFolder: "logs",
    rotatingSize: "1M",
    logLevel: logger_1.default.LOG_LEVEL.DEBUG,
    debugLogging: false
};
class CustomLogger extends logger_1.default {
    outputWrite(write) {
        this.outputStream.write = write;
    }
    errorWrite(write) {
        this.errorStream.write = write;
    }
}
describe('test logger', function () {
    let oldLog;
    let oldConf;
    beforeEach(function () {
        oldLog = console.log;
        oldConf = utils_1.default.deepExtend({}, config);
    });
    afterEach(function () {
        console.log = oldLog;
        config = utils_1.default.deepExtend({}, oldConf);
    });
    it('general log', function (done) {
        settings_1.default.Instance.setLogger("test", config);
        let logger = new CustomLogger("test");
        logger.outputWrite(function (str) {
            assert.notEqual(str.indexOf("[DEBUG]"), -1);
            assert.notEqual(str.indexOf("message"), -1);
            done();
            return true;
        });
        logger.errorWrite(function (str) {
            done("no need to log in error file");
            return true;
        });
        logger.log("message", logger_1.default.LOG_LEVEL.DEBUG);
    });
    it('error log', function (done) {
        config.logLevel = 0; //error need to log always
        settings_1.default.Instance.setLogger("test", config);
        let logger = new CustomLogger("test");
        logger.errorWrite(function (str) {
            assert.notEqual(str.indexOf("[ERROR]"), -1);
            assert.notEqual(str.indexOf("message"), -1);
            done();
            return true;
        });
        logger.outputWrite(function (str) {
            done("no need to log in output file");
            return true;
        });
        logger.log("message", logger_1.default.LOG_LEVEL.ERROR);
    });
    it('debug log', function (done) {
        console.log = function (str) {
            console.log = oldLog;
            assert.notEqual(str.indexOf("[DEBUG]"), -1);
            assert.notEqual(str.indexOf("message"), -1);
            done();
        };
        config.debugLogging = true;
        settings_1.default.Instance.setLogger("test", config);
        let logger = new CustomLogger("test");
        logger.outputWrite(function (str) {
            done("no need to log in output file");
            return true;
        });
        logger.errorWrite(function (str) {
            done("no need to log in error file");
            return true;
        });
        logger.log("message", logger_1.default.LOG_LEVEL.DEBUG);
    });
});
//# sourceMappingURL=test-logger.js.map