代码拉取完成,页面将自动刷新
// https://log.xlongwei.com/lajax.min.js
!function(e){function t(o){if(r[o])return r[o].exports;var n=r[o]={exports:{},id:o,loaded:!1};return e[o].call(n.exports,n,n.exports,t),n.loaded=!0,n.exports}var r={};return t.m=e,t.c=r,t.p="",t(0)}([function(e,t,r){e.exports=r(1)},function(e,t,r){"use strict";function o(e){return e&&e.__esModule?e:{default:e}}var n=r(2),a=o(n);window.Lajax=a.default},function(e,t){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},n=function(){function e(e,t){for(var r=0;r<t.length;r++){var o=t[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,r,o){return r&&e(t.prototype,r),o&&e(t,o),t}}();"toJSON"in Error.prototype||Object.defineProperty(Error.prototype,"toJSON",{value:function(){var e={};return Object.getOwnPropertyNames(this).forEach(function(t){e[t]=this[t]},this),e},configurable:!0,writable:!0});var a=function(){function e(t){r(this,e);var n=t;if("undefined"==typeof n)throw new Error("lajax初始化错误 - 构造函数的参数不能为空!");if("string"==typeof n)n={url:t};else{if("object"!==("undefined"==typeof n?"undefined":o(n)))throw new Error("lajax初始化错误 - 构造函数的参数格式不正确!");if("string"!=typeof t.url)throw new Error("lajax初始化错误 - 构造函数的参数 url 必须是一个字符串!");if(null!=t.logAjaxFilter&&"function"!=typeof t.logAjaxFilter)throw new Error("lajax初始化错误 - 构造函数的参数 logAjaxFilter 必须是一个函数!");if(null!=t.customDesc&&"function"!=typeof t.customDesc)throw new Error("lajax初始化错误 - 构造函数的参数 customDesc 必须是一个函数!")}this.url=n.url,this.autoLogError=null==n.autoLogError||n.autoLogError,this.autoLogRejection=null==n.autoLogRejection||n.autoLogRejection,this.autoLogAjax=null==n.autoLogAjax||n.autoLogAjax;var a=function(e,t){return!0};this.logAjaxFilter=null==n.logAjaxFilter?a:n.logAjaxFilter,this.stylize=null==n.stylize||n.stylize,this.stylize=this.stylize&&this._stylizeSupport(),this.showDesc=null==n.showDesc||n.showDesc,this.customDesc=n.customDesc;var i=1e4;this.interval=null==n.interval?i:n.interval;var s=5;this.maxErrorReq=null==n.maxErrorReq?s:n.maxErrorReq,this.errorReq=0,this.queue=[],this.xhr=null,this.xhrOpen=XMLHttpRequest.prototype.open,this.xhrSend=XMLHttpRequest.prototype.send,this._init()}return n(e,[{key:"_init",value:function(){var e=this;this._getReqId(),this._loadFromStorage(),this._printDesc(),this._exceptionHandler(),this._ajaxHandler(),this._storageUnsendData(),this.timer=setInterval(function(){e._send()},this.interval)}},{key:"_getReqId",value:function(){if(this.reqId=document.querySelector('[name="_reqId"]')?document.querySelector('[name="_reqId"]').content:"",this.reqId||(this.reqId=window._reqId),this.reqId)this.idFromServer=!0;else{var e=Date.now();"undefined"!=typeof performance&&"function"==typeof performance.now&&(e+=performance.now()),this.reqId="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){var r=(e+16*Math.random())%16|0;return e=Math.floor(e/16),("x"===t?r:3&r|8).toString(16)}),this.idFromServer=!1}}},{key:"_defaultDesc",value:function(e,t,r){return"🚀 lajax 前端日志模块加载完成。\n自动记录页面错误: "+(this.autoLogError?"✔":"✘")+"\n自动记录Promise异常: "+(this.autoLogRejection?"✔":"✘")+"\n自动记录Ajax请求: "+(this.autoLogAjax?"✔":"✘")+"\n当前页面请求id:"+t+(r?" (来自服务端)":" (自动生成)")}},{key:"_printDesc",value:function(){if(console&&this.showDesc){var t=void 0;t=this.customDesc?this.customDesc(this.lastUnsend,this.reqId,this.idFromServer):this._defaultDesc(this.lastUnsend,this.reqId,this.idFromServer),this.stylize?console.log("%c"+t,"color: "+e.colorEnum.desc+"; font-family: 宋体; line-height: 1.5;"):console.log(t)}}},{key:"_isSecret",value:function(){try{var e="lajax-test";return window.localStorage.setItem(e,"1"),window.localStorage.removeItem(e),!1}catch(e){return!0}}},{key:"_loadFromStorage",value:function(){if(!this._isSecret()){var e=JSON.parse(window.localStorage.getItem("lajax"));Array.isArray(e)&&e.length&&(this.lastUnsend=e.length,this.queue=e,this._send()),window.localStorage.removeItem("lajax")}}},{key:"_exceptionHandler",value:function(){var e=this;this.autoLogError&&window.addEventListener("error",function(t){e.error("[OnError]",t.message,"("+t.lineno+"行"+t.colno+"列)")}),this.autoLogRejection&&window.addEventListener("unhandledrejection",function(t){e.error("[OnRejection]",t.reason)})}},{key:"_stylizeSupport",value:function(){var e=!!window.chrome,t=navigator.userAgent.indexOf("Firefox")!==-1;return e||t}},{key:"_resolveUrl",value:function(e){var t=document.createElement("a");return t.href=e,t.protocol+"//"+t.host+t.pathname+t.search+t.hash}},{key:"_ajaxHandler",value:function(){if(this.autoLogAjax){var t=this;XMLHttpRequest.prototype.open=function(){for(var e=arguments.length,r=Array(e),o=0;o<e;o++)r[o]=arguments[o];this._lajaxMethod=r[0],this._lajaxUrl=t._resolveUrl(r[1]),t.xhrOpen.apply(this,r)},XMLHttpRequest.prototype.send=function(r){var o=new Date;t.logAjaxFilter(this._lajaxUrl,this._lajaxMethod)&&(t._pushToQueue(o,e.levelEnum.info,"[ajax] 发送"+this._lajaxMethod.toLowerCase()+"请求:"+this._lajaxUrl),this.setRequestHeader("X-Request-Id",t.reqId)),this.addEventListener("readystatechange",function(){if(t.logAjaxFilter(this._lajaxUrl,this._lajaxMethod))try{if(this.readyState===XMLHttpRequest.DONE){console&&console.group&&t.stylize&&console.group("%cajax请求","color: "+e.colorEnum.ajaxGroup+";"),t._printConsole(o,e.levelEnum.info,"[ajax] 发送"+this._lajaxMethod.toLowerCase()+"请求:"+this._lajaxUrl);var n=new Date,a=(n-o)/1e3,i=[];this.status>=200&&this.status<400?i.push("接口请求成功。"):i.push("接口请求失败!"),i.push("请求耗时:"+a+"s URL:"+this._lajaxUrl+" 请求方式:"+this._lajaxMethod),"post"===this._lajaxMethod.toLowerCase()&&i.push("表单数据:",JSON.parse(r)),i.push("状态码:"+this.status),this.status>=200&&this.status<400?t.info.apply(t,["[ajax]"].concat(i)):t.error.apply(t,["[ajax]"].concat(i)),console&&console.group&&console.groupEnd()}}catch(e){var s=[];s.push("接口请求出错!"),s.push("URL:"+this._lajaxUrl+" 请求方式:"+this._lajaxMethod),"post"===this._lajaxMethod.toLowerCase()&&s.push("表单数据:",JSON.parse(r)),s.push("状态码:"+this.status),s.push("ERROR:"+e),t.error.apply(t,["[ajax]"].concat(s))}}),t.xhrSend.call(this,r)}}}},{key:"_storageUnsendData",value:function(){var e=this;window.onunload=function(){e.queue.length&&(navigator.sendBeacon&&navigator.sendBeacon(e.url,JSON.stringify(e.queue))?e.queue=[]:e._isSecret()?e._send():window.localStorage.setItem("lajax",JSON.stringify(e.queue)))}}},{key:"_send",value:function(){var t=this,r=this.queue.length;r&&(this.xhr&&(this.xhr.onreadystatechange=null,this.xhr.abort()),this.xhr=new XMLHttpRequest,this.xhrOpen.call(this.xhr,"POST",this.url,!0),this.xhr.setRequestHeader("Content-Type","application/json; charset=utf-8"),this.xhrSend.call(this.xhr,JSON.stringify(this.queue)),this.xhr.onreadystatechange=function(){t.xhr.readyState===XMLHttpRequest.DONE&&(t.xhr.status>=200&&t.xhr.status<400?(t.queue.splice(0,r),t.errorReq=0,console&&(t.stylize?console.log("%c["+t._getTimeString(null)+"] - "+r+"条日志发送成功!","color: "+e.colorEnum.sendSuccess):console.log(r+"条日志发送成功!"))):(t._printConsole(null,e.levelEnum.error,"发送日志请求失败!配置的接口地址:"+t.url+" 状态码:"+t.xhr.status),t._checkErrorReq()),t.xhr=null)})}},{key:"_checkErrorReq",value:function(){this.errorReq++,this.errorReq>=this.maxErrorReq&&(clearInterval(this.timer),this._printConsole(null,e.levelEnum.warn,"发送日志请求的连续失败次数过多,已停止发送日志。请检查日志接口 "+this.url+" 是否正常!"))}},{key:"_getTimeString",value:function(e){var t=null===e?new Date:e,r=String(t.getHours());1===r.length&&(r="0"+r);var o=String(t.getMinutes());1===o.length&&(o="0"+o);var n=String(t.getSeconds());1===n.length&&(n="0"+n);var a=String(t.getMilliseconds());return 1===a.length?a="00"+a:2===a.length&&(a="0"+a),r+":"+o+":"+n+"."+a}},{key:"_getDateTimeString",value:function(e){var t=null===e?new Date:e,r=String(t.getFullYear()),o=String(t.getMonth()+1);1===o.length&&(o="0"+o);var n=String(t.getDate());return 1===n.length&&(n="0"+n),r+"-"+o+"-"+n+" "+this._getTimeString(t)}},{key:"_printConsole",value:function(t,r){if(console){for(var o=arguments.length,n=Array(o>2?o-2:0),a=2;a<o;a++)n[a-2]=arguments[a];if(this.stylize){var i;(i=console)[r].apply(i,["%c["+this._getTimeString(t)+"] ["+r.toUpperCase()+"] -","color: "+e.colorEnum[r]].concat(n))}else{var s;(s=console)[r].apply(s,n)}}}},{key:"_pushToQueue",value:function(e,t){for(var r=arguments.length,o=Array(r>2?r-2:0),n=2;n<r;n++)o[n-2]=arguments[n];o.unshift("{"+this.reqId+"}"),this.queue.push({time:this._getDateTimeString(e),level:t,messages:o,url:window.location.href,agent:navigator.userAgent})}},{key:"_log",value:function(e,t){for(var r=arguments.length,o=Array(r>2?r-2:0),n=2;n<r;n++)o[n-2]=arguments[n];this._printConsole.apply(this,[e,t].concat(o)),this._pushToQueue.apply(this,[e,t].concat(o))}},{key:"info",value:function(){for(var t=arguments.length,r=Array(t),o=0;o<t;o++)r[o]=arguments[o];this._log.apply(this,[null,e.levelEnum.info].concat(r))}},{key:"log",value:function(){this.info.apply(this,arguments)}},{key:"warn",value:function(){for(var t=arguments.length,r=Array(t),o=0;o<t;o++)r[o]=arguments[o];this._log.apply(this,[null,e.levelEnum.warn].concat(r))}},{key:"error",value:function(){for(var t=arguments.length,r=Array(t),o=0;o<t;o++)r[o]=arguments[o];this._log.apply(this,[null,e.levelEnum.error].concat(r))}}]),e}();a.levelEnum={info:"info",warn:"warn",error:"error"},a.colorEnum={info:"DodgerBlue",warn:"orange",error:"red",ajaxGroup:"#800080",sendSuccess:"green",desc:"#d30775"},t.default=a}]);
// https://log.xlongwei.com/logserver.js
Lajax.logLevel='info';Lajax.logConsole=false;Lajax.logServer=true;Lajax.token='xlongwei';Lajax.prototype._log=function(time,level,...args){if(!Lajax.logLevel||'info'==Lajax.logLevel||('warn'==Lajax.logLevel&&(Lajax.levelEnum.warn==level||Lajax.levelEnum.error==level))||('error'==Lajax.logLevel&&Lajax.levelEnum.error==level)){if(Lajax.logConsole){this._printConsole(time,level,...args)}if(Lajax.logServer){this._pushToQueue(time,level,...args)}}};Lajax.prototype._send=function(){const logCount=this.queue.length;if(logCount){if(this.xhr){this.xhr.onreadystatechange=null;this.xhr.abort()}try{this.xhr=new XMLHttpRequest();this.xhrOpen.call(this.xhr,'POST',this.url,true);this.xhr.setRequestHeader('Content-Type','application/json; charset=utf-8');if(Lajax.token){this.xhr.setRequestHeader('X-Request-Token',Lajax.token)}this.xhrSend.call(this.xhr,JSON.stringify(this.queue));this.xhr.onreadystatechange=()=>{if(this.xhr.readyState===XMLHttpRequest.DONE){if(this.xhr.status>=200&&this.xhr.status<400){this.queue.splice(0,logCount);this.errorReq=0;if(console&&Lajax.logConsole){if(this.stylize){console.log(`%c[${this._getTimeString(null)}]-${logCount}条日志发送成功!`,`color:${Lajax.colorEnum.sendSuccess}`)}else{console.log(`${logCount}条日志发送成功!`)}}}else{this._printConsole(null,Lajax.levelEnum.error,`发送日志请求失败!配置的接口地址:${this.url}状态码:${this.xhr.status}`);this._checkErrorReq()}this.xhr=null}}}catch(err){this._printConsole(null,Lajax.levelEnum.error,`发送日志请求失败!配置的接口地址:${this.url}`);this._checkErrorReq();this.xhr=null}}};var logger=new Lajax({url:'lajax',autoLogError:false,autoLogRejection:false,autoLogAjax:false,stylize:true,showDesc:false,interval:5000,maxErrorReq:3});
// config
Lajax.dev=process.env.NODE_ENV === 'development';
Lajax.logLevel='info';//info warn error off
Lajax.logConsole=Lajax.dev;//是否输出日志到控制台
Lajax.logServer=!Lajax.dev;//是否输出日志到logserver
Lajax.token='apidemo';//通过X-Request-Token传入,作为日志上下文contextName(密码难以保密)
logger.url=Lajax.dev?'http://localhost:9880/lajax':'https://log.xlongwei.com/lajax';
// logger.autoLogAjax=true;
logger.stylize=false;
export { logger }
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。