const ZeroLogFactory=()=>{const logStore=idbKeyval.createStore("log-store","log-store"),logSequence=[];let isRunning=!1,splitStr="\n----Z-e-r-o-O-m-e-g-a--------------\n";const originConsoleLog=console.log,originConsoleError=console.error,_logFn=async function(){if(isRunning)return;isRunning=!0;const _moment=moment(),dayOfWeek=_moment.format("E"),logKey=(_moment.format("DD"),"zerolog-"+dayOfWeek);for(;logSequence.length>0;){const str=logSequence.join("\n");logSequence.length=0;let logInfo=await idbKeyval.get(logKey,logStore),date=_moment.format("YYYY-MM-DD");logInfo&&logInfo.date||(logInfo={date:date,val:""});let{val:val}=logInfo;logInfo.date!=date&&(val=""),val+=splitStr,splitStr="\n",val+=str,await idbKeyval.set(logKey,{date:date,val:val},logStore)}isRunning=!1},logFn=str=>{logSequence.push(moment().format("YYYY-MM-DD HH:mm:ss   ")+" "+str),_logFn()},replacerFn=(key,value)=>{switch(key){case"username":case"password":case"host":case"port":case"token":case"gistToken":case"gistId":return"<secret>";default:return value}},getStr=function(){return[...arguments].map((obj=>{let str="";try{str="string"==typeof obj?obj:JSON.stringify(obj,replacerFn,4)}catch(e){try{str=obj.toString()}catch(e){}}return str})).join(" ")},ZeroLog=function(){logFn(getStr.apply(null,arguments))},_lastErrorLogFn=async()=>{if(!_lastErrorLogFn.isRunning){for(_lastErrorLogFn.isRunning=!0;_lastErrorLogFn.val;){const val=_lastErrorLogFn.val;_lastErrorLogFn.val="",await idbKeyval.set("lastError",val,logStore)}_lastErrorLogFn.isRunning=!1}},lastErrorLogFn=async function(){const val=getStr.apply(null,arguments);_lastErrorLogFn.val=val,_lastErrorLogFn()},ZeroLogInfo=function(){originConsoleLog.apply(null,arguments),ZeroLog.apply(null,["[INFO]",...arguments])},ZeroLogError=function(){originConsoleError.apply(null,arguments),ZeroLog.apply(null,["[ERROR]",...arguments]),lastErrorLogFn.apply(null,arguments)};console.log=ZeroLogInfo,console.error=ZeroLogError};export default ZeroLogFactory;