UNPKG

app-lib-log

Version:

个人日志组件 -【app-lib-log】

2 lines 15.5 kB
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var r=t();for(var o in r)("object"==typeof exports?exports:e)[o]=r[o]}}(this,(()=>(()=>{var e={798:function(e){var t;t=()=>(()=>{"use strict";var e={d:(t,r)=>{for(var o in r)e.o(r,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:r[o]})}};e.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),e.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),e.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var t={};e.r(t),e.d(t,{ENV:()=>r,bindToGlobal:()=>a,default:()=>c,getEnv:()=>o,getGlobal:()=>l,getbindData:()=>s,isBindToGlobal:()=>u,isBroswerEnv:()=>i,isNodeEnv:()=>n});const r={NODE:"node",BROWSER:"browser"},o=()=>"undefined"!=typeof process&&null!=process.release&&"node"===process.release.name?r.NODE:r.BROWSER,n=()=>o()===r.NODE,i=()=>o()===r.BROWSER,l=()=>e.g,s=e=>{let t=l();if(!t)throw new Error("未找到当前环境的全局变量");return t[e]},a=(e,t,r)=>u(e)&&!r?s(e):(l()[e]=t,t),u=(e,t)=>{if(!e)throw new Error("必须执行绑定名称");let r=l();if(!r)throw new Error("未找到当前环境的全局变量");let o=r[e];return void 0!==o&&(null==t||o===t||JSON.stringify(o)===JSON.stringify(t))},c=a;return t})(),e.exports=t()}},t={};function r(o){var n=t[o];if(void 0!==n)return n.exports;var i=t[o]={exports:{}};return e[o].call(i.exports,i,i.exports,r),i.exports}r.d=(e,t)=>{for(var o in t)r.o(t,o)&&!r.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};return(()=>{"use strict";r.r(o),r.d(o,{ALL_FUNCTIONS:()=>R,LEVEL:()=>j,Logger:()=>ge,TYPE:()=>N,create:()=>de,default:()=>he,log:()=>be});const e=(e=0)=>t=>`[${t+e}m`,t=(e=0)=>t=>`[${38+e};5;${t}m`,n=(e=0)=>(t,r,o)=>`[${38+e};2;${t};${r};${o}m`,i={modifier:{reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],overline:[53,55],inverse:[7,27],hidden:[8,28],strikethrough:[9,29]},color:{black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],blackBright:[90,39],gray:[90,39],grey:[90,39],redBright:[91,39],greenBright:[92,39],yellowBright:[93,39],blueBright:[94,39],magentaBright:[95,39],cyanBright:[96,39],whiteBright:[97,39]},bgColor:{bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],bgBlackBright:[100,49],bgGray:[100,49],bgGrey:[100,49],bgRedBright:[101,49],bgGreenBright:[102,49],bgYellowBright:[103,49],bgBlueBright:[104,49],bgMagentaBright:[105,49],bgCyanBright:[106,49],bgWhiteBright:[107,49]}};Object.keys(i.modifier),Object.keys(i.color),Object.keys(i.bgColor);const l=function(){const r=new Map;for(const[e,t]of Object.entries(i)){for(const[e,o]of Object.entries(t))i[e]={open:`[${o[0]}m`,close:`[${o[1]}m`},t[e]=i[e],r.set(o[0],o[1]);Object.defineProperty(i,e,{value:t,enumerable:!1})}return Object.defineProperty(i,"codes",{value:r,enumerable:!1}),i.color.close="",i.bgColor.close="",i.color.ansi=e(),i.color.ansi256=t(),i.color.ansi16m=n(),i.bgColor.ansi=e(10),i.bgColor.ansi256=t(10),i.bgColor.ansi16m=n(10),Object.defineProperties(i,{rgbToAnsi256:{value:(e,t,r)=>e===t&&t===r?e<8?16:e>248?231:Math.round((e-8)/247*24)+232:16+36*Math.round(e/255*5)+6*Math.round(t/255*5)+Math.round(r/255*5),enumerable:!1},hexToRgb:{value(e){const t=/[a-f\d]{6}|[a-f\d]{3}/i.exec(e.toString(16));if(!t)return[0,0,0];let[r]=t;3===r.length&&(r=[...r].map((e=>e+e)).join(""));const o=Number.parseInt(r,16);return[o>>16&255,o>>8&255,255&o]},enumerable:!1},hexToAnsi256:{value:e=>i.rgbToAnsi256(...i.hexToRgb(e)),enumerable:!1},ansi256ToAnsi:{value(e){if(e<8)return 30+e;if(e<16)return e-8+90;let t,r,o;if(e>=232)t=(10*(e-232)+8)/255,r=t,o=t;else{const n=(e-=16)%36;t=Math.floor(e/36)/5,r=Math.floor(n/6)/5,o=n%6/5}const n=2*Math.max(t,r,o);if(0===n)return 30;let i=30+(Math.round(o)<<2|Math.round(r)<<1|Math.round(t));return 2===n&&(i+=60),i},enumerable:!1},rgbToAnsi:{value:(e,t,r)=>i.ansi256ToAnsi(i.rgbToAnsi256(e,t,r)),enumerable:!1},hexToAnsi:{value:e=>i.ansi256ToAnsi(i.hexToAnsi256(e)),enumerable:!1}}),i}();let s=!1;"undefined"!=typeof navigator&&(s=navigator&&navigator.userAgentData?navigator.userAgentData.brands.some((({brand:e})=>"Chromium"===e)):/\b(Chrome|Chromium)\//.test(navigator.userAgent));const a=!!s&&{level:1,hasBasic:!0,has256:!1,has16m:!1},u={stdout:a,stderr:a};function c(e,t,r){let o=e.indexOf(t);if(-1===o)return e;const n=t.length;let i=0,l="";do{l+=e.slice(i,o)+t+r,i=o+n,o=e.indexOf(t,i)}while(-1!==o);return l+=e.slice(i),l}const{stdout:f,stderr:g}=u,d=Symbol("GENERATOR"),b=Symbol("STYLER"),h=Symbol("IS_EMPTY"),p=["ansi","ansi","ansi256","ansi16m"],m=Object.create(null),x=e=>{const t=(...e)=>e.join(" ");return((e,t={})=>{if(t.level&&!(Number.isInteger(t.level)&&t.level>=0&&t.level<=3))throw new Error("The `level` option should be an integer from 0 to 3");const r=f?f.level:0;e.level=void 0===t.level?r:t.level})(t,e),Object.setPrototypeOf(t,T.prototype),t};function T(e){return x(e)}Object.setPrototypeOf(T.prototype,Function.prototype);for(const[e,t]of Object.entries(l))m[e]={get(){const r=O(this,y(t.open,t.close,this[b]),this[h]);return Object.defineProperty(this,e,{value:r}),r}};m.visible={get(){const e=O(this,this[b],!0);return Object.defineProperty(this,"visible",{value:e}),e}};const v=(e,t,r,...o)=>"rgb"===e?"ansi16m"===t?l[r].ansi16m(...o):"ansi256"===t?l[r].ansi256(l.rgbToAnsi256(...o)):l[r].ansi(l.rgbToAnsi(...o)):"hex"===e?v("rgb",t,r,...l.hexToRgb(...o)):l[r][e](...o),E=["rgb","hex","ansi256"];for(const e of E)m[e]={get(){const{level:t}=this;return function(...r){const o=y(v(e,p[t],"color",...r),l.color.close,this[b]);return O(this,o,this[h])}}},m["bg"+e[0].toUpperCase()+e.slice(1)]={get(){const{level:t}=this;return function(...r){const o=y(v(e,p[t],"bgColor",...r),l.bgColor.close,this[b]);return O(this,o,this[h])}}};const w=Object.defineProperties((()=>{}),{...m,level:{enumerable:!0,get(){return this[d].level},set(e){this[d].level=e}}}),y=(e,t,r)=>{let o,n;return void 0===r?(o=e,n=t):(o=r.openAll+e,n=t+r.closeAll),{open:e,close:t,openAll:o,closeAll:n,parent:r}},O=(e,t,r)=>{const o=(...e)=>A(o,1===e.length?""+e[0]:e.join(" "));return Object.setPrototypeOf(o,w),o[d]=e,o[b]=t,o[h]=r,o},A=(e,t)=>{if(e.level<=0||!t)return e[h]?"":t;let r=e[b];if(void 0===r)return t;const{openAll:o,closeAll:n}=r;if(t.includes(""))for(;void 0!==r;)t=c(t,r.close,r.open),r=r.parent;const i=t.indexOf("\n");return-1!==i&&(t=function(e,t,r,o){let n=0,i="";do{const l="\r"===e[o-1];i+=e.slice(n,l?o-1:o)+t+(l?"\r\n":"\n")+r,n=o+1,o=e.indexOf("\n",n)}while(-1!==o);return i+=e.slice(n),i}(t,n,o,i)),o+t+n};Object.defineProperties(T.prototype,m),T(),T({level:g?g.level:0});var C=r(798);const R=[],L=(0,C.isBroswerEnv)(),_=(0,C.getEnv)(),B=new class{constructor(e){return x(e)}}({level:2}),N={TRACE:"trace",DEBUG:"debug",INFO:"info",LOG:"log",SUCCESS:"success",TABLE:"table",TIME:"time",WARN:"warn",ERROR:"error"},j={trace:10,debug:20,info:30,log:31,success:32,table:33,time:40,warn:60,error:70},S={node:{maxCharLength:9,textAlgin:"right",space:"",module:{background:"#0a0afb",color:"#ffffff"},trace:{background:"#4a4848",color:"#ffffff"},debug:{background:"#4a4848",color:"#ffffff",index:" "},info:{background:"#08df08",color:"#ffffff",index:" "},success:{background:"#0808ef",color:"#ffffff",index:" "},warn:{background:"#ffff08",color:"#ff0000"},error:{background:"#f50303",color:"#ffffff"},time:{background:"#47b2b2",color:"#ffffff",index:" "}},browser:{maxCharLength:9,textAlgin:"right",index:"background: transparent;margin-left:4px;",space:"background: transparent;",trace:"background: linear-gradient(90deg, #b7b2b2,#8080804d, #b7b2b2); color:white; font-weight:bold; border-radius: 1px; ",debug:"background:linear-gradient(70deg, #b7b2b2, #8080804d, #b7b2b2); color:white; font-weight:bold; border-radius: 1px;",info:"background: linear-gradient(70deg, #00800085, #57d4c1,#57d4c1, #00800085); color:white; font-weight:bold;border-radius: 1px;",success:"background: linear-gradient(70deg, #172bdca1, #0000ff36, #172bdca1); color:white; font-weight:bold;border-radius: 1px;",time:"background: linear-gradient(70deg, #00bfffcf,#00bfff4f,#00bfffcf); color:white; font-weight:bold;border-radius: 1px;",warn:"background: linear-gradient(90deg, #eab60e, #eab60e6e, #eab60e); color:yellow; font-weight:bold; border-radius: 1px;",error:"background: linear-gradient(90deg, #ff00006b, #ff000033,#ff000033, #ff00006b); color:red; font-weight:bold; border-radius: 1px;",dateTime:"background: none; border: 1px #ad10da4d solid; color:#ad10dacf; font-weight:bold; border-radius: 1px;",module:"background: linear-gradient(70deg, #0a0afb, #44448a); color:white; font-weight:bold; border-radius: 1px;padding:0 5px"}},k={bindGlobalName:"log",level:100,moduleName:"",isModule:!1,isColorful:!0,colorful:S[_],LEVEL:j,dateFormatter:"YYYY-MM-DD HH:mm:ss",onLogger:null,logFn:console},M=(e,t)=>{var r={"M+":e.getMonth()+1,"D+":e.getDate(),"H+":e.getHours(),"m+":e.getMinutes(),"s+":e.getSeconds()};for(var o in/(Y+)/.test(t)&&(t=t.replace(RegExp.$1,(e.getFullYear()+"").substr(4-RegExp.$1.length))),r)new RegExp("("+o+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?r[o]:("00"+r[o]).substr((""+r[o]).length)));return t},F=function(){};function P(e,t){let{indent:r,width:o,algin:n,color:i,background:l}=t;return be.fill(r||0)+be.tx(be.autoFillText(e,o,n),i,l)}function I(e,t,r){let o=B.hex(t||"#ffffff");return r&&(o=o.bgHex(r)),o(e)}function D(e,t,r){return this.tx(e,t,r)}function G(e=N.INFO,t="",r=!0){let{background:o,color:n}=S.node[e]||S.node[N.INFO],i=B.hex(n||o||"#ffffff");return r&&o&&(i=i.bgHex(o)),i(t)}function W(e=N.INFO,t="",r=!1){k.logFn.log.apply(null,this.tl(e,t,r))}function $(e,t,r){if(!["object","undefined"].includes(typeof r))return this.error("transLevelTextColorAndLog(level,text,chalkOption) 方法参数 chalkOption 传递错误,请传递{ bg, color }对象形式");let o=e?this._getTerminalColorfulArguments(e):[];o=o.length?[o.join("")]:o;let{background:n}=S.node[e],{bg:i,color:l}=r||{color:n||"#ffffff"},s=B.hex(l||n||"#ffffff");return i&&(s=s.bgHex(i)),o.push(s(" "+t+" ")),o.join("")}function Y(...e){return this.exe(N.TRACE,e)}function H(...e){return this.exe(N.DEBUG,[...arguments])}function U(...e){return this.exe(N.INFO,[...arguments])}function V(...e){return this.exe(N.LOG,[...arguments])}function J(...e){return this.exe(N.SUCCESS,[...arguments])}function q(...e){return this.exe(N.TIME,[...arguments])}function z(...e){return this.exe(N.TABLE,[...arguments])}function K(...e){return this.exe(N.WARN,[...arguments])}function Q(...e){return this.exe(N.WARN,[...arguments],{noTrace:!0})}function X(...e){return this.exe(N.ERROR,[...arguments])}function Z(...e){return this.exe(N.ERROR,[...arguments],{noTrace:!0})}function ee(...e){return this._mExecute(N.TRACE,[...arguments])}function te(...e){return this._mExecute(N.DEBUG,[...arguments])}function re(...e){return this._mExecute(N.INFO,[...arguments])}function oe(...e){return this._mExecute(N.LOG,[...arguments])}function ne(...e){return this._mExecute(N.SUCCESS,[...arguments])}function ie(...e){return this._mExecute(N.TIME,[...arguments])}function le(...e){return this._mExecute(N.TABLE,[...arguments])}function se(...e){return this._mExecute(N.WARN,[...arguments])}function ae(...e){return this._mExecute(N.WARN,[...arguments],{noTrace:!0})}function ue(...e){return this._mExecute(N.ERROR,[...arguments])}function ce(...e){return this._mExecute(N.ERROR,[...arguments],{noTrace:!0})}const fe={setOption:function(e){return this.option={...this.option,...e},this.option},getOption:function(){return this.option},auotLogLevel:F,auotLevel:F,autoFillText:function(e,t,r="right"){let o=this.option.colorful.maxCharLength;return this._autoFillLength(t||o,e,r)},fill:function(e,t){return this._fill(e,t)},transTextColorBlock:P,tb:P,trace:Y,debug:H,info:U,log:V,success:J,time:q,table:z,warn:K,warnNoTrace:Q,error:X,errorNoTrace:Z,t:Y,d:H,i:U,l:V,s:J,tt:q,T:z,w:K,wn:Q,e:X,en:Z,mTrace:ee,mDebug:te,mInfo:re,mLog:oe,mSuccess:ne,mTime:ie,mTable:le,mWarn:se,mWarnNoTrace:ae,mError:ue,mErrorNoTrace:ce,mt:ee,md:te,mi:re,ml:oe,ms:ne,mtt:ie,mT:le,mw:se,mwn:ae,me:ue,men:ce,transTextColor:I,transTextColorAndLog:D,transLevelTextColor:G,transLevelTextColorAndLog:W,transLevelHeaderAndLog:$,tx:I,txl:D,tl:G,tll:W,tlh:$};class ge{constructor(e){this.option={...k,...e},(e=>{for(let t in fe)e[t]=fe[t]})(this)}_isIndex(e){return![N.TRACE,N.WARN,N.ERROR].includes(e)}_getSpace(e){let t="";for(let r=0;r<e;r++)t+=" ";return t}_getAlgin(e,t,r){let o=r-e.length,n=0,i=1;return"center"===t?(n=Math.floor(o/2),i=Math.ceil(o/2)):n=o-1,"%c"+this._getSpace(n)+e.toLowerCase()+this._getSpace(i)}_getBroswerColorfulArguments(e){let{isColorful:t,colorful:r,moduleName:o,dateFormatter:n}=this.option,{textAlgin:i,maxCharLength:l,index:s,space:a,module:u,dateTime:c}=r;if(!t)return[];let f="",g=[];if(this._isIndex(e)&&(f+="%c ",g.push(s)),f+=this._getAlgin(e,i,l),g.push(r[e.toLowerCase()]),o&&(f+="%c %c%s",g=g.concat([a,u,o])),e===N.TIME){f+="%c %c%s";let e="string"==typeof n?M(new Date,n):n(new Date);g=g.concat([a,c,e])}return[f].concat(g)}_fill(e,t=" "){let r=[];for(let o=0;o<e;o++)r.push(t);return r.join("")}_getPosition(e){let t=e/2;return[Math.ceil(t),Math.floor(t)]}_autoFillLength(e,t,r="right"){let o=e-(t+=" ").length;if("center"===r){let[e,r]=this._getPosition(o);return this._fill(e)+t+this._fill(r)}return o<=0?t:"right"==r?this._fill(o)+t:t+this._fill(o)}_getTerminalColorfulArguments(e,t={}){let{isColorful:r,colorful:o,moduleName:n,dateFormatter:i}=this.option;if(!r)return[];let{textAlgin:l,maxCharLength:s,space:a,module:u}=o,{background:c,color:f,index:g}=o[e]||o.trace,d=[];(t.noTrace||g)&&d.push(t.noTrace?o.debug.index:g);let b=this._autoFillLength(s,e.toLowerCase(),l);if(d.push(B.bgHex(c).hex(f)(b)),d.push(a),n&&d.push(B.bgHex(u.background).hex(u.color)(" "+n+" ")),e===N.TIME){let e="string"==typeof i?M(new Date,i):i(new Date);d=d.concat([e])}return d}_output(e,t,r,o={}){let{onLogger:n,level:i}=this.option;if("number"==typeof i){if(i>this.option.LEVEL[e])return}else if(Array.isArray(i)&&!i.includes(e))return!1;n&&n(e,r);let l=this.option.logFn;if(l){let n=L||![N.WARN,N.ERROR].includes(e)||o.noTrace?e:N.TRACE;n=L&&[N.DEBUG].includes(e)?N.INFO:n;let i=l[n.toLowerCase()]||l[N.INFO];n.toLowerCase()===N.TABLE?l.table.apply(null,r):n.toLowerCase()===N.TIME?l.log.apply(null,t.concat(r)):n.toLowerCase()===N.LOG?l.log.apply(null,r):i.apply(null,t.concat(r))}}exe(e,t,r){let o=L?this._getBroswerColorfulArguments(e):this._getTerminalColorfulArguments(e,r);return this._output(e,o,t,r),null}_mExecute(e,t,r={}){this.option.moduleName=t[0];let o=e.toLowerCase()+(r.noTrace?"NoTrace":"");this[o]&&this[o].apply(this,t.slice(1,t.length)),this.option.moduleName=""}}const de=function(e){let t=e.bindGlobalName;return(0,C.isBindToGlobal)(t)?(0,C.getbindData)(t):(0,C.bindToGlobal)(t,new ge(e||{}))},be=de(k),he=be})(),o})())); //# sourceMappingURL=index-bundle-min.js.map