node-logger-plus
Version:
node console 有趣的打印 log print 打印颜色 style log 美化 带风格的日志
1 lines • 8.01 kB
JavaScript
import*as e from"bus-plus";var t,r={},n={};function o(e){var t=n[e];if(void 0!==t)return t.exports;var a=n[e]={exports:{}};return r[e](a,a.exports,o),a.exports}o.d=function(e,t){for(var r in t)o.o(t,r)&&!o.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},o.rv=function(){return"1.0.0-alpha.5"},o.ruid="bundler=rspack@1.0.0-alpha.5";var a={};o.d(a,{kg:function(){return j},Il:function(){return u},Yd:function(){return m},O9:function(){return l}});function c(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}var l={reset:"\x1b[0m",red:"\x1b[31m",green:"\x1b[32m",yellow:"\x1b[33m",blue:"\x1b[34m",magenta:"\x1b[35m",cyan:"\x1b[36m",white:"\x1b[37m"},u=function(){"use strict";var e,t,r;function n(){!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,n)}return e=n,t=null,r=[{key:"setColor",value:function(e,t){return"".concat(e).concat(t).concat(l.reset)}},{key:"red",value:function(e){return"".concat(l.red).concat(e).concat(l.reset)}},{key:"green",value:function(e){return"".concat(l.green).concat(e).concat(l.reset)}},{key:"yellow",value:function(e){return"".concat(l.yellow).concat(e).concat(l.reset)}},{key:"blue",value:function(e){return"".concat(l.blue).concat(e).concat(l.reset)}},{key:"magenta",value:function(e){return"".concat(l.magenta).concat(e).concat(l.reset)}},{key:"cyan",value:function(e){return"".concat(l.cyan).concat(e).concat(l.reset)}},{key:"white",value:function(e){return"".concat(l.white).concat(e).concat(l.reset)}}],r&&c(e,r),n}();function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function f(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function s(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function y(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function g(e){return(g=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function p(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter(function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable}))),n.forEach(function(t){y(e,t,r[t])})}return e}function b(e,t){return(b=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function v(e){return function(e){if(Array.isArray(e))return i(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,t){if(e){if("string"==typeof e)return i(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);if("Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r)return Array.from(r);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return i(e,t)}}(e)||function(){throw TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function h(e){return e&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":typeof e}var d={log:!0,debug:!0,info:!0,warn:!0,error:!0,table:!0},m=function(e){"use strict";!function(e,t){if("function"!=typeof t&&null!==t)throw TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&b(e,t)}(l,e);var t,r,n,o,a,c=(t=l,r=function(){if("undefined"==typeof Reflect||!Reflect.construct||Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}(),function(){var e,n,o,a=g(t);return o=r?Reflect.construct(a,arguments,g(this).constructor):a.apply(this,arguments),e=this,(n=o)&&("object"===h(n)||"function"==typeof n)?n:f(e)});function l(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:console;return!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,l),y(f(e=c.call(this)),"logger",void 0),y(f(e),"caches",{}),y(f(e),"loggerConfig",JSON.parse(JSON.stringify(d))),e.logger=t,e}return n=l,o=[{key:"setConfig",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.loggerConfig=Object.assign({},this.loggerConfig,e),this.caches={},this.logger.log(u.green("设置【CONFIG】Successify"))}},{key:"getCaches",value:function(){return this.caches}},{key:"instance",get:function(){return this.logger}},{key:"log",value:function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];return Promise.resolve({enabled:!0,result:[]})}},{key:"success",value:function(){for(var e,t=arguments.length,r=Array(t),n=0;n<t;n++)r[n]=arguments[n];return(e=this.log).call.apply(e,[this.logger].concat(v(r)))}},{key:"error",value:function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];return Promise.resolve({enabled:!0,result:[]})}},{key:"warn",value:function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];return Promise.resolve({enabled:!0,result:[]})}},{key:"info",value:function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];return Promise.resolve({enabled:!0,result:[]})}},{key:"debug",value:function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];return Promise.resolve({enabled:!0,result:[]})}},{key:"table",value:function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];return Promise.resolve({enabled:!0,result:[]})}},{key:"default",value:function(){for(var e,t=arguments.length,r=Array(t),n=0;n<t;n++)r[n]=arguments[n];return(e=this.log).call.apply(e,[this.logger].concat(v(r)))}}],a=[{key:"decoratorTime",value:function(e){return u.cyan(e)}},{key:"getLocaleDateTime",value:function(){return new Date().toLocaleString()}},{key:"printDateTime",value:function(){console.log(l.decoratorTime("".concat(l.getLocaleDateTime())))}}],o&&s(n.prototype,o),a&&s(n,a),l}(e.BusPlus),w=["log","error","warn","info","debug","table","success"],k=(y(t={},w[0],l.white),y(t,w[1],l.red),y(t,w[2],l.yellow),y(t,w[3],l.blue),y(t,w[4],l.magenta),y(t,w[5],l.green),y(t,w[6],l.green),y(t,"default",l.green),t);function O(e){return function(t){for(var r=arguments.length,n=Array(r>1?r-1:0),o=1;o<r;o++)n[o-1]=arguments[o];var a=m.getLocaleDateTime(),c=m.decoratorTime(a),u=("undefined"==typeof window?"undefined":h(window))?"":l.reset,i="【".concat(t.toLocaleUpperCase(),"】"),f=["".concat(c).concat(k[t]).concat(i)].concat(v(n),[u]),s=this.logger,y=null!==(g=s[t])&&void 0!==g?g:s.log;if("table"===e){y.call.apply(y,[s].concat(v(n)));var g,p=["".concat(c).concat(l.green).concat(i).concat(l.reset),n[0]];s.log.apply(s,v(p))}else y.call.apply(y,[s].concat(v(f)));return{result:f,source:[a,i].concat(v(n))}}}var _={table:O("table"),default:O("default")};function P(e){for(var t,r=arguments.length,n=Array(r>1?r-1:0),o=1;o<r;o++)n[o-1]=arguments[o];var a=null!==(t=_[e])&&void 0!==t?t:_.default;return a.call.apply(a,[this,e].concat(v(n)))}w.forEach(function(e){Object.defineProperty(m.prototype,e,{enumerable:!1,value:function(){for(var t,r,n=arguments.length,o=Array(n),a=0;a<n;a++)o[a]=arguments[a];var c={result:[],source:[]};if(!1===this.loggerConfig[e])return Promise.resolve(p({endabled:!1},c));this.caches[e]?c=(t=this.caches[e]).call.apply(t,[this].concat(v(o))):(this.caches[e]=P.bind(this,e),c=(r=this.caches)[e].apply(r,v(o)));var l=p({endabled:!0},c);return this.emit("data",l),Promise.resolve(l)}})});var j=new m,x=a.Il,A=a.Yd,C=a.O9,S=a.kg;export{x as Color,A as Logger,C as colors,S as logger};