Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add categories for Y.log entries missing them #1610

Merged
merged 1 commit into from
Feb 16, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/yui/js/yui-log.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ INSTANCE.log = function(msg, cat, src, silent) {
bail = excl[src];
}

// Set a default category of info if the category was not defined or was not
// a real category.
if ((typeof cat === 'undefined') || !(cat in LEVELS)) {
cat = 'info';
}

// Determine the current minlevel as defined in configuration
Y.config.logLevel = Y.config.logLevel || 'debug';
minlevel = LEVELS[Y.config.logLevel.toLowerCase()];
Expand Down
63 changes: 63 additions & 0 deletions src/yui/tests/unit/assets/core-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ YUI.add('core-tests', function(Y) {
'getLocation() should return the location object': (Y.UA.nodejs ? true : false),
'getLocation() should return `null` when executing in node.js': (!Y.UA.nodejs || (Y.UA.nodejs && Y.config.win)), //If there is a window object, ignore too
test_log_params: (typeof console == "undefined" || !console.info || Y.UA.nodejs),
test_log_default_category: (typeof console == "undefined" || !console.info || Y.UA.nodejs),
'test: domready delay': !Y.config.win,
'test: window.onload delay': !Y.config.win,
'test: contentready delay': !Y.config.win,
Expand Down Expand Up @@ -438,6 +439,68 @@ YUI.add('core-tests', function(Y) {
Y.log('This should NOT be ignored', 'error', 'logleveltest');
Assert.areEqual(last, 'logleveltest', 'Failed to include log param');
});

console.info = l;
},
test_log_default_category: function() {
if (typeof console == "undefined" || !console.info) {
return;
}
var l = console.info,
Assert = Y.Assert,
consoleFn,
last, lastCategory;

// Override all of the console functions so that we can check
// their return values.
consoleFn = function(str) {
last = str.split(':')[0];
};
console.error = function(str) {
lastCategory = 'error';
consoleFn(str);
};
console.log = function(str) {
lastCategory = 'log';
consoleFn(str);
};
console.warn = function(str) {
lastCategory = 'warn';
consoleFn(str);
};
console.debug = function(str) {
lastCategory = 'debug';
consoleFn(str);
};
console.info = function(str) {
lastCategory = 'info';
consoleFn(str);
};

YUI().use(function (Y) {
Y.applyConfig({
logLevel: 'debug'
});
lastCategory = undefined;
Y.log('This has a valid log level', 'debug');
Assert.areEqual(lastCategory, 'debug', 'Failed to log at debug log category');
lastCategory = undefined;
Y.log('This has a valid log level', 'info');
Assert.areEqual(lastCategory, 'info', 'Failed to log at info log category');
lastCategory = undefined;
Y.log('This has a valid log level', 'warn');
Assert.areEqual(lastCategory, 'warn', 'Failed to log at warn log category');
lastCategory = undefined;
Y.log('This has a valid log level', 'error');
Assert.areEqual(lastCategory, 'error', 'Failed to log at error log category');
lastCategory = undefined;
Y.log('This has no log level and should use the default');
Assert.areEqual(lastCategory, 'info', 'Failed to log at default log category of info');
lastCategory = undefined;
Y.log('This has an invalid log level and should use the default', 'notice');
Assert.areEqual(lastCategory, 'info', 'Failed to log at default info log category');
});

console.info = l;
},
test_global_apply_config: function() {
Expand Down