Skip to content
This repository has been archived by the owner on Oct 30, 2018. It is now read-only.

Y.config.debug is true by default per YUI default settings #808

Merged
merged 1 commit into from
Nov 30, 2012
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
13 changes: 12 additions & 1 deletion lib/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,18 @@
"mojitsDirs": [ "mojits" ],
"routesFiles": [ "routes.json" ],
"tunnelPrefix": "/tunnel",
"yui": {},
"yui": {
"config": {
"logLevelOrder": [
"debug",
"mojito",
"info",
"warn",
"error",
"none"
]
}
},
"specs": {
"tunnelProxy": {
"type": "TunnelProxy"
Expand Down
23 changes: 10 additions & 13 deletions lib/mojito.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ MojitoServer.prototype._configureAppInstance = function(app, options) {
useSync: true
});

this._configureLogger(Y, yuiConfig);
this._configureLogger(Y);
this._configureYUI(Y, store, modules);

// attaching all modules available for this application for the server side
Expand Down Expand Up @@ -342,9 +342,10 @@ MojitoServer.prototype._configureAppInstance = function(app, options) {
* Configures YUI logger to honor the logLevel and logLevelOrder
* TODO: this should be done at the low level in YUI.
*/
MojitoServer.prototype._configureLogger = function(Y, yuiConfig) {
var logLevel = (yuiConfig.logLevel || 'debug').toLowerCase(),
logLevelOrder = ['debug', 'mojito', 'info', 'warn', 'error', 'none'];
MojitoServer.prototype._configureLogger = function(Y) {
var logLevel = (Y.config.logLevel || 'debug').toLowerCase(),
logLevelOrder = Y.config.logLevelOrder || [],
defaultLogLevel = logLevelOrder[0] || 'info';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't logLevelOrder[0] now always be debug, since we're always using config.json?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@drewfish No, because Y.config.logLevelOrder comes from getAppConfig() from store in the first place, it is set as part of the Y.config early on, and it lands in the _configureLogger through Y.config.logLevelOrder. So, developers my want to redefine that list, in which case the lower priority element does not need to be 'debug' necessarily.


function log(c, msg, cat, src) {
var f,
Expand All @@ -361,32 +362,28 @@ MojitoServer.prototype._configureLogger = function(Y, yuiConfig) {
// to be able to listen for Y.on.
Y.use('base');

if (yuiConfig.debug) {
if (Y.config.debug) {

logLevelOrder = yuiConfig.logLevelOrder || logLevelOrder;
logLevel = (logLevelOrder.indexOf(logLevel) >= 0 ? logLevel : logLevelOrder[0]);

// logLevel index defines the begining of the logLevelOrder structure
// e.g: ['foo', 'bar', 'baz'], and logLevel 'bar' should produce: ['bar', 'baz']
yuiConfig.logLevel = logLevel;
yuiConfig.logLevelOrder = (logLevel ? logLevelOrder.slice(logLevelOrder.indexOf(logLevel)) : []);
logLevelOrder = (logLevel ? logLevelOrder.slice(logLevelOrder.indexOf(logLevel)) : []);

Y.applyConfig({
useBrowserConsole: false,
logLevel: yuiConfig.logLevel,
logLevelOrder: yuiConfig.logLevelOrder
logLevel: logLevel,
logLevelOrder: logLevelOrder
});

// listening for low level log events to filter some of them.
Y.on('yui:log', function (e) {
// we want to use Y.config instead of the original yuiConfig so
// people can switch that value on runtime for debugging
var c = Y.config,
cat = e && e.cat && e.cat.toLowerCase();

// this covers the case Y.log(msg) without category
// by using the low priority category from logLevelOrder.
cat = cat || c.logLevelOrder[0];
cat = cat || defaultLogLevel;

// applying logLevel filters
if (cat && ((c.logLevel === cat) || (c.logLevelOrder.indexOf(cat) >= 0))) {
Expand Down