a minimalist debugger/logger to paste into third party modules (like requirejs) to log what is happening.
Created
February 7, 2016 12:48
-
-
Save bcowgill/b0dcfb39001c6b935f4d to your computer and use it in GitHub Desktop.
A little debugger for third party modules
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
h1#el | |
|H3ll0, {World} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// a mini debugger to put into third party libraries to log/break when | |
// something interesting happens. | |
// set a desired log level with __DEBUG, set __BREAK to enter the debugger | |
// set __MATCH to a regex to match against to filter logs | |
var __DEBUG = 10, __BREAK = 0, __MATCH = /./i, __M = 'minidebug', __LOG = 0; if (__DEBUG) { console.trace(__M+'#_debug level ' + __DEBUG + ' =~ ' + __MATCH.toString()); } function _debug(level, match) { 'use strict'; if (level <= __DEBUG && (!match || __MATCH.test(match))) { ++__LOG; if (__DEBUG >= 10) { console.trace(__M+'?match['+match+']'); } if (__BREAK) { /*jshint -W087*/ | |
debugger; /*jshint +W087*/ } | |
return true; } return false; } | |
(function __test() { | |
'use strict'; | |
if(_debug(1,'hidden')){ console.log(__M+'#method1', this); } | |
if(_debug(1,'matched')){ console.log(__M+'#method2', this); } | |
console.log(__LOG); | |
})(); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* { | |
background: black; | |
color: orange; | |
font-family: ProFontWindows, Consolas, Courier, Monospace, Fixed, Serif; | |
font-size: 24px; | |
font-weight: 1000; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment