var Logger = require('../../../../lib/log/logger'),
    levels = Logger.levels;

exports['Format messages.'] = function (test) {
    var logger = new Logger;
    test.equal(logger._format(['A%sD', 'BC', 'EF']), 'ABCD');
    test.done();
};
exports['Decorate messages.'] = function (test) {
    var logger = new Logger;
    test.ok(logger._decorate('foo', 0));
    test.ok(logger._decorate('foo', 1));
    test.ok(logger._decorate('foo', 2));
    test.ok(logger._decorate('foo', 3));
    test.ok(logger._decorate('foo', 4));
    test.ok(logger._decorate('foo', 5));
    test.ok(logger._decorate('foo', 6));
    test.ok(logger._decorate('foo', 7));
    logger.color = null;
    test.ok(logger._decorate('foo', 8));
    test.done();
};
exports['Set log level by string.'] = function (test) {
    test.equal(new Logger(Logger.levels.FATAL).level(), new Logger('fatal').level());
    test.equal(new Logger(Logger.levels.FATAL).level(), new Logger('Fatal').level());
    test.equal(new Logger(Logger.levels.FATAL).level(), new Logger('FATAL').level());
    test.done();
};

exports['Log messages to the console'] = function (test) {
    var logger = new Logger(levels.TRACE);
    logger.console(false);
    logger.fatal('This is fatal');
    logger.error('This is error');
    logger.warn('This is warn');
    logger.info('This is info');
    logger.debug('This is debug');
    logger.trace('This is trace');
    logger.debug('This is invalid message %% %d %', 2);
    test.done()
};
exports['Ignore if higher.'] = function (test) {
    var logger = new Logger(levels.TRACE);
    logger._err = logger._log = function () {
        test.ifError(new Error('Should not log.'));
    };
    logger.level(levels.OFF);
    logger.fatal('foo');
    logger.level(levels.FATAL);
    logger.error('foo');
    logger.level(levels.ERROR);
    logger.warn('foo');
    logger.level(levels.WARN);
    logger.info('foo');
    logger.level(levels.INFO);
    logger.debug('foo');
    logger.level(levels.DEBUG);
    logger.trace('foo');
    logger.level(levels.TRACE);
    test.done();
};

exports['Print to console.'] = function (test) {
    var log = console.log, error = console.error;
    console.log = function () {

    };
    console.error = function () {

    };
    var logger = new Logger().console(true);
    logger._log('');
    logger._err('');

    console.log = log;
    console.error = error;
    test.done();
};