Skip to content

Commit

Permalink
Added isVerbose as a property of mechanic to suppress excessive loggi…
Browse files Browse the repository at this point in the history
…ng from UIALogger.
  • Loading branch information
boxiong authored and boxiong committed Dec 3, 2013
1 parent 0da7767 commit 85dbefb
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
24 changes: 23 additions & 1 deletion spec/logging-spec.js
@@ -1,10 +1,29 @@
describe('Mechanic Event Module', function() {
describe('Mechanic Logging Module', function() {
it('suppresses message and debug logs when isVerbose is false', function() {
spyOn(UIALogger, 'logError');
spyOn(UIALogger, 'logWarning');
spyOn(UIALogger, 'logDebug');
spyOn(UIALogger, 'logMessage');

$.isVerbose = false;
$.log('error', 'error');
$.log('warn', 'warn');
$.log('debug', 'debug');
$.log('message', 'message');

expect(UIALogger.logError).toHaveBeenCalledWith('error');
expect(UIALogger.logWarning).toHaveBeenCalledWith('warn');
expect(UIALogger.logDebug).not.toHaveBeenCalled();
expect(UIALogger.logMessage).not.toHaveBeenCalled();
});

it('delegates to UIALogger when logging', function() {
spyOn(UIALogger, 'logError');
spyOn(UIALogger, 'logWarning');
spyOn(UIALogger, 'logDebug');
spyOn(UIALogger, 'logMessage');

$.isVerbose = true;
$.error('error');
$.warn('warn');
$.debug('debug');
Expand All @@ -20,6 +39,7 @@ describe('Mechanic Event Module', function() {
spyOn(UIALogger, 'logMessage');
spyOn(UIALogger, 'logError');

$.isVerbose = true;
$.log('hello!');

expect(UIALogger.logMessage).toHaveBeenCalledWith('hello!');
Expand All @@ -30,6 +50,7 @@ describe('Mechanic Event Module', function() {
spyOn(UIALogger, 'logMessage');
spyOn(UIALogger, 'logError');

$.isVerbose = true;
$.log('hello!', 'fakelevel');

expect(UIALogger.logMessage).toHaveBeenCalledWith('hello!');
Expand All @@ -42,6 +63,7 @@ describe('Mechanic Event Module', function() {
spyOn(UIALogger, 'logDebug');
spyOn(UIALogger, 'logMessage');

$.isVerbose = true;
$.log('error', 'error');
$.log('warn', 'warn');
$.log('debug', 'debug');
Expand Down
8 changes: 5 additions & 3 deletions src/logging.js
Expand Up @@ -8,15 +8,17 @@
level = level || 'message';
if (level === 'error') $.error(s);
else if (level === 'warn') $.warn(s);
else if (level === 'debug') $.debug(s);
else $.message(s);
else if (typeof $.isVerbose !== "undefined" && $.isVerbose) {
if (level === 'debug') $.debug(s);
else $.message(s);
}
},
error: function(s) { UIALogger.logError(s); },
warn: function(s) { UIALogger.logWarning(s); },
debug: function(s) { UIALogger.logDebug(s); },
message: function(s) { UIALogger.logMessage(s); },
capture: function(imageName, rect) {
var target = UIATarget.localTarget();
var target = UIATarget.localTarget();
imageName = imageName || new Date().toString();
if (rect) target.captureRectWithName(rect, imageName);
else target.captureScreenWithName(imageName);
Expand Down
3 changes: 3 additions & 0 deletions src/mechanic-core.js
Expand Up @@ -18,6 +18,9 @@ var mechanic = (function() {
// Developers can adjust this value by calling $.timeout(duration)
target.setTimeout(0);

// This property is meant to suppress excessive logging which prevents instruments from promptly dumping out screenshots.
this.isVerbose = false

var app = target.frontMostApp(),
window = app.mainWindow(),
emptyArray = [],
Expand Down

0 comments on commit 85dbefb

Please sign in to comment.