Files
elasticsearch-js/test/unit/test_stdio_logger.js
Spencer Alger 37cd2f4f6c Summary of changes:
- updated copyright
 - several tempalate changes for the docs
 - added a config for grunt-contrib-watch
 - updated nock commit number
 - fixed the coverage script
 - removed the export_docs script
 - added error message for legacy "es" users who don't have a version locked and have not upgraded
 - host will now add auth to urls created with `#makeUrl()`
 - Log class no longer looks for `config.loggers`
 - The log class now properly escapes single quotes in trace logs
 - Removed compiled yaml_tests.js from the repo
 - Yaml suite will only log error and warning messages unless the VERBOSE env var is set
 - createDefer is now a global setting, changed by modifying Transport.createDefer fubction
 - wrote tests for Content-Type checking
 - callbacks will now return the body and status of the request (if the request has completed) when an error occurs
 - Stdio logger now adds "Elasticsearch " to the front of log messages to distinguish it from other output to stdout.
2013-12-15 14:12:39 -07:00

69 lines
1.8 KiB
JavaScript

var Log = require('../../src/lib/log');
var StdioLogger = require('../../src/lib/loggers/stdio');
var sinon = require('sinon');
var parentLog;
beforeEach(function () {
parentLog = new Log();
});
afterEach(function () {
parentLog.close();
});
function makeLogger(parent, levels) {
parent = parent || parentLog;
var config = {
levels: Log.parseLevels(levels || 'trace')
};
return new StdioLogger(parent, config);
}
var stub = require('./auto_release_stub').make();
describe('Stdio Logger', function () {
require('./generic_logger_tests')(makeLogger);
describe('colorizing', function () {
var chalk = require('chalk');
var now = '2013-01-01T00:00:00Z';
var nowDate = new Date(now);
var nowTime = nowDate.getTime();
var clock;
beforeEach(function () {
stub.autoRelease(sinon.useFakeTimers(nowTime));
});
it('uses colors when it\'s supported', function () {
var logger = makeLogger();
var hasColor = require('chalk').supportsColor;
logger.color.should.be.exactly(hasColor);
});
it('obeys the logger.color === false', function () {
var logger = makeLogger();
stub(process.stdout, 'write');
var withoutColor = 'Elasticsearch INFO: ' + now + '\n something\n\n';
logger.color = false;
logger.onInfo('something');
process.stdout.write.lastCall.args[0].should.eql(withoutColor);
});
it('obeys the logger.color === true', function () {
var logger = makeLogger();
stub(process.stdout, 'write');
var withoutColor = 'Elasticsearch TRACE: ' + now + '\n curl\n msg\n\n';
logger.color = true;
logger.onTrace('msg', 'curl');
process.stdout.write.lastCall.args[0].should.not.eql(withoutColor);
chalk.stripColor(process.stdout.write.lastCall.args[0]).should.eql(withoutColor);
});
});
});