diff --git a/bows.js b/bows.js index 7410c4e..493e6ab 100644 --- a/bows.js +++ b/bows.js @@ -32,6 +32,7 @@ bind = Function.prototype.bind, hue = 0, padLength = 15, + profile = true, noop = function() {}, // if ls.debugColors is set, use that, otherwise check for support colorsSupported = ls.debugColors ? (ls.debugColors !== "false") : checkColorSupport(), @@ -68,6 +69,14 @@ if (!bind) return noop; + if (profile) { + var interval = new Date(); + var now = (new Date()).getTime(); + interval.toString = function() { + return -now + (now = new Date().getTime()) + } + } + var logArgs = [logger]; if (colorsSupported) { if(!moduleColorsMap[str]){ @@ -77,11 +86,24 @@ msg = "%c" + msg; colorString = "color: hsl(" + (color) + ",99%,40%); font-weight: bold"; + if (profile) { + msg += " +%sms "; + } + logArgs.push(msg, colorString); }else{ + + if (profile) { + msg += " +%sms "; + } + logArgs.push(msg); } + if (profile) { + logArgs.push(interval); + } + if(arguments.length>1){ var args = Array.prototype.slice.call(arguments, 1); logArgs = logArgs.concat(args); @@ -99,6 +121,9 @@ if (config.padLength) { padLength = config.padLength; } + if (config.profile !== null) { + profile = config.profile; + } }; if (typeof module !== 'undefined') { diff --git a/dist/bows.js b/dist/bows.js index e3f85d1..d7dedd5 100644 --- a/dist/bows.js +++ b/dist/bows.js @@ -33,6 +33,7 @@ bind = Function.prototype.bind, hue = 0, padLength = 15, + profile = true, noop = function() {}, // if ls.debugColors is set, use that, otherwise check for support colorsSupported = ls.debugColors ? (ls.debugColors !== "false") : checkColorSupport(), @@ -69,6 +70,14 @@ if (!bind) return noop; + if (profile) { + var interval = new Date(); + var now = (new Date()).getTime(); + interval.toString = function() { + return -now + (now = new Date().getTime()) + } + } + var logArgs = [logger]; if (colorsSupported) { if(!moduleColorsMap[str]){ @@ -78,11 +87,24 @@ msg = "%c" + msg; colorString = "color: hsl(" + (color) + ",99%,40%); font-weight: bold"; + if (profile) { + msg += " +%sms "; + } + logArgs.push(msg, colorString); }else{ + + if (profile) { + msg += " +%sms "; + } + logArgs.push(msg); } + if (profile) { + logArgs.push(interval); + } + if(arguments.length>1){ var args = Array.prototype.slice.call(arguments, 1); logArgs = logArgs.concat(args); @@ -100,6 +122,9 @@ if (config.padLength) { padLength = config.padLength; } + if (config.profile !== null) { + profile = config.profile; + } }; if (typeof module !== 'undefined') { diff --git a/dist/bows.min.js b/dist/bows.min.js index 64b1e03..063acdd 100644 --- a/dist/bows.min.js +++ b/dist/bows.min.js @@ -1 +1 @@ -!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n;"undefined"!=typeof window?n=window:"undefined"!=typeof global?n=global:"undefined"!=typeof self&&(n=self),n.bows=e()}}(function(){return function e(n,o,r){function t(f,u){if(!o[f]){if(!n[f]){var d="function"==typeof require&&require;if(!u&&d)return d(f,!0);if(i)return i(f,!0);var l=new Error("Cannot find module '"+f+"'");throw l.code="MODULE_NOT_FOUND",l}var a=o[f]={exports:{}};n[f][0].call(a.exports,function(e){var o=n[f][1][e];return t(o?o:e)},a,a.exports,e,n,o,r)}return o[f].exports}for(var i="function"==typeof require&&require,f=0;f=31}var r=function(){var e=.618033988749895;return a+=e,a%=1,360*a},t="undefined"==typeof window,i=!t&&window.localStorage,f=i.andlogKey||"debug",u=i[f],d=e("andlog"),l=Function.prototype.bind,a=0,c=15,p=function(){},s=i.debugColors?"false"!==i.debugColors:o(),g=null,w=null,v=!1,y={};u&&"!"===u[0]&&"/"===u[1]&&(v=!0,u=u.slice(1)),w=u&&"/"===u[0]&&new RegExp(u.substring(1,u.length-1));for(var h=["log","debug","warn","error","info"],b=0,m=h.length;m>b;b++)p[h[b]]=p;g=function(e){var n,o,t;if(n=e.slice(0,c),n+=Array(c+3-n.length).join(" ")+"|",w){var i=e.match(w);if(!v&&!i||v&&i)return p}if(!l)return p;var f=[d];if(s){y[e]||(y[e]=r());var u=y[e];n="%c"+n,o="color: hsl("+u+",99%,40%); font-weight: bold",f.push(n,o)}else f.push(n);if(arguments.length>1){var a=Array.prototype.slice.call(arguments,1);f=f.concat(a)}return t=l.apply(d.log,f),h.forEach(function(e){t[e]=l.apply(d[e]||t,f)}),t},g.config=function(e){e.padLength&&(c=e.padLength)},"undefined"!=typeof n?n.exports=g:window.bows=g}).call()},{andlog:2}],2:[function(e,n,o){!function(){var e="undefined"==typeof window,r=!e&&window.localStorage,t={};if(e)return void(n.exports=console);var i=r.andlogKey||"debug";if(r&&r[i]&&window.console)t=window.console;else for(var f="assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,markTimeline,profile,profileEnd,time,timeEnd,trace,warn".split(","),u=f.length,d=function(){};u--;)t[f[u]]=d;"undefined"!=typeof o?n.exports=t:window.console=t}()},{}]},{},[1])(1)}); \ No newline at end of file +!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n;"undefined"!=typeof window?n=window:"undefined"!=typeof global?n=global:"undefined"!=typeof self&&(n=self),n.bows=e()}}(function(){return function e(n,o,r){function t(f,u){if(!o[f]){if(!n[f]){var l="function"==typeof require&&require;if(!u&&l)return l(f,!0);if(i)return i(f,!0);var d=new Error("Cannot find module '"+f+"'");throw d.code="MODULE_NOT_FOUND",d}var a=o[f]={exports:{}};n[f][0].call(a.exports,function(e){var o=n[f][1][e];return t(o?o:e)},a,a.exports,e,n,o,r)}return o[f].exports}for(var i="function"==typeof require&&require,f=0;f=31}var r=function(){var e=.618033988749895;return a+=e,a%=1,360*a},t="undefined"==typeof window,i=!t&&window.localStorage,f=i.andlogKey||"debug",u=i[f],l=e("andlog"),d=Function.prototype.bind,a=0,c=15,p=!0,s=function(){},g=i.debugColors?"false"!==i.debugColors:o(),w=null,v=null,y=!1,h={};u&&"!"===u[0]&&"/"===u[1]&&(y=!0,u=u.slice(1)),v=u&&"/"===u[0]&&new RegExp(u.substring(1,u.length-1));for(var m=["log","debug","warn","error","info"],b=0,x=m.length;x>b;b++)s[m[b]]=s;w=function(e){var n,o,t;if(n=e.slice(0,c),n+=Array(c+3-n.length).join(" ")+"|",v){var i=e.match(v);if(!y&&!i||y&&i)return s}if(!d)return s;if(p){var f=new Date,u=(new Date).getTime();f.toString=function(){return-u+(u=(new Date).getTime())}}var a=[l];if(g){h[e]||(h[e]=r());var w=h[e];n="%c"+n,o="color: hsl("+w+",99%,40%); font-weight: bold",p&&(n+=" +%sms "),a.push(n,o)}else p&&(n+=" +%sms "),a.push(n);if(p&&a.push(f),arguments.length>1){var b=Array.prototype.slice.call(arguments,1);a=a.concat(b)}return t=d.apply(l.log,a),m.forEach(function(e){t[e]=d.apply(l[e]||t,a)}),t},w.config=function(e){e.padLength&&(c=e.padLength),null!==e.profile&&(p=e.profile)},"undefined"!=typeof n?n.exports=w:window.bows=w}).call()},{andlog:2}],2:[function(e,n,o){!function(){var e="undefined"==typeof window,r=!e&&window.localStorage,t={};if(e)return void(n.exports=console);var i=r.andlogKey||"debug";if(r&&r[i]&&window.console)t=window.console;else for(var f="assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,markTimeline,profile,profileEnd,time,timeEnd,trace,warn".split(","),u=f.length,l=function(){};u--;)t[f[u]]=l;"undefined"!=typeof o?n.exports=t:window.console=t}()},{}]},{},[1])(1)}); \ No newline at end of file