Skip to content

Commit

Permalink
Modify log to work with dojo settings. Add log test.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Wilcox committed Jul 3, 2012
1 parent 0343459 commit 70e55e0
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 25 deletions.
53 changes: 28 additions & 25 deletions log.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,23 @@ define(function(){
//
var ua = window.navigator.userAgent;

window.bvConfig = {
debug:1
};
// uncommented for dev
//window.dojoConfig = { debug:1 };

var fixConsole = function(){
if(window.bvConfig === undefined) window.bvConfig = {};
if(bvConfig.nofixios) return;
var dbg = window.debug || bvConfig.debug || /debug=true/.test(document.location.href) || false;
bvConfig.loglimit = bvConfig.loglimit || 299;
var count = bvConfig.loglimit;
if(window.dojoConfig === undefined) window.dojoConfig = {};
if(dojoConfig.nofixios) return;
var dbg = window.debug || dojoConfig.debug || /debug=true/.test(document.location.href) || false;
dojoConfig.loglimit = dojoConfig.loglimit || 299;
var count = dojoConfig.loglimit;

var common = "info,error,log,warn";
var more = "debug,time,timeEnd,assert,count,trace,dir,dirxml,group,groupEnd,groupCollapsed,exception";

var supportedBrowser = /Android/.test(ua);


if(bvConfig.pageDebug || (supportedBrowser && bvConfig.androidDebug)){
if(dojoConfig.pageDebug || (supportedBrowser && dojoConfig.androidDebug)){
var loaded = false;

if(!/Firefox/.test(ua)) window.console = {};
Expand All @@ -70,7 +69,10 @@ define(function(){
}
var flush = function(){
list.forEach(function(o){
bv.dom('div', {css:"bvLog", innerHTML:o.type+":"+o.args}, node);
var div = document.createElement('div');
div.className = 'djLog';
div.innerHTML = o.type+":"+o.args;
node.appendChild(div);
});
list = [];
}
Expand All @@ -89,22 +91,23 @@ define(function(){
c[n] = function(){}
});

window.bvPageDebugger = function(){
bv.ready(function(){
node = bv.byId("bvDbg");
flush();
});
bv.on("interval", function(){
if(list.length) flush();
}, 100);


}

var ready = function(){
node = document.getElementById("djDbg");
flush();
};

var h1 = setInterval(function(){
if(!!document.body){
clearInterval(h1);
ready();
setInterval(function(){
if(list.length) flush();
}, 100);
}
}, 100);
}


if(!window.console) {
console = {};
dbg = false;
Expand All @@ -122,8 +125,8 @@ define(function(){
count--;
if(count == 0){
console.clear();
count = bvConfig.loglimit;
}//console._log("***LOG LIMIT OF "+bvConfig.loglimit+" HAS BEEN REACHED***");
count = dojoConfig.loglimit;
}//console._log("***LOG LIMIT OF "+dojoConfig.loglimit+" HAS BEEN REACHED***");
if(count < 1) return;
try{
console[type](Array.prototype.slice.call(arguments).join(" "));
Expand All @@ -135,7 +138,7 @@ define(function(){
}
// clear the console on load. This is more than a convenience - too many logs crashes it.
// (If closed it throws an error)
try{ console.clear(); }catch(e){}
try{ console.clear(); }catch(e){}
}

var fixMobile = function(){
Expand Down
70 changes: 70 additions & 0 deletions tests/test_log.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 5//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>Test dx-alias/log</title>
<style>
html, body{
margin:10px;
padding:0;
background:#fff;
font-family: sans-serif;
}
a{
display: block;
}
.warn{
margin: 20px;
padding: 5px;
width: 450px;
background: #FFFDEA;
color: #8E0C0C;
font-size: 14px;
}
</style>
<script>
dojoConfig = {
async:1
};
</script>
<script src="../../dojo/dojo.js"></script>
<script>
require([
'dx-alias/log',
'dx-alias/dom'
], function(logger, dom){

var log = logger('', 1);
log('log without prefix');

var log2 = logger('PRE', 1);
log2('log with PRE prefix');

var log3 = logger('OFF', 0);
log('log will not show:');
log3('not showing!');

// logger is here on used unconventionally
log('log will not show unless FOO is in the URL:');
logger('FOO', 0)('showing??');
log('log will not show unless BAR is in the URL:');
logger('BAR', 0)('showing??');

if(!window.dojoConfig || !window.dojoConfig.isDebug || !window.dojoConfig.debug){
window.onload = function(){
dom('div', {css:'warn', html:'The console is turned off. Please set: dojoConfig.debug = true'}, document.body);
}
}
});
</script>
</head>
<body>
<h1>
Test dx-alias/log
</h1>
<p>Test is in the console.</p>
<a href='?debug=BAR,FOO'>Show FOO and BAR logs</a>
<a href='?debug=FOO'>Show FOO logs</a>
<a href='?debug=BAR'>Show BAR logs</a>
<a href='?'>Show default logs</a>
</body>
</html>

0 comments on commit 70e55e0

Please sign in to comment.