analogger 1.8.2 → 1.8.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -1
- package/dist/analogger-browser.min.mjs +2 -2
- package/generated/browser/{src/cjs/ana-logger.mjs → ana-logger.mjs} +3 -3
- package/generated/browser/demo.mjs +1 -1
- package/package.json +8 -7
- package/src/cjs/ana-logger.cjs +807 -0
- package/src/cjs/bump.js +1 -0
- package/src/cjs/constants.cjs +31 -0
- package/.run/Debuggable demo.run.xml +0 -12
- package/.run/Demo in browser with importmap.run.xml +0 -12
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
## [1.8.
|
|
1
|
+
## [1.8.5](https://github.com/thimpat/analogger/compare/v1.8.4...v1.8.5) (2022-02-28)
|
|
2
2
|
|
|
3
|
+
## [1.8.4](https://github.com/thimpat/analogger/compare/v1.8.3...v1.8.4) (2022-02-28)
|
|
4
|
+
|
|
5
|
+
## [1.8.3](https://github.com/thimpat/analogger/compare/v1.8.2...v1.8.3) (2022-02-28)
|
|
6
|
+
|
|
7
|
+
## [1.8.2](https://github.com/thimpat/analogger/compare/v1.8.1...v1.8.2) (2022-02-28)
|
|
8
|
+
|
|
3
9
|
## [1.8.1](https://github.com/thimpat/analogger/compare/v1.8.0...v1.8.1) (2022-02-28)
|
|
4
10
|
|
|
5
11
|
# [1.8.0](https://github.com/thimpat/analogger/compare/v1.7.0...v1.8.0) (2022-02-23)
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const s={};{s["691688ee4a625b95e9da121716860eed508244a8d18f0b3c060da20f5fcdad09"]={};const o=["#d2466e","#FFA07A","#FF7F50","#FF6347","#FFE4B5","#ADFF2F","#808000","#40E0D0","#1E90FF","#EE82EE","#708090","#DEB887","#FE642E","#210B61","#088A4B","#5E610B","#FA8258","#088A68","#B40431"],t={BROWSER:"BROWSER",NODE:"NODE"};var r=o,e=t;s["691688ee4a625b95e9da121716860eed508244a8d18f0b3c060da20f5fcdad09"].COLOR_TABLE=r,s["691688ee4a625b95e9da121716860eed508244a8d18f0b3c060da20f5fcdad09"].SYSTEM=e}s["37feee54896c340bb578ce5b0f398fc0c97d65b8575a4553f2e082a496645c80"]={},s["37feee54896c340bb578ce5b0f398fc0c97d65b8575a4553f2e082a496645c80"].default=function(e,o,t,s){var r=(e+(s||"")).toString().includes("%");if("string"==typeof e?[e,o,t,s]=e.match(/(0?\.?\d{1,3})%?\b/g).map(e=>Number(e)):void 0!==s&&(s=Number.parseFloat(s)),"number"!=typeof e||"number"!=typeof o||"number"!=typeof t||255<e||255<o||255<t)throw new TypeError("Expected three numbers below 256");if("number"==typeof s){if(!r&&0<=s&&s<=1)s=Math.round(255*s);else{if(!(r&&0<=s&&s<=100))throw new TypeError(`Expected alpha value (${s}) as a fraction or percentage`);s=Math.round(255*s/100)}s=(256|s).toString(16).slice(1)}else s="";return(t|o<<8|e<<16|1<<24).toString(16).slice(1)+s};{s.f919b6b1b49ea775df278d9a53baeb24cbc3173d1e555db776aa666bbb6cb102={};const i={Foreground:38,Background:48},
|
|
2
|
-
`){const t=JSON.parse(JSON.stringify(this.logHistory.slice(0)));return e?t.join(o):t}isNode(){return this.system===e.NODE}isBrowser(){return!this.isNode()}resetLogger(){this.options={contextLenMax:10,idLenMax:5,lidLenMax:5,symbolLenMax:2,messageLenMax:void 0,hideLog:void 0,hideError:void 0,hideHookMessage:void 0,hidePassingTests:void 0,logToDom:void 0,logToFile:void 0,oneConsolePerContext:void 0,silent:void 0}}resetOptions(){this.options.contextLenMax=10,this.options.idLenMax=5,this.options.lidLenMax=5,this.options.messageLenMax=void 0,this.options.symbolLenMax=60,this.options.hideHookMessage=!1,this.options.hidePassingTests=!1,this.options.hideLog=!1,this.options.hideError=!1,this.options.oneConsolePerContext=!0,this.options.logToDom=void 0,this.options.logToDomlogToFile=void 0,this.options.silent=!1}setOptions({contextLenMax:e=10,idLenMax:o=5,lidLenMax:d=5,symbolLenMax:c=2,messageLenMax:h=void 0,hideLog:t=void 0,hideError:s=void 0,hideHookMessage:r=void 0,hidePassingTests:i=void 0,logToDom:n=void 0,logToFile:a=void 0,oneConsolePerContext:l=void 0,silent:g=void 0}=null){this.options.contextLenMax=e,this.options.idLenMax=o,this.options.lidLenMax=d,this.options.messageLenMax=h,this.options.symbolLenMax=c,void 0!==i&&(this.options.hidePassingTests=!!i),void 0!==r&&(this.options.hideHookMessage=!!r),void 0!==t&&(this.options.hideLog=!!t),void 0!==s&&(this.options.hideError=!!s),void 0!==l&&(this.options.oneConsolePerContext=!!l),void 0!==n&&(this.options.logToDom=n||"#analogger"),void 0!==a&&(this.isBrowser()||(this.options.logToFile=a||"./analogger.log"),this.realConsoleLog("LogToFile is not supported in this environment. ")),void 0!==g&&(this.options.silent=!!g,this.options.hideLog=this.options.silent)}getOptions(){return this.options}truncateMessage(e="",{fit:o=0,align:t=h.ALIGN.LEFT}={}){return e=""+e,o&&e.length>=o+2&&(e=e.substring(0,o-3)+"..."),e=t===h.ALIGN.LEFT?e.padEnd(o," "):e.padStart(o," ")}onBuildLog({contextName:e,message:o="",lid:t="",symbol:s=""}={}){const r=new Date;var i=("0"+r.getHours()).slice(-2)+":"+("0"+r.getMinutes()).slice(-2)+":"+("0"+r.getSeconds()).slice(-2),i=this.truncateMessage(i,{fit:7});return e=this.truncateMessage(e,{fit:this.options.contextLenMax,align:h.ALIGN.RIGHT}),t=this.truncateMessage(t,{fit:this.options.lidLenMax}),void 0!==this.options.messageLenMax&&(o=this.truncateMessage(o,{fit:this.options.messageLenMax})),`[${i}] ${e}: (${t}) ${s=this.truncateMessage(s,{fit:this.options.symbolLenMax})} `+o}onErrorForUserTarget(e,...o){this.errorUserTargetHandler(e,...o)}onError(e,...o){e.target===this.targets.USER&&this.onErrorForUserTarget(e,...o)}onDisplayLog(...e){this.log(...e)}onDisplayError(...e){this.error(...e)}setLogFormat(e){if("function"!=typeof e)return console.error("Invalid parameter for setFormat. It is expecting a function or method."),!1;this.format=e.bind(this)}resetLogFormatter(){this.format=this.originalFormatFunction}setErrorHandler(e){this.errorTargetHandler=e.bind(this)}setErrorHandlerForUserTarget(e){this.errorUserTargetHandler=e.bind(this)}isContextValid(e){return"object"==typeof e&&!Array.isArray(e)&&null!==e&&(e.hasOwnProperty("contextName")&&e.hasOwnProperty("target"))}generateDefaultContext(){const e={name:"DEFAULT",contextName:"DEFAULT",target:"ALL",symbol:"⚡"};return e.id=this.logIndex++,e.color=o[1],e}generateNewContext(){const e=this.generateDefaultContext();return e.color=o[this.indexColor++%(o.length-3)+2],e.symbol="",e}generateErrorContext(){const e=this.generateDefaultContext();return e.color=o[0],e.symbol="v",e.error=!0,e}#allegeProperties(e){let o=e;e=this.generateNewContext();return-1<(o=Object.assign({},e,o)).color.toLowerCase().indexOf("rgb")?o.color="#"+t(o.color):-1===o.color.indexOf("#")&&0,o}setContexts(t){const e=Object.keys(t);t.DEFAULT=this.contexts.DEFAULT=this.generateDefaultContext(),t.ERROR=this.contexts.ERROR=this.generateErrorContext(),e.forEach(e=>{const o=t[e]||{};o.contextName=e,o.name=e,this.contexts[e]=this.#allegeProperties(o),t[e]=this.contexts[e]})}setTargets(e={}){this.targets=Object.assign({},e,{ALL:"ALL",USER:"USER"})}setActiveTarget(e){this.activeTarget=e}isTargetAllowed(e){return!e||!this.activeTarget||(e===this.targets.ALL||this.activeTarget===e)}setColumns(e,o,t){let s=0;for(var r in o)if("name"!==r){var i=o[r];const n=document.createElement("span");n.classList.add("analogger-col","analogger-col-"+r,"analogger-col-"+s),++s,n.textContent=i,e.append(n)}const n=document.createElement("span");n.classList.add("analogger-col","analogger-col-text","analogger-col-"+s),n.textContent=t,e.append(n)}writeLogToDom(t,s){this.$containers=this.$containers||document.querySelectorAll(this.options.logToDom);for(let o=0;o<this.$containers.length;++o){const r=this.$containers[o];let e=r.querySelector(".analogger-view");e||((e=document.createElement("div")).classList.add("analogger-view"),r.append(e));const i=document.createElement("div");i.classList.add("to-esm-line"),i.style.color=t.color,i.setAttribute("data-log-counter",this.logCounter),i.setAttribute("data-log-index",this.logIndex),this.setColumns(i,t,s),e.append(i)}}writeLogToFile(e){this.logFile.write(e+this.EOL)}processOutput(t={}){try{if(!this.isTargetAllowed(t.target))return;let e=Array.prototype.slice.call(arguments);e.shift();var s=e.join(" | ");let o="";var r=this.format({...t,message:s});if(++this.logCounter,this.isBrowser()?(t.environnment=h.ENVIRONMENT_TYPE.BROWSER,this.options.logToDom&&this.writeLogToDom(t,r),o="%c"+r):(t.environnment=h.ENVIRONMENT_TYPE.NODE,o=i.getTextFromHex(r,{fg:t.color}),this.options.logToFile&&this.writeLogToFile(r)),this.keepLog&&this.logHistory.push(o),this.options.hideLog)return;this.isBrowser()?this.realConsoleLog(o,"color: "+t.color):this.realConsoleLog(o),this.errorTargetHandler(t,e)}catch(e){console.error("AnaLogger:",e.message)}}isExtendedOptionsPassed(e){return"object"==typeof e&&(e.hasOwnProperty("context")||e.hasOwnProperty("target")||e.hasOwnProperty("color")||e.hasOwnProperty("lid"))}convertToContext(e,o){o=o||this.generateDefaultContext();let t=e=e||o;if(e.context&&"object"==typeof e.context){const s=Object.assign({},e);delete s.context,t=Object.assign({},e.context,s)}return delete(t=Object.assign({},o,t)).context,t}log(e,...o){if(!this.isExtendedOptionsPassed(e))return t=this.generateDefaultContext(),void this.processOutput.apply(this,[t,e,...o]);var t=this.convertToContext(e);this.processOutput.apply(this,[t,...o])}error(e,...o){if(!this.options.hideError){if(!this.isExtendedOptionsPassed(e))return t=this.generateErrorContext(),void this.processOutput.apply(this,[t,e,...o]);var t=this.generateErrorContext(),t=this.convertToContext(e,t),s=Array.prototype.slice.call(arguments,1);this.log(t,...s)}}overrideError(){this.options.hideHookMessage||this.realConsoleLog("AnaLogger: Hook placed on console.error"),console.error=this.onDisplayError.bind(this)}overrideConsole({log:e=!0,info:o=!0,warn:t=!0,error:s=!1}={}){this.options.hideHookMessage||this.realConsoleLog("AnaLogger: Hook placed on console.log"),e&&(console.log=this.onDisplayLog.bind(this)),o&&(console.info=this.onDisplayLog.bind(this)),t&&(console.warn=this.onDisplayLog.bind(this)),s&&this.overrideError()}removeOverrideError(){console.warn=this.realConsoleError}removeOverride({log:e=!0,info:o=!0,warn:t=!0,error:s=!1}={}){e&&(console.log=this.realConsoleLog),o&&(console.info=this.realConsoleInfo),t&&(console.warn=this.realConsoleWarn),s&&this.removeOverrideError()}info(...e){return this.log(...e)}warn(...e){return this.log(...e)}alert(...e){if(this.isNode())return this.log(...e);e=e.join(" | ");alert(e)}assert(e,o=!0,...t){try{return"function"==typeof e?e(...t)!==o?(this.error("Asset failed"),!1):(this.options.hidePassingTests||this.log("SUCCESS: Assert passed"),!0):e!==o?(this.error("Assert failed"),!1):(this.options.hidePassingTests||this.log("SUCCESS: Assert passed"),!0)}catch(e){this.error("Unexpected error in assert")}return!1}}s["4d57d38aa40d107726ae91903137473bc8081bb629cc75d09818e590b4424721"].default=new h,r=new h,s["4d57d38aa40d107726ae91903137473bc8081bb629cc75d09818e590b4424721"].anaLogger=r}s.c30121e4056ba978b4fb451fa7489c6ff84e611cdca39ae86de3030d10e7073e={},s.c30121e4056ba978b4fb451fa7489c6ff84e611cdca39ae86de3030d10e7073e.LOG_CONTEXTS={STANDARD:{},TEST:{color:"#B18904",symbol:"⏰"},TEST2:{color:"rgb(127, 127, 127)",symbol:"⏰"},TEST3:{color:"blue",symbol:"⏰"},C1:null,C2:null,C3:null,DEFAULT:{}},s.c30121e4056ba978b4fb451fa7489c6ff84e611cdca39ae86de3030d10e7073e.LOG_TARGETS={ALL:"ALL",DEV1:"TOM",DEV2:"TIM",DEV3:"ME",USER:"USER"};{s.ca63110bb9882fce16420271e1c0aa1a22360931c93ababb90ba99d2da8a867c={};var{LOG_CONTEXTS:e,LOG_TARGETS:r}=s.c30121e4056ba978b4fb451fa7489c6ff84e611cdca39ae86de3030d10e7073e;let o=s["4d57d38aa40d107726ae91903137473bc8081bb629cc75d09818e590b4424721"]["anaLogger"];o.keepLogHistory(),o.setContexts(e),o.setTargets(r),o.setActiveTarget(r.DEV3),o.setOptions({logToDom:".analogger"}),o.setOptions({silent:!0}),console.log("=========================="),o.log(e.C1,"You should not see this C1"),o.log(e.C2,"You should not see this C2"),o.log(e.C3,"You should not see this C3"),o.setOptions({silent:!1,hideError:!1,logToFile:"./logme.log"}),o.log(e.C1,"You should see this C100"),o.log(e.C2,"You should see this C200"),o.log(e.C3,"You should see this C300"),console.log("============= From History ==========================="),console.log(o.getLogHistory()),console.log("============= From History (Closed) =================="),o.assert(!0),o.assert(!1),o.assert(()=>!0,!0),o.assert((e,o)=>e===o,!0,2,2),console.log("-------------------------- console.log is about to be overridden"),o.overrideConsole(),console.log("Log After override <= Console.log is overridden"),console.error("-------------------------- console.error is about to be overridden"),o.overrideError(),console.error("Hook on Error placed after override <= Console.error is also overridden"),console.log("=========================="),o.log(e.STANDARD,"Basic Log example 2","+Something 0","+Something 1"),o.log({context:e.TEST,lid:1e5},"Test Log example"),o.log({context:e.TEST,target:r.DEV3,lid:100001},"Test Log example with active target"),o.log({context:e.TEST,target:r.DEV1,lid:100002},"Test Log example with DEV1 target"),o.log({context:e.TEST,target:r.DEV2,lid:100003},"Test Log example with DEV2 target"),o.log("Test Log example with DEFAULT target"),o.log(e.TEST,"Test Log example","+Something 3"),o.log(e.C1,"Test Log example C1"),o.log(e.C2,"Test Log example C2"),o.log(e.C3,"Test Log example C3"),console.log(e.C1,"Test Log example C4"),console.log(e.C1,"Test Log example C5"),console.log(e.C1,"Test Log example C6"),console.error({context:e.ERROR,lid:2e5},"Testing Error 1"),console.error(e.ERROR,"Testing Error 2"),console.error("Testing Error 3"),console.error(void 0,"Testing Error 4"),console.error({context:e.ERROR,target:r.USER,lid:200010},"Testing Error 4"),o.info("Hello from alert",{aaa:1012}),o.setActiveTarget(r.USER),o.setErrorHandlerForUserTarget(function(e){o.log("User explicitly see this message"),o.info("User explicitly see this message",e)}),console.error({context:e.ERROR,target:r.USER,lid:200020},"Testing Error that triggers a special handler"),o.setLogFormat(function({contextName:e,message:o}){return e+": "+o}),console.log(e.C1,"Test Log example C4 with new format"),console.log(e.C1,"Test Log example C5 with new format"),console.log(e.C1,"Test Log example C6 with new format"),o.log("Basic Log example 1")}
|
|
1
|
+
const s={};{s["691688ee4a625b95e9da121716860eed508244a8d18f0b3c060da20f5fcdad09"]={};const o=["#d2466e","#FFA07A","#FF7F50","#FF6347","#FFE4B5","#ADFF2F","#808000","#40E0D0","#1E90FF","#EE82EE","#708090","#DEB887","#FE642E","#210B61","#088A4B","#5E610B","#FA8258","#088A68","#B40431"],t={BROWSER:"BROWSER",NODE:"NODE"};var r=o,e=t;s["691688ee4a625b95e9da121716860eed508244a8d18f0b3c060da20f5fcdad09"].COLOR_TABLE=r,s["691688ee4a625b95e9da121716860eed508244a8d18f0b3c060da20f5fcdad09"].SYSTEM=e}s["37feee54896c340bb578ce5b0f398fc0c97d65b8575a4553f2e082a496645c80"]={},s["37feee54896c340bb578ce5b0f398fc0c97d65b8575a4553f2e082a496645c80"].default=function(e,o,t,s){var r=(e+(s||"")).toString().includes("%");if("string"==typeof e?[e,o,t,s]=e.match(/(0?\.?\d{1,3})%?\b/g).map(e=>Number(e)):void 0!==s&&(s=Number.parseFloat(s)),"number"!=typeof e||"number"!=typeof o||"number"!=typeof t||255<e||255<o||255<t)throw new TypeError("Expected three numbers below 256");if("number"==typeof s){if(!r&&0<=s&&s<=1)s=Math.round(255*s);else{if(!(r&&0<=s&&s<=100))throw new TypeError(`Expected alpha value (${s}) as a fraction or percentage`);s=Math.round(255*s/100)}s=(256|s).toString(16).slice(1)}else s="";return(t|o<<8|e<<16|1<<24).toString(16).slice(1)+s};{s.f919b6b1b49ea775df278d9a53baeb24cbc3173d1e555db776aa666bbb6cb102={};const i={Foreground:38,Background:48},f="[0m",d={Bold:"[1m",Underline:"[4m",Reversed:"[7m"},u=(e,o,t)=>e===o&&o===t?e<8?16:248<e?231:Math.round((e-8)/247*24)+232:16+36*Math.round(e/255*5)+6*Math.round(o/255*5)+Math.round(t/255*5),p=e=>{e=e.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i,function(e,o,t,s){return o+o+t+t+s+s});e=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);return e?{red:parseInt(e[1],16),blue:parseInt(e[2],16),green:parseInt(e[3],16)}:{}},c=function(e,o,t){return t<0&&(t+=1),1<t&&--t,t<1/6?e+6*(o-e)*t:t<.5?o:t<2/3?e+(o-e)*(2/3-t)*6:e};function n({red:e,blue:o,green:t},s=!0){if(void 0===e||void 0===o||void 0===t)return"";e=u(e,o,t);return`[${s?i.Foreground:i.Background};5;`+e+"m "}function a(e,o){var{red:e,green:t,blue:s}=p(e);return n({red:e,green:t,blue:s},o)}function l({hue:e,saturation:o,lightness:t},s){var{red:e,green:o,blue:t}=(({hue:e,saturation:o,lightness:t})=>{let s,r,i;return 0===o?s=r=i=t:(o=2*t-(t=t<.5?t*(1+o):t+o-t*o),s=c(o,t,e+1/3),r=c(o,t,e),i=c(o,t,e-1/3)),{red:Math.round(255*s),blue:Math.round(255*i),green:Math.round(255*r)}})({hue:e,saturation:o,lightness:t});return n({red:e,green:o,blue:t},s)}function g(e,{fg:o,bg:t,isUnderline:s=!1,isBold:r=!1,isReversed:i=!1}){let n="";return o&&(n+=o),t&&(n+=t),s&&(n+=d.Underline),r&&(n+=d.Bold),i&&(n+=d.Reversed),n+e+f}s.f919b6b1b49ea775df278d9a53baeb24cbc3173d1e555db776aa666bbb6cb102.default={fromRgb:n,fromHexa:a,fromHsl:l,getTextFromRgb:function(e,{fg:o={},bg:t={},isUnderline:s=!1,isBold:r=!1,isReversed:i=!1}){return g(e,{fg:o=o&&n({...o}),bg:t=t&&n({...t},!1),isUnderline:s,isBold:r,isReversed:i})},getTextFromHsl:function(e,{fg:o="",bg:t="",isUnderline:s=!1,isBold:r=!1,isReversed:i=!1}){return g(e,{fg:o=o&&l({...o}),bg:t=t&&l({...t},!1),isUnderline:s,isBold:r,isReversed:i})},getTextFromHex:function(e,{fg:o="",bg:t="",isUnderline:s=!1,isBold:r=!1,isReversed:i=!1}){return g(e,{fg:o=o&&a(o),bg:t=t&&a(t,!1),isUnderline:s,isBold:r,isReversed:i})},hexToRgb:p,rgbToAnsi256:u,hue2rgb:c,RESET:f,FONT_STYLE:d,STYLE:{Bold:"[1m",Underline:"[4m",Reversed:"[7m"}}}{s.b8449304eec2797907cc7f2ee0c87c037a9af4d34da7ab5f57c5f4ef535d3667={};let i=s.f919b6b1b49ea775df278d9a53baeb24cbc3173d1e555db776aa666bbb6cb102.default,t=s["37feee54896c340bb578ce5b0f398fc0c97d65b8575a4553f2e082a496645c80"].default,{COLOR_TABLE:o,SYSTEM:e}=s["691688ee4a625b95e9da121716860eed508244a8d18f0b3c060da20f5fcdad09"];class h{system="";logIndex=0;logCounter=0;contexts=[];targets={};activeTarget=null;indexColor=0;format="";keepLog=!1;logHistory=[];$containers=null;options={hideHookMessage:!1};static ALIGN={LEFT:"LEFT",RIGHT:"RIGHT"};static ENVIRONMENT_TYPE={BROWSER:"BROWSER",NODE:"NODE",OTHER:"OTHER"};originalFormatFunction;constructor(){if(h.Instance)return h.Instance;(h.Instance=this).system="object"==typeof process?e.NODE:e.BROWSER,this.format=this.onBuildLog.bind(this),this.originalFormatFunction=this.format,this.errorTargetHandler=this.onError.bind(this),this.errorUserTargetHandler=this.onErrorForUserTarget.bind(this),this.setOptions(this.options),this.realConsoleLog=console.log,this.realConsoleInfo=console.info,this.realConsoleWarn=console.warn,this.realConsoleError=console.error,this.ALIGN=h.ALIGN,this.ENVIRONMENT_TYPE=h.ENVIRONMENT_TYPE}keepLogHistory(){this.keepLog=!0}releaseLogHistory(){this.keepLog=!1}resetLogHistory(){this.logHistory=[]}getLogHistory(e=!0,o=`
|
|
2
|
+
`){const t=JSON.parse(JSON.stringify(this.logHistory.slice(0)));return e?t.join(o):t}isNode(){return this.system===e.NODE}isBrowser(){return!this.isNode()}resetLogger(){this.options={contextLenMax:10,idLenMax:5,lidLenMax:5,symbolLenMax:2,messageLenMax:void 0,hideLog:void 0,hideError:void 0,hideHookMessage:void 0,hidePassingTests:void 0,logToDom:void 0,logToFile:void 0,oneConsolePerContext:void 0,silent:void 0}}resetOptions(){this.options.contextLenMax=10,this.options.idLenMax=5,this.options.lidLenMax=5,this.options.messageLenMax=void 0,this.options.symbolLenMax=60,this.options.hideHookMessage=!1,this.options.hidePassingTests=!1,this.options.hideLog=!1,this.options.hideError=!1,this.options.oneConsolePerContext=!0,this.options.logToDom=void 0,this.options.logToDomlogToFile=void 0,this.options.silent=!1}setOptions({contextLenMax:e=10,idLenMax:o=5,lidLenMax:d=5,symbolLenMax:c=2,messageLenMax:h=void 0,hideLog:t=void 0,hideError:s=void 0,hideHookMessage:r=void 0,hidePassingTests:i=void 0,logToDom:n=void 0,logToFile:a=void 0,oneConsolePerContext:l=void 0,silent:g=void 0}=null){this.options.contextLenMax=e,this.options.idLenMax=o,this.options.lidLenMax=d,this.options.messageLenMax=h,this.options.symbolLenMax=c,void 0!==i&&(this.options.hidePassingTests=!!i),void 0!==r&&(this.options.hideHookMessage=!!r),void 0!==t&&(this.options.hideLog=!!t),void 0!==s&&(this.options.hideError=!!s),void 0!==l&&(this.options.oneConsolePerContext=!!l),void 0!==n&&(this.options.logToDom=n||"#analogger"),void 0!==a&&(this.isBrowser()||(this.options.logToFile=a||"./analogger.log"),this.realConsoleLog("LogToFile is not supported in this environment. ")),void 0!==g&&(this.options.silent=!!g,this.options.hideLog=this.options.silent)}getOptions(){return this.options}truncateMessage(e="",{fit:o=0,align:t=h.ALIGN.LEFT}={}){return e=""+e,o&&e.length>=o+2&&(e=e.substring(0,o-3)+"..."),e=t===h.ALIGN.LEFT?e.padEnd(o," "):e.padStart(o," ")}onBuildLog({contextName:e,message:o="",lid:t="",symbol:s=""}={}){const r=new Date;var i=("0"+r.getHours()).slice(-2)+":"+("0"+r.getMinutes()).slice(-2)+":"+("0"+r.getSeconds()).slice(-2),i=this.truncateMessage(i,{fit:7});return e=this.truncateMessage(e,{fit:this.options.contextLenMax,align:h.ALIGN.RIGHT}),t=this.truncateMessage(t,{fit:this.options.lidLenMax}),void 0!==this.options.messageLenMax&&(o=this.truncateMessage(o,{fit:this.options.messageLenMax})),`[${i}] ${e}: (${t}) ${s=this.truncateMessage(s,{fit:this.options.symbolLenMax})} `+o}onErrorForUserTarget(e,...o){this.errorUserTargetHandler(e,...o)}onError(e,...o){e.target===this.targets.USER&&this.onErrorForUserTarget(e,...o)}onDisplayLog(...e){this.log(...e)}onDisplayError(...e){this.error(...e)}setLogFormat(e){if("function"!=typeof e)return console.error("Invalid parameter for setFormat. It is expecting a function or method."),!1;this.format=e.bind(this)}resetLogFormatter(){this.format=this.originalFormatFunction}setErrorHandler(e){this.errorTargetHandler=e.bind(this)}setErrorHandlerForUserTarget(e){this.errorUserTargetHandler=e.bind(this)}isContextValid(e){return"object"==typeof e&&!Array.isArray(e)&&null!==e&&(e.hasOwnProperty("contextName")&&e.hasOwnProperty("target"))}generateDefaultContext(){const e={name:"DEFAULT",contextName:"DEFAULT",target:"ALL",symbol:"⚡"};return e.id=this.logIndex++,e.color=o[1],e}generateNewContext(){const e=this.generateDefaultContext();return e.color=o[this.indexColor++%(o.length-3)+2],e.symbol="",e}generateErrorContext(){const e=this.generateDefaultContext();return e.color=o[0],e.symbol="v",e.error=!0,e}#allegeProperties(e){let o=e;e=this.generateNewContext();return-1<(o=Object.assign({},e,o)).color.toLowerCase().indexOf("rgb")?o.color="#"+t(o.color):-1===o.color.indexOf("#")&&0,o}setContexts(t){const e=Object.keys(t);t.DEFAULT=this.contexts.DEFAULT=this.generateDefaultContext(),t.ERROR=this.contexts.ERROR=this.generateErrorContext(),e.forEach(e=>{const o=t[e]||{};o.contextName=e,o.name=e,this.contexts[e]=this.#allegeProperties(o),t[e]=this.contexts[e]})}setTargets(e={}){this.targets=Object.assign({},e,{ALL:"ALL",USER:"USER"})}setActiveTarget(e){this.activeTarget=e}isTargetAllowed(e){return!e||!this.activeTarget||(e===this.targets.ALL||this.activeTarget===e)}setColumns(e,o,t){let s=0;for(var r in o)if("name"!==r){var i=o[r];const n=document.createElement("span");n.classList.add("analogger-col","analogger-col-"+r,"analogger-col-"+s),++s,n.textContent=i,e.append(n)}const n=document.createElement("span");n.classList.add("analogger-col","analogger-col-text","analogger-col-"+s),n.textContent=t,e.append(n)}writeLogToDom(t,s){this.$containers=this.$containers||document.querySelectorAll(this.options.logToDom);for(let o=0;o<this.$containers.length;++o){const r=this.$containers[o];let e=r.querySelector(".analogger-view");e||((e=document.createElement("div")).classList.add("analogger-view"),r.append(e));const i=document.createElement("div");i.classList.add("to-esm-line"),i.style.color=t.color,i.setAttribute("data-log-counter",this.logCounter),i.setAttribute("data-log-index",this.logIndex),this.setColumns(i,t,s),e.append(i)}}writeLogToFile(e){this.logFile.write(e+this.EOL)}processOutput(t={}){try{if(!this.isTargetAllowed(t.target))return;let e=Array.prototype.slice.call(arguments);e.shift();var s=e.join(" | ");let o="";var r=this.format({...t,message:s});if(++this.logCounter,this.isBrowser()?(t.environnment=h.ENVIRONMENT_TYPE.BROWSER,this.options.logToDom&&this.writeLogToDom(t,r),o="%c"+r):(t.environnment=h.ENVIRONMENT_TYPE.NODE,o=i.getTextFromHex(r,{fg:t.color}),this.options.logToFile&&this.writeLogToFile(r)),this.keepLog&&this.logHistory.push(o),this.options.hideLog)return;this.isBrowser()?this.realConsoleLog(o,"color: "+t.color):this.realConsoleLog(o),this.errorTargetHandler(t,e)}catch(e){console.error("AnaLogger:",e.message)}}isExtendedOptionsPassed(e){return"object"==typeof e&&(e.hasOwnProperty("context")||e.hasOwnProperty("target")||e.hasOwnProperty("color")||e.hasOwnProperty("lid"))}convertToContext(e,o){o=o||this.generateDefaultContext();let t=e=e||o;if(e.context&&"object"==typeof e.context){const s=Object.assign({},e);delete s.context,t=Object.assign({},e.context,s)}return delete(t=Object.assign({},o,t)).context,t}log(e,...o){if(!this.isExtendedOptionsPassed(e))return t=this.generateDefaultContext(),void this.processOutput.apply(this,[t,e,...o]);var t=this.convertToContext(e);this.processOutput.apply(this,[t,...o])}error(e,...o){if(!this.options.hideError){if(!this.isExtendedOptionsPassed(e))return t=this.generateErrorContext(),void this.processOutput.apply(this,[t,e,...o]);var t=this.generateErrorContext(),t=this.convertToContext(e,t),s=Array.prototype.slice.call(arguments,1);this.log(t,...s)}}overrideError(){this.options.hideHookMessage||this.realConsoleLog("AnaLogger: Hook placed on console.error"),console.error=this.onDisplayError.bind(this)}overrideConsole({log:e=!0,info:o=!0,warn:t=!0,error:s=!1}={}){this.options.hideHookMessage||this.realConsoleLog("AnaLogger: Hook placed on console.log"),e&&(console.log=this.onDisplayLog.bind(this)),o&&(console.info=this.onDisplayLog.bind(this)),t&&(console.warn=this.onDisplayLog.bind(this)),s&&this.overrideError()}removeOverrideError(){console.warn=this.realConsoleError}removeOverride({log:e=!0,info:o=!0,warn:t=!0,error:s=!1}={}){e&&(console.log=this.realConsoleLog),o&&(console.info=this.realConsoleInfo),t&&(console.warn=this.realConsoleWarn),s&&this.removeOverrideError()}info(...e){return this.log(...e)}warn(...e){return this.log(...e)}alert(...e){if(this.isNode())return this.log(...e);e=e.join(" | ");alert(e)}assert(e,o=!0,...t){try{return"function"==typeof e?e(...t)!==o?(this.error("Asset failed"),!1):(this.options.hidePassingTests||this.log("SUCCESS: Assert passed"),!0):e!==o?(this.error("Assert failed"),!1):(this.options.hidePassingTests||this.log("SUCCESS: Assert passed"),!0)}catch(e){this.error("Unexpected error in assert")}return!1}}s.b8449304eec2797907cc7f2ee0c87c037a9af4d34da7ab5f57c5f4ef535d3667.default=new h,r=new h,s.b8449304eec2797907cc7f2ee0c87c037a9af4d34da7ab5f57c5f4ef535d3667.anaLogger=r}s.c30121e4056ba978b4fb451fa7489c6ff84e611cdca39ae86de3030d10e7073e={},s.c30121e4056ba978b4fb451fa7489c6ff84e611cdca39ae86de3030d10e7073e.LOG_CONTEXTS={STANDARD:{},TEST:{color:"#B18904",symbol:"⏰"},TEST2:{color:"rgb(127, 127, 127)",symbol:"⏰"},TEST3:{color:"blue",symbol:"⏰"},C1:null,C2:null,C3:null,DEFAULT:{}},s.c30121e4056ba978b4fb451fa7489c6ff84e611cdca39ae86de3030d10e7073e.LOG_TARGETS={ALL:"ALL",DEV1:"TOM",DEV2:"TIM",DEV3:"ME",USER:"USER"};{s.ca63110bb9882fce16420271e1c0aa1a22360931c93ababb90ba99d2da8a867c={};var{LOG_CONTEXTS:e,LOG_TARGETS:r}=s.c30121e4056ba978b4fb451fa7489c6ff84e611cdca39ae86de3030d10e7073e;let o=s.b8449304eec2797907cc7f2ee0c87c037a9af4d34da7ab5f57c5f4ef535d3667["anaLogger"];o.keepLogHistory(),o.setContexts(e),o.setTargets(r),o.setActiveTarget(r.DEV3),o.setOptions({logToDom:".analogger"}),o.setOptions({silent:!0}),console.log("=========================="),o.log(e.C1,"You should not see this C1"),o.log(e.C2,"You should not see this C2"),o.log(e.C3,"You should not see this C3"),o.setOptions({silent:!1,hideError:!1,logToFile:"./logme.log"}),o.log(e.C1,"You should see this C100"),o.log(e.C2,"You should see this C200"),o.log(e.C3,"You should see this C300"),console.log("============= From History ==========================="),console.log(o.getLogHistory()),console.log("============= From History (Closed) =================="),o.assert(!0),o.assert(!1),o.assert(()=>!0,!0),o.assert((e,o)=>e===o,!0,2,2),console.log("-------------------------- console.log is about to be overridden"),o.overrideConsole(),console.log("Log After override <= Console.log is overridden"),console.error("-------------------------- console.error is about to be overridden"),o.overrideError(),console.error("Hook on Error placed after override <= Console.error is also overridden"),console.log("=========================="),o.log(e.STANDARD,"Basic Log example 2","+Something 0","+Something 1"),o.log({context:e.TEST,lid:1e5},"Test Log example"),o.log({context:e.TEST,target:r.DEV3,lid:100001},"Test Log example with active target"),o.log({context:e.TEST,target:r.DEV1,lid:100002},"Test Log example with DEV1 target"),o.log({context:e.TEST,target:r.DEV2,lid:100003},"Test Log example with DEV2 target"),o.log("Test Log example with DEFAULT target"),o.log(e.TEST,"Test Log example","+Something 3"),o.log(e.C1,"Test Log example C1"),o.log(e.C2,"Test Log example C2"),o.log(e.C3,"Test Log example C3"),console.log(e.C1,"Test Log example C4"),console.log(e.C1,"Test Log example C5"),console.log(e.C1,"Test Log example C6"),console.error({context:e.ERROR,lid:2e5},"Testing Error 1"),console.error(e.ERROR,"Testing Error 2"),console.error("Testing Error 3"),console.error(void 0,"Testing Error 4"),console.error({context:e.ERROR,target:r.USER,lid:200010},"Testing Error 4"),o.info("Hello from alert",{aaa:1012}),o.setActiveTarget(r.USER),o.setErrorHandlerForUserTarget(function(e){o.log("User explicitly see this message"),o.info("User explicitly see this message",e)}),console.error({context:e.ERROR,target:r.USER,lid:200020},"Testing Error that triggers a special handler"),o.setLogFormat(function({contextName:e,message:o}){return e+": "+o}),console.log(e.C1,"Test Log example C4 with new format"),console.log(e.C1,"Test Log example C5 with new format"),console.log(e.C1,"Test Log example C6 with new format"),o.log("Basic Log example 1")}
|
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
* [./src/cjs/ana-logger.cjs]{@link ./src/cjs/ana-logger.cjs}
|
|
5
5
|
*
|
|
6
6
|
**/
|
|
7
|
-
import toAnsi from "
|
|
8
|
-
import rgbHex from "
|
|
9
|
-
import {COLOR_TABLE, SYSTEM} from "./constants.mjs";
|
|
7
|
+
import toAnsi from "./node_modules/to-ansi/index.mjs";
|
|
8
|
+
import rgbHex from "./node_modules/rgb-hex/index.mjs";
|
|
9
|
+
import {COLOR_TABLE, SYSTEM} from "./src/cjs/constants.mjs";
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "analogger",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.5",
|
|
4
4
|
"description": "Js Logger",
|
|
5
|
-
"main": "./
|
|
6
|
-
"module": "./generated/browser/
|
|
5
|
+
"main": "./src/cjs/ana-logger.cjs",
|
|
6
|
+
"module": "./generated/browser/ana-logger.mjs",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
10
|
-
"require": "./
|
|
11
|
-
"import": "./generated/browser/
|
|
10
|
+
"require": "./src/cjs/ana-logger.cjs",
|
|
11
|
+
"import": "./generated/browser/ana-logger.mjs"
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
14
|
"scripts": {
|
|
@@ -79,7 +79,8 @@
|
|
|
79
79
|
"rimraf": "^3.0.2",
|
|
80
80
|
"selenium-webdriver": "^4.1.1",
|
|
81
81
|
"semantic-release": "^19.0.2",
|
|
82
|
-
"sinon": "^13.0.1"
|
|
82
|
+
"sinon": "^13.0.1",
|
|
83
|
+
"to-esm": "file:../../../../projects/to-esm"
|
|
83
84
|
},
|
|
84
85
|
"dependencies": {
|
|
85
86
|
"chalk": "^5.0.0",
|
|
@@ -92,7 +93,7 @@
|
|
|
92
93
|
"rgb-hex": "^4.0.0",
|
|
93
94
|
"rgb-hex-cjs": "npm:rgb-hex@^3.0.0",
|
|
94
95
|
"to-ansi": "^1.0.5",
|
|
95
|
-
"to-esm": "
|
|
96
|
+
"to-esm": "file:../../../../projects/to-esm",
|
|
96
97
|
"uglify-js": "^3.15.1"
|
|
97
98
|
}
|
|
98
99
|
}
|
|
@@ -0,0 +1,807 @@
|
|
|
1
|
+
/** to-esm-browser: remove **/
|
|
2
|
+
const path = require("path");
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const os = require("os");
|
|
5
|
+
/** to-esm-browser: end-remove **/
|
|
6
|
+
|
|
7
|
+
const toAnsi = require("to-ansi");
|
|
8
|
+
const rgbHex = require("rgb-hex-cjs");
|
|
9
|
+
const {COLOR_TABLE, SYSTEM} = require("./constants.cjs");
|
|
10
|
+
|
|
11
|
+
const EOL =`
|
|
12
|
+
`;
|
|
13
|
+
|
|
14
|
+
class AnaLogger
|
|
15
|
+
{
|
|
16
|
+
system = "";
|
|
17
|
+
|
|
18
|
+
logIndex = 0;
|
|
19
|
+
logCounter = 0;
|
|
20
|
+
contexts = [];
|
|
21
|
+
targets = {};
|
|
22
|
+
|
|
23
|
+
activeTarget = null;
|
|
24
|
+
|
|
25
|
+
indexColor = 0;
|
|
26
|
+
|
|
27
|
+
format = "";
|
|
28
|
+
|
|
29
|
+
keepLog = false;
|
|
30
|
+
logHistory = [];
|
|
31
|
+
|
|
32
|
+
$containers = null;
|
|
33
|
+
|
|
34
|
+
options = {
|
|
35
|
+
hideHookMessage: false
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
static ALIGN = {
|
|
39
|
+
LEFT : "LEFT",
|
|
40
|
+
RIGHT: "RIGHT"
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
static ENVIRONMENT_TYPE = {
|
|
44
|
+
BROWSER: "BROWSER",
|
|
45
|
+
NODE : "NODE",
|
|
46
|
+
OTHER : "OTHER"
|
|
47
|
+
};
|
|
48
|
+
originalFormatFunction;
|
|
49
|
+
|
|
50
|
+
constructor()
|
|
51
|
+
{
|
|
52
|
+
if (AnaLogger.Instance)
|
|
53
|
+
{
|
|
54
|
+
return AnaLogger.Instance;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
AnaLogger.Instance = this;
|
|
58
|
+
|
|
59
|
+
this.system = (typeof process === "object") ? SYSTEM.NODE : SYSTEM.BROWSER;
|
|
60
|
+
this.format = this.onBuildLog.bind(this);
|
|
61
|
+
this.originalFormatFunction = this.format;
|
|
62
|
+
|
|
63
|
+
this.errorTargetHandler = this.onError.bind(this);
|
|
64
|
+
this.errorUserTargetHandler = this.onErrorForUserTarget.bind(this);
|
|
65
|
+
|
|
66
|
+
this.setOptions(this.options);
|
|
67
|
+
|
|
68
|
+
this.realConsoleLog = console.log;
|
|
69
|
+
this.realConsoleInfo = console.info;
|
|
70
|
+
this.realConsoleWarn = console.warn;
|
|
71
|
+
this.realConsoleError = console.error;
|
|
72
|
+
|
|
73
|
+
this.ALIGN = AnaLogger.ALIGN;
|
|
74
|
+
this.ENVIRONMENT_TYPE = AnaLogger.ENVIRONMENT_TYPE;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
keepLogHistory()
|
|
78
|
+
{
|
|
79
|
+
this.keepLog = true;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
releaseLogHistory()
|
|
83
|
+
{
|
|
84
|
+
this.keepLog = false;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
resetLogHistory()
|
|
88
|
+
{
|
|
89
|
+
this.logHistory = [];
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
getLogHistory(join = true, symbol = EOL)
|
|
93
|
+
{
|
|
94
|
+
const history = JSON.parse(JSON.stringify(this.logHistory.slice(0)));
|
|
95
|
+
if (!join)
|
|
96
|
+
{
|
|
97
|
+
return history;
|
|
98
|
+
}
|
|
99
|
+
return history.join(symbol);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Tell whether we are in a Node environment
|
|
104
|
+
* @returns {boolean}
|
|
105
|
+
*/
|
|
106
|
+
isNode()
|
|
107
|
+
{
|
|
108
|
+
return this.system === SYSTEM.NODE;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Tell whether the logger runs from a browser
|
|
113
|
+
* @returns {boolean}
|
|
114
|
+
*/
|
|
115
|
+
isBrowser()
|
|
116
|
+
{
|
|
117
|
+
return !this.isNode();
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
resetLogger()
|
|
121
|
+
{
|
|
122
|
+
this.options = {
|
|
123
|
+
contextLenMax : 10,
|
|
124
|
+
idLenMax : 5,
|
|
125
|
+
lidLenMax : 5,
|
|
126
|
+
symbolLenMax : 2,
|
|
127
|
+
messageLenMax : undefined,
|
|
128
|
+
hideLog : undefined,
|
|
129
|
+
hideError : undefined,
|
|
130
|
+
hideHookMessage : undefined,
|
|
131
|
+
hidePassingTests : undefined,
|
|
132
|
+
logToDom : undefined,
|
|
133
|
+
logToFile : undefined,
|
|
134
|
+
oneConsolePerContext: undefined,
|
|
135
|
+
silent : undefined
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
resetOptions()
|
|
140
|
+
{
|
|
141
|
+
this.options.contextLenMax = 10;
|
|
142
|
+
this.options.idLenMax = 5;
|
|
143
|
+
this.options.lidLenMax = 5;
|
|
144
|
+
this.options.messageLenMax = undefined;
|
|
145
|
+
this.options.symbolLenMax = 60;
|
|
146
|
+
this.options.hideHookMessage = false;
|
|
147
|
+
this.options.hidePassingTests = false;
|
|
148
|
+
this.options.hideLog = false;
|
|
149
|
+
this.options.hideError = false;
|
|
150
|
+
this.options.oneConsolePerContext = true;
|
|
151
|
+
this.options.logToDom = undefined;
|
|
152
|
+
this.options.logToDomlogToFile = undefined;
|
|
153
|
+
this.options.silent = false;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
setOptions({
|
|
157
|
+
contextLenMax = 10,
|
|
158
|
+
idLenMax = 5,
|
|
159
|
+
lidLenMax = 5,
|
|
160
|
+
symbolLenMax = 2,
|
|
161
|
+
messageLenMax = undefined,
|
|
162
|
+
hideLog = undefined,
|
|
163
|
+
hideError = undefined,
|
|
164
|
+
hideHookMessage = undefined,
|
|
165
|
+
hidePassingTests = undefined,
|
|
166
|
+
logToDom = undefined,
|
|
167
|
+
logToFile = undefined,
|
|
168
|
+
oneConsolePerContext = undefined,
|
|
169
|
+
silent = undefined
|
|
170
|
+
} = null)
|
|
171
|
+
{
|
|
172
|
+
this.options.contextLenMax = contextLenMax;
|
|
173
|
+
this.options.idLenMax = idLenMax;
|
|
174
|
+
this.options.lidLenMax = lidLenMax;
|
|
175
|
+
this.options.messageLenMax = messageLenMax;
|
|
176
|
+
this.options.symbolLenMax = symbolLenMax;
|
|
177
|
+
|
|
178
|
+
if (hidePassingTests !== undefined)
|
|
179
|
+
{
|
|
180
|
+
this.options.hidePassingTests = !!hidePassingTests;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (hideHookMessage !== undefined)
|
|
184
|
+
{
|
|
185
|
+
this.options.hideHookMessage = !!hideHookMessage;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (hideLog !== undefined)
|
|
189
|
+
{
|
|
190
|
+
this.options.hideLog = !!hideLog;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (hideError !== undefined)
|
|
194
|
+
{
|
|
195
|
+
this.options.hideError = !!hideError;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (oneConsolePerContext !== undefined)
|
|
199
|
+
{
|
|
200
|
+
this.options.oneConsolePerContext = !!oneConsolePerContext;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (logToDom !== undefined)
|
|
204
|
+
{
|
|
205
|
+
this.options.logToDom = logToDom || "#analogger";
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if (logToFile !== undefined)
|
|
209
|
+
{
|
|
210
|
+
if (!this.isBrowser())
|
|
211
|
+
{
|
|
212
|
+
this.options.logToFile = logToFile || "./analogger.log";
|
|
213
|
+
|
|
214
|
+
/** to-esm-browser: remove **/
|
|
215
|
+
// these require won't get compiled by to-esm
|
|
216
|
+
this.options.logToFilePath = path.resolve(this.options.logToFile);
|
|
217
|
+
this.logFile = fs.createWriteStream(this.options.logToFilePath, {flags : "a"});
|
|
218
|
+
this.EOL = os.EOL;
|
|
219
|
+
/** to-esm-browser: end-remove **/
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/** to-esm-browser: add
|
|
223
|
+
this.realConsoleLog("LogToFile is not supported in this environment. ")
|
|
224
|
+
* **/
|
|
225
|
+
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if (silent !== undefined)
|
|
229
|
+
{
|
|
230
|
+
this.options.silent = !!silent;
|
|
231
|
+
this.options.hideLog = this.options.silent;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
getOptions()
|
|
237
|
+
{
|
|
238
|
+
return this.options;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
truncateMessage(input = "", {fit = 0, align = AnaLogger.ALIGN.LEFT} = {})
|
|
242
|
+
{
|
|
243
|
+
input = "" + input;
|
|
244
|
+
if (fit && input.length >= fit + 2)
|
|
245
|
+
{
|
|
246
|
+
input = input.substring(0, fit - 3) + "...";
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
input = align === AnaLogger.ALIGN.LEFT ? input.padEnd(fit, " ") : input.padStart(fit, " ");
|
|
250
|
+
return input;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Format inputs
|
|
255
|
+
* @see Override {@link setLogFormat}
|
|
256
|
+
* @param contextName
|
|
257
|
+
* @param id
|
|
258
|
+
* @param message
|
|
259
|
+
* @param lid
|
|
260
|
+
* @param symbol
|
|
261
|
+
* @returns {string}
|
|
262
|
+
*/
|
|
263
|
+
onBuildLog({contextName, message = "", lid = "", symbol = ""} = {})
|
|
264
|
+
{
|
|
265
|
+
// Time
|
|
266
|
+
const date = new Date();
|
|
267
|
+
let time = ("0" + date.getHours()).slice(-2) + ":" + ("0" + date.getMinutes()).slice(-2) + ":" + ("0" + date.getSeconds()).slice(-2);
|
|
268
|
+
|
|
269
|
+
// Display content in columns
|
|
270
|
+
time = this.truncateMessage(time, {fit: 7});
|
|
271
|
+
contextName = this.truncateMessage(contextName, {fit: this.options.contextLenMax, align: AnaLogger.ALIGN.RIGHT});
|
|
272
|
+
// id = this.truncateMessage(id, {fit: this.options.idLenMax})
|
|
273
|
+
lid = this.truncateMessage(lid, {fit: this.options.lidLenMax});
|
|
274
|
+
|
|
275
|
+
if (this.options.messageLenMax !== undefined)
|
|
276
|
+
{
|
|
277
|
+
message = this.truncateMessage(message, {fit: this.options.messageLenMax});
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
symbol = this.truncateMessage(symbol, {fit: this.options.symbolLenMax});
|
|
281
|
+
|
|
282
|
+
return `[${time}] ${contextName}: (${lid}) ${symbol} ${message}`;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
onErrorForUserTarget(context, ...args)
|
|
286
|
+
{
|
|
287
|
+
this.errorUserTargetHandler(context, ...args);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
onError(context, ...args)
|
|
291
|
+
{
|
|
292
|
+
if (context.target === this.targets.USER)
|
|
293
|
+
{
|
|
294
|
+
this.onErrorForUserTarget(context, ...args);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Forward input to real console log
|
|
300
|
+
* @param args
|
|
301
|
+
*/
|
|
302
|
+
onDisplayLog(...args)
|
|
303
|
+
{
|
|
304
|
+
this.log(...args);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Forward input to real console log
|
|
309
|
+
* @param args
|
|
310
|
+
*/
|
|
311
|
+
onDisplayError(...args)
|
|
312
|
+
{
|
|
313
|
+
this.error(...args);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Set log template
|
|
318
|
+
* @param format
|
|
319
|
+
*/
|
|
320
|
+
setLogFormat(format)
|
|
321
|
+
{
|
|
322
|
+
if (typeof format !== "function")
|
|
323
|
+
{
|
|
324
|
+
console.error("Invalid parameter for setFormat. It is expecting a function or method.");
|
|
325
|
+
return false;
|
|
326
|
+
}
|
|
327
|
+
this.format = format.bind(this);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
resetLogFormatter()
|
|
331
|
+
{
|
|
332
|
+
this.format = this.originalFormatFunction;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
setErrorHandler(handler)
|
|
336
|
+
{
|
|
337
|
+
this.errorTargetHandler = handler.bind(this);
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
setErrorHandlerForUserTarget(handler)
|
|
341
|
+
{
|
|
342
|
+
this.errorUserTargetHandler = handler.bind(this);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// ------------------------------------------------
|
|
346
|
+
// Color
|
|
347
|
+
// ------------------------------------------------
|
|
348
|
+
|
|
349
|
+
// ------------------------------------------------
|
|
350
|
+
// Log Contexts
|
|
351
|
+
// ------------------------------------------------
|
|
352
|
+
isContextValid(context)
|
|
353
|
+
{
|
|
354
|
+
if (
|
|
355
|
+
!(typeof context === "object" &&
|
|
356
|
+
!Array.isArray(context) &&
|
|
357
|
+
context !== null)
|
|
358
|
+
)
|
|
359
|
+
{
|
|
360
|
+
return false;
|
|
361
|
+
}
|
|
362
|
+
return (context.hasOwnProperty("contextName") && context.hasOwnProperty("target"));
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
generateDefaultContext()
|
|
366
|
+
{
|
|
367
|
+
const defaultContext = {
|
|
368
|
+
name : "DEFAULT",
|
|
369
|
+
contextName: "DEFAULT",
|
|
370
|
+
target : "ALL",
|
|
371
|
+
symbol : "⚡"
|
|
372
|
+
};
|
|
373
|
+
|
|
374
|
+
defaultContext.id = this.logIndex++;
|
|
375
|
+
defaultContext.color = COLOR_TABLE[1];
|
|
376
|
+
return defaultContext;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
generateNewContext()
|
|
380
|
+
{
|
|
381
|
+
const newContext = this.generateDefaultContext();
|
|
382
|
+
newContext.color = COLOR_TABLE[(this.indexColor++) % (COLOR_TABLE.length - 3) + 2];
|
|
383
|
+
newContext.symbol = "";
|
|
384
|
+
return newContext;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
generateErrorContext()
|
|
388
|
+
{
|
|
389
|
+
const errorContext = this.generateDefaultContext();
|
|
390
|
+
errorContext.color = COLOR_TABLE[0];
|
|
391
|
+
errorContext.symbol = "v";
|
|
392
|
+
errorContext.error = true;
|
|
393
|
+
return errorContext;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
#allegeProperties(entry)
|
|
397
|
+
{
|
|
398
|
+
let converted = entry;
|
|
399
|
+
|
|
400
|
+
const defaultContext = this.generateNewContext();
|
|
401
|
+
|
|
402
|
+
converted = Object.assign({}, defaultContext, converted);
|
|
403
|
+
|
|
404
|
+
if (converted.color.toLowerCase().indexOf("rgb") > -1)
|
|
405
|
+
{
|
|
406
|
+
converted.color = "#" + rgbHex(converted.color);
|
|
407
|
+
}
|
|
408
|
+
else if (converted.color.indexOf("#") === -1)
|
|
409
|
+
{
|
|
410
|
+
const colorConvert = require("color-convert-cjs");
|
|
411
|
+
if (colorConvert)
|
|
412
|
+
{
|
|
413
|
+
converted.color = "#" + colorConvert.keyword.hex(converted.color);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
return converted;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* Load the context names that should be available to the environment.
|
|
422
|
+
* They are defined by the user.
|
|
423
|
+
* @see Context definitions {@link ./example/cjs/contexts-def.cjs}
|
|
424
|
+
* @param contextTable
|
|
425
|
+
*/
|
|
426
|
+
setContexts(contextTable)
|
|
427
|
+
{
|
|
428
|
+
const arr = Object.keys(contextTable);
|
|
429
|
+
contextTable["DEFAULT"] = this.contexts["DEFAULT"] = this.generateDefaultContext();
|
|
430
|
+
contextTable["ERROR"] = this.contexts["ERROR"] = this.generateErrorContext();
|
|
431
|
+
arr.forEach((key) =>
|
|
432
|
+
{
|
|
433
|
+
const contextPassed = contextTable[key] || {};
|
|
434
|
+
contextPassed.contextName = key;
|
|
435
|
+
contextPassed.name = key;
|
|
436
|
+
this.contexts[key] = this.#allegeProperties(contextPassed);
|
|
437
|
+
contextTable[key] = this.contexts[key];
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
setTargets(targetTable = {})
|
|
442
|
+
{
|
|
443
|
+
this.targets = Object.assign({}, targetTable, {ALL: "ALL", USER: "USER"});
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
setActiveTarget(target)
|
|
447
|
+
{
|
|
448
|
+
this.activeTarget = target;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
isTargetAllowed(target)
|
|
452
|
+
{
|
|
453
|
+
if (!target || !this.activeTarget)
|
|
454
|
+
{
|
|
455
|
+
return true;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
if (target === this.targets.ALL)
|
|
459
|
+
{
|
|
460
|
+
return true;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
return this.activeTarget === target;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
|
|
467
|
+
// ------------------------------------------------
|
|
468
|
+
// Logging methods
|
|
469
|
+
// ------------------------------------------------
|
|
470
|
+
setColumns($line, context, text)
|
|
471
|
+
{
|
|
472
|
+
let index = 0;
|
|
473
|
+
for (let columnName in context)
|
|
474
|
+
{
|
|
475
|
+
if ("name" === columnName)
|
|
476
|
+
{
|
|
477
|
+
continue;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
const colContent = context[columnName];
|
|
481
|
+
const $col = document.createElement("span");
|
|
482
|
+
$col.classList.add("analogger-col", `analogger-col-${columnName}`, `analogger-col-${index}`);
|
|
483
|
+
++index;
|
|
484
|
+
$col.textContent = colContent;
|
|
485
|
+
$line.append($col);
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
const $col = document.createElement("span");
|
|
489
|
+
$col.classList.add("analogger-col", "analogger-col-text", `analogger-col-${index}`);
|
|
490
|
+
$col.textContent = text;
|
|
491
|
+
$line.append($col);
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
writeLogToDom(context, text)
|
|
495
|
+
{
|
|
496
|
+
this.$containers = this.$containers || document.querySelectorAll(this.options.logToDom);
|
|
497
|
+
|
|
498
|
+
for (let i = 0; i < this.$containers.length; ++i)
|
|
499
|
+
{
|
|
500
|
+
const $container = this.$containers[i];
|
|
501
|
+
|
|
502
|
+
let $view = $container.querySelector(".analogger-view");
|
|
503
|
+
if (!$view)
|
|
504
|
+
{
|
|
505
|
+
$view = document.createElement("div");
|
|
506
|
+
$view.classList.add("analogger-view");
|
|
507
|
+
$container.append($view);
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
const $line = document.createElement("div");
|
|
511
|
+
$line.classList.add("to-esm-line");
|
|
512
|
+
$line.style.color = context.color;
|
|
513
|
+
$line.setAttribute("data-log-counter", this.logCounter);
|
|
514
|
+
$line.setAttribute("data-log-index", this.logIndex);
|
|
515
|
+
|
|
516
|
+
this.setColumns($line ,context, text);
|
|
517
|
+
|
|
518
|
+
$view.append($line);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
writeLogToFile(text)
|
|
523
|
+
{
|
|
524
|
+
this.logFile.write(text + this.EOL);
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
/**
|
|
528
|
+
* Display log following template
|
|
529
|
+
* @param context
|
|
530
|
+
*/
|
|
531
|
+
processOutput(context = {})
|
|
532
|
+
{
|
|
533
|
+
try
|
|
534
|
+
{
|
|
535
|
+
if (!this.isTargetAllowed(context.target))
|
|
536
|
+
{
|
|
537
|
+
return;
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
let args = Array.prototype.slice.call(arguments);
|
|
541
|
+
args.shift();
|
|
542
|
+
|
|
543
|
+
const message = args.join(" | ");
|
|
544
|
+
|
|
545
|
+
let output = "";
|
|
546
|
+
const text = this.format({...context, message});
|
|
547
|
+
|
|
548
|
+
++this.logCounter;
|
|
549
|
+
|
|
550
|
+
if (this.isBrowser())
|
|
551
|
+
{
|
|
552
|
+
context.environnment = AnaLogger.ENVIRONMENT_TYPE.BROWSER;
|
|
553
|
+
if (this.options.logToDom)
|
|
554
|
+
{
|
|
555
|
+
this.writeLogToDom(context, text);
|
|
556
|
+
}
|
|
557
|
+
output = `%c${text}`;
|
|
558
|
+
}
|
|
559
|
+
else
|
|
560
|
+
{
|
|
561
|
+
context.environnment = AnaLogger.ENVIRONMENT_TYPE.NODE;
|
|
562
|
+
output = toAnsi.getTextFromHex(text, {fg: context.color});
|
|
563
|
+
|
|
564
|
+
if (this.options.logToFile)
|
|
565
|
+
{
|
|
566
|
+
this.writeLogToFile(text);
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
if (this.keepLog)
|
|
571
|
+
{
|
|
572
|
+
this.logHistory.push(output);
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
if (this.options.hideLog)
|
|
576
|
+
{
|
|
577
|
+
return;
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
if (this.isBrowser())
|
|
581
|
+
{
|
|
582
|
+
this.realConsoleLog(output, `color: ${context.color}`);
|
|
583
|
+
}
|
|
584
|
+
else
|
|
585
|
+
{
|
|
586
|
+
this.realConsoleLog(output);
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
this.errorTargetHandler(context, args);
|
|
590
|
+
}
|
|
591
|
+
catch (e)
|
|
592
|
+
{
|
|
593
|
+
/* istanbul ignore next */
|
|
594
|
+
console.error("AnaLogger:", e.message);
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
/**
|
|
599
|
+
* Check that a parameter (should be the first) uses the expected format.
|
|
600
|
+
* @param options
|
|
601
|
+
* @returns {boolean}
|
|
602
|
+
*/
|
|
603
|
+
isExtendedOptionsPassed(options)
|
|
604
|
+
{
|
|
605
|
+
if (typeof options !== "object")
|
|
606
|
+
{
|
|
607
|
+
return false;
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
return options.hasOwnProperty("context") ||
|
|
611
|
+
options.hasOwnProperty("target") ||
|
|
612
|
+
options.hasOwnProperty("color") ||
|
|
613
|
+
options.hasOwnProperty("lid");
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
convertToContext(options, defaultContext)
|
|
617
|
+
{
|
|
618
|
+
defaultContext = defaultContext || this.generateDefaultContext();
|
|
619
|
+
options = options || defaultContext;
|
|
620
|
+
let context = options;
|
|
621
|
+
if (options.context && typeof options.context === "object")
|
|
622
|
+
{
|
|
623
|
+
const moreOptions = Object.assign({}, options);
|
|
624
|
+
delete moreOptions.context;
|
|
625
|
+
context = Object.assign({}, options.context, moreOptions);
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
context = Object.assign({}, defaultContext, context);
|
|
629
|
+
delete context.context;
|
|
630
|
+
|
|
631
|
+
return context;
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
/**
|
|
635
|
+
* console.log with options set on the first parameter to dictate console log behaviours
|
|
636
|
+
* @param options
|
|
637
|
+
* @param args
|
|
638
|
+
*/
|
|
639
|
+
log(options, ...args)
|
|
640
|
+
{
|
|
641
|
+
if (!this.isExtendedOptionsPassed(options))
|
|
642
|
+
{
|
|
643
|
+
const defaultContext = this.generateDefaultContext();
|
|
644
|
+
this.processOutput.apply(this, [defaultContext, options, ...args]);
|
|
645
|
+
return;
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
let context = this.convertToContext(options);
|
|
649
|
+
|
|
650
|
+
this.processOutput.apply(this, [context, ...args]);
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
error(options, ...args)
|
|
654
|
+
{
|
|
655
|
+
if (this.options.hideError)
|
|
656
|
+
{
|
|
657
|
+
return;
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
if (!this.isExtendedOptionsPassed(options))
|
|
661
|
+
{
|
|
662
|
+
const defaultContext = this.generateErrorContext();
|
|
663
|
+
this.processOutput.apply(this, [defaultContext, options, ...args]);
|
|
664
|
+
return;
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
const errorContext = this.generateErrorContext();
|
|
668
|
+
let context = this.convertToContext(options, errorContext);
|
|
669
|
+
|
|
670
|
+
let args0 = Array.prototype.slice.call(arguments, 1);
|
|
671
|
+
this.log(context, ...args0);
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
overrideError()
|
|
675
|
+
{
|
|
676
|
+
if (!this.options.hideHookMessage)
|
|
677
|
+
{
|
|
678
|
+
this.realConsoleLog("AnaLogger: Hook placed on console.error");
|
|
679
|
+
}
|
|
680
|
+
console.error = this.onDisplayError.bind(this);
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
overrideConsole({log = true, info = true, warn = true, error = false} = {})
|
|
684
|
+
{
|
|
685
|
+
if (!this.options.hideHookMessage)
|
|
686
|
+
{
|
|
687
|
+
this.realConsoleLog("AnaLogger: Hook placed on console.log");
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
if (log)
|
|
691
|
+
{
|
|
692
|
+
console.log = this.onDisplayLog.bind(this);
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
if (info)
|
|
696
|
+
{
|
|
697
|
+
console.info = this.onDisplayLog.bind(this);
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
if (warn)
|
|
701
|
+
{
|
|
702
|
+
console.warn = this.onDisplayLog.bind(this);
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
if (error)
|
|
706
|
+
{
|
|
707
|
+
this.overrideError();
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
removeOverrideError()
|
|
712
|
+
{
|
|
713
|
+
console.warn = this.realConsoleError;
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
removeOverride({log = true, info = true, warn = true, error = false} = {})
|
|
717
|
+
{
|
|
718
|
+
if (log)
|
|
719
|
+
{
|
|
720
|
+
console.log = this.realConsoleLog;
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
if (info)
|
|
724
|
+
{
|
|
725
|
+
console.info = this.realConsoleInfo;
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
if (warn)
|
|
729
|
+
{
|
|
730
|
+
console.warn = this.realConsoleWarn;
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
if (error)
|
|
734
|
+
{
|
|
735
|
+
this.removeOverrideError();
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
info(...args)
|
|
741
|
+
{
|
|
742
|
+
return this.log(...args);
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
warn(...args)
|
|
746
|
+
{
|
|
747
|
+
return this.log(...args);
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
alert(...args)
|
|
751
|
+
{
|
|
752
|
+
if (this.isNode())
|
|
753
|
+
{
|
|
754
|
+
return this.log(...args);
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
const message = args.join(" | ");
|
|
758
|
+
|
|
759
|
+
alert(message);
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
assert(condition, expected = true, ...args)
|
|
763
|
+
{
|
|
764
|
+
let result;
|
|
765
|
+
|
|
766
|
+
try
|
|
767
|
+
{
|
|
768
|
+
if (typeof condition === "function")
|
|
769
|
+
{
|
|
770
|
+
result = condition(...args);
|
|
771
|
+
if (result !== expected)
|
|
772
|
+
{
|
|
773
|
+
this.error("Asset failed");
|
|
774
|
+
return false;
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
if (!this.options.hidePassingTests)
|
|
778
|
+
{
|
|
779
|
+
this.log("SUCCESS: Assert passed");
|
|
780
|
+
}
|
|
781
|
+
return true;
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
if (condition !== expected)
|
|
785
|
+
{
|
|
786
|
+
this.error("Assert failed");
|
|
787
|
+
return false;
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
if (!this.options.hidePassingTests)
|
|
791
|
+
{
|
|
792
|
+
this.log("SUCCESS: Assert passed");
|
|
793
|
+
}
|
|
794
|
+
return true;
|
|
795
|
+
}
|
|
796
|
+
catch (e)
|
|
797
|
+
{
|
|
798
|
+
this.error("Unexpected error in assert");
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
return false;
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
module.exports = new AnaLogger();
|
|
807
|
+
module.exports.anaLogger = new AnaLogger();
|
package/src/cjs/bump.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// Bump version to fix failing build
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const constants = {
|
|
2
|
+
COLOR_TABLE: [
|
|
3
|
+
"#d2466e", // Error context color
|
|
4
|
+
"#FFA07A", // Default context color
|
|
5
|
+
"#FF7F50",
|
|
6
|
+
"#FF6347",
|
|
7
|
+
"#FFE4B5",
|
|
8
|
+
"#ADFF2F",
|
|
9
|
+
"#808000",
|
|
10
|
+
"#40E0D0",
|
|
11
|
+
"#1E90FF",
|
|
12
|
+
"#EE82EE",
|
|
13
|
+
"#708090",
|
|
14
|
+
"#DEB887",
|
|
15
|
+
"#FE642E",
|
|
16
|
+
"#210B61",
|
|
17
|
+
"#088A4B",
|
|
18
|
+
"#5E610B",
|
|
19
|
+
"#FA8258",
|
|
20
|
+
"#088A68",
|
|
21
|
+
"#B40431",
|
|
22
|
+
],
|
|
23
|
+
SYSTEM: {
|
|
24
|
+
BROWSER: "BROWSER",
|
|
25
|
+
NODE: "NODE"
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
module.exports.COLOR_TABLE = constants.COLOR_TABLE;
|
|
31
|
+
module.exports.SYSTEM = constants.SYSTEM;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
<component name="ProjectRunConfigurationManager">
|
|
2
|
-
<configuration default="false" name="Debuggable demo" type="js.build_tools.npm">
|
|
3
|
-
<package-json value="$PROJECT_DIR$/package.json" />
|
|
4
|
-
<command value="run" />
|
|
5
|
-
<scripts>
|
|
6
|
-
<script value="quick:run" />
|
|
7
|
-
</scripts>
|
|
8
|
-
<node-interpreter value="project" />
|
|
9
|
-
<envs />
|
|
10
|
-
<method v="2" />
|
|
11
|
-
</configuration>
|
|
12
|
-
</component>
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
<component name="ProjectRunConfigurationManager">
|
|
2
|
-
<configuration default="false" name="Demo in browser with importmap" type="js.build_tools.npm">
|
|
3
|
-
<package-json value="$PROJECT_DIR$/package.json" />
|
|
4
|
-
<command value="run" />
|
|
5
|
-
<scripts>
|
|
6
|
-
<script value="build:browser:importmap" />
|
|
7
|
-
</scripts>
|
|
8
|
-
<node-interpreter value="project" />
|
|
9
|
-
<envs />
|
|
10
|
-
<method v="2" />
|
|
11
|
-
</configuration>
|
|
12
|
-
</component>
|