Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var hasLogger = false;
config = config || {};
// TODO warn about setting per instance errorHandler / logger / logLevel
if (config.errorHandler) {
logging.setErrorHandler(config.errorHandler);
}
if (config.logger) {
// only set a logger in node if one is provided, by not setting we are noop-ing
hasLogger = true;
logging.setLogHandler(config.logger);
// respect the logger's shouldLog functionality
logging.setLogLevel(logging.LogLevel.NOTSET);
}
if (config.logLevel !== undefined) {
logging.setLogLevel(config.logLevel);
}
try {
configValidator.validate(config);
config.isValidInstance = true;
} catch (ex) {
if (hasLogger) {
logger.error(ex);
} else {
console.error(ex.message);
}
config.isValidInstance = false;
}
config = fns.assign(
{
createInstance: function(config) {
try {
config = config || {};
// TODO warn about setting per instance errorHandler / logger / logLevel
if (config.errorHandler) {
logging.setErrorHandler(config.errorHandler);
}
if (config.logger) {
logging.setLogHandler(config.logger);
// respect the logger's shouldLog functionality
logging.setLogLevel(logging.LogLevel.NOTSET);
}
if (config.logLevel !== undefined) {
logging.setLogLevel(config.logLevel);
}
try {
configValidator.validate(config);
config.isValidInstance = true;
} catch (ex) {
logger.error(ex);
config.isValidInstance = false;
}
// Explicitly check for null or undefined
// prettier-ignore
if (config.skipJSONValidation == null) { // eslint-disable-line eqeqeq
config.skipJSONValidation = true;
}
createInstance: function(config) {
try {
config = config || {};
// TODO warn about setting per instance errorHandler / logger / logLevel
if (config.errorHandler) {
logging.setErrorHandler(config.errorHandler);
}
if (config.logger) {
logging.setLogHandler(config.logger);
// respect the logger's shouldLog functionality
logging.setLogLevel(logging.LogLevel.NOTSET);
}
if (config.logLevel !== undefined) {
logging.setLogLevel(config.logLevel);
}
try {
configValidator.validate(config);
config.isValidInstance = true;
} catch (ex) {
logger.error(ex);
config.isValidInstance = false;
}
// Explicitly check for null or undefined
// prettier-ignore
if (config.skipJSONValidation == null) { // eslint-disable-line eqeqeq
config.skipJSONValidation = true;
}
beforeEach(function() {
sinon.stub(datafileManager, 'HttpPollingDatafileManager').returns({
start: sinon.stub(),
stop: sinon.stub(),
get: sinon.stub().returns(null),
on: sinon.stub().returns(function() {}),
onReady: sinon.stub().returns({ then: function() {} }),
});
globalStubErrorHandler = {
handleError: sinon.stub(),
};
logging.setErrorHandler(globalStubErrorHandler);
logging.setLogLevel('notset');
stubLogHandler = {
log: sinon.stub(),
};
logging.setLogHandler(stubLogHandler);
});