import{c as d}from"./chunk-IPB45UXV.js";import{O as a,e as c}from"./chunk-KBLF2WKH.js";var m=(()=>{let r=class r{constructor(){this.logs=[],this.logsSubject=new c([]),this.maxLogs=1e3,this.logs$=this.logsSubject.asObservable(),this.isEnabled=!0,this.ignoreNavigatorLockErrors=!0,this.interceptConsoleErrors(),this.interceptUnhandledErrors()}interceptConsoleErrors(){let e=console.error,s=console.warn,i=console.log;console.error=(...o)=>{let n=o.join(" ");this.ignoreNavigatorLockErrors&&(n.includes("NavigatorLockAcquireTimeoutError")||n.includes("lock:faildaily-mysql-auth")||n.includes("Acquiring an exclusive Navigator LockManager lock"))||(this.addLog("error","Console",n,o.length>1?o:o[0]),e.apply(console,o))},console.warn=(...o)=>{this.addLog("warn","Console",o.join(" "),o.length>1?o:o[0]),s.apply(console,o)},console.log=(...o)=>{let n=o.join(" ");if(n.includes("\u{1F510}")||n.includes("\u274C")||n.includes("\u26A0\uFE0F")||n.includes("\u2705")||n.includes("\u{1F504}")||n.includes("\u{1F4E4}")||n.includes("\u{1F4E5}")||n.includes("\u2139\uFE0F")){let l=this.extractServiceFromMessage(n);this.addLog("info",l,n,o.length>1?o:o[0])}i.apply(console,o)}}interceptUnhandledErrors(){globalThis.addEventListener("error",e=>{this.addLog("error","Global",e.message,{filename:e.filename,lineno:e.lineno,colno:e.colno,error:e.error},e.error?.stack)}),globalThis.addEventListener("unhandledrejection",e=>{this.addLog("error","Promise",`Unhandled Promise Rejection: ${e.reason}`,{reason:e.reason})})}extractServiceFromMessage(e){return e.includes("AuthService")?"AuthService":e.includes("MysqlService")?"MysqlService":e.includes("BadgeService")?"BadgeService":e.includes("FailService")?"FailService":e.includes("PushService")?"PushService":"Unknown"}addLog(e,s,i,o,n){if(!this.isEnabled)return;let l={id:this.generateId(),timestamp:new Date,level:e,service:s,message:i,data:o,stackTrace:n};this.logs.unshift(l),this.logs.length>this.maxLogs&&(this.logs=this.logs.slice(0,this.maxLogs)),this.logsSubject.next([...this.logs])}generateId(){return d("debug_")}logInfo(e,s,i){this.addLog("info",e,s,i)}logWarn(e,s,i){this.addLog("warn",e,s,i)}logError(e,s,i){this.addLog("error",e,s,i,i?.stack)}logDebug(e,s,i){this.addLog("debug",e,s,i)}getLogs(e){let s=[...this.logs];return e&&(e.level&&e.level.length>0&&(s=s.filter(i=>e.level.includes(i.level))),e.service&&e.service.length>0&&(s=s.filter(i=>e.service.includes(i.service))),e.since&&(s=s.filter(i=>i.timestamp>=e.since))),s}clearLogs(){this.logs=[],this.logsSubject.next([])}exportLogs(e){let s=e?this.getLogs(e):this.logs,i={timestamp:new Date().toISOString(),totalLogs:s.length,logs:s.map(o=>({timestamp:o.timestamp.toISOString(),level:o.level,service:o.service,message:o.message,data:o.data?JSON.stringify(o.data,null,2):void 0,stackTrace:o.stackTrace}))};return JSON.stringify(i,null,2)}setEnabled(e){this.isEnabled=e,e&&globalThis.location.hostname!=="localhost"&&this.restoreConsoleForAdmin()}restoreConsoleForAdmin(){let e={log:console.log,error:console.error,warn:console.warn,info:console.info,debug:console.debug};(console.log.toString().includes("function(){}")||console.log.toString().includes("[native code]")===!1)&&(globalThis.window.console.log=(...s)=>{e.log("[ADMIN]",...s)},console.log("\u{1F527} Console restaur\xE9 pour admin en production"))}};r.\u0275fac=function(s){return new(s||r)},r.\u0275prov=a({token:r,factory:r.\u0275fac,providedIn:"root"});let t=r;return t})();export{m as a};
