Skip to content

Commit

Permalink
Merge pull request #107 from twitter/automate_logging_setup
Browse files Browse the repository at this point in the history
Automate logging setup
  • Loading branch information
sayrer committed May 10, 2013
2 parents 588da8f + 3d5e94d commit 3e7212a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
18 changes: 11 additions & 7 deletions lib/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ define(
'./advice',
'./utils',
'./compose',
'./registry'
'./registry',
'./logger',
'../tools/debug/debug'
],

function(advice, utils, compose, registry) {
function(advice, utils, compose, registry, withLogging, debug) {

var functionNameRegEx = /function (.*?)\s?\(/;
var componentId = 0;
Expand Down Expand Up @@ -91,7 +93,7 @@ define(

type = event.type || event;

if (window.DEBUG && window.DEBUG.enabled && window.postMessage) {
if (debug.enabled && window.postMessage) {
checkSerializable.call(this, type, data);
}

Expand Down Expand Up @@ -224,7 +226,7 @@ define(
function define(/*mixins*/) {
// unpacking arguments by hand benchmarked faster
var l = arguments.length;
var mixins = new Array(l);
var mixins = new Array(l + 3); //add three for common mixins
for (var i = 0; i < l; i++) mixins[i] = arguments[i];

Component.toString = function() {
Expand All @@ -240,7 +242,7 @@ define(
return prettyPrintMixins;
};

if (window.DEBUG && window.DEBUG.enabled) {
if (debug.enabled) {
Component.describe = Component.toString();
}

Expand All @@ -262,7 +264,7 @@ define(
}

this.toString = Component.toString;
if (window.DEBUG && window.DEBUG.enabled) {
if (debug.enabled) {
this.describe = this.toString();
}

Expand All @@ -289,8 +291,10 @@ define(
Component.teardownAll = teardownAll;

// prepend common mixins to supplied list, then mixin all flavors
if (debug.enabled) {
mixins.unshift(withLogging);
}
mixins.unshift(withBaseComponent, advice.withAdvice, registry.withRegistration);

compose.mixin(Component.prototype, mixins);

return Component;
Expand Down
4 changes: 1 addition & 3 deletions lib/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,12 @@ define(
action,
'[' + name + ']',
elemToString(elem),
component.constructor.toString(),
fn && (fnName = fn.name || fn.displayName) && '-> ' + fnName
component.constructor.describe.split(' ').slice(0,3).join(' ') //two mixins only
);
}
}
}


function withLogging() {
this.before('trigger', function() {
log('trigger', this, util.toArray(arguments));
Expand Down

0 comments on commit 3e7212a

Please sign in to comment.