import{EventTarget}from'../common/common.js';import{SDKModel,LogModel,ConsoleModel,RuntimeModel}from'../sdk/sdk.js';class LogManager{constructor(){SDKModel.TargetManager.instance().observeModels(LogModel.LogModel,this);}
modelAdded(logModel){const eventListeners=[];eventListeners.push(logModel.addEventListener(LogModel.Events.EntryAdded,this._logEntryAdded,this));logModel[_eventSymbol]=eventListeners;}
modelRemoved(logModel){EventTarget.EventTarget.removeEventListeners(logModel[_eventSymbol]);}
_logEntryAdded(event){const data=(event.data);const target=data.logModel.target();const consoleMessage=new ConsoleModel.ConsoleMessage(target.model(RuntimeModel.RuntimeModel),data.entry.source,data.entry.level,data.entry.text,undefined,data.entry.url,data.entry.lineNumber,undefined,[data.entry.text,...(data.entry.args||[])],data.entry.stackTrace,data.entry.timestamp,undefined,undefined,data.entry.workerId);if(data.entry.networkRequestId){self.SDK.networkLog.associateConsoleMessageWithRequest(consoleMessage,data.entry.networkRequestId);}
if(consoleMessage.source===ConsoleModel.MessageSource.Worker){const workerId=consoleMessage.workerId||'';if(SDKModel.TargetManager.instance().targetById(workerId)){return;}
setTimeout(()=>{if(!SDKModel.TargetManager.instance().targetById(workerId)){ConsoleModel.ConsoleModel.instance().addMessage(consoleMessage);}},1000);}else{ConsoleModel.ConsoleModel.instance().addMessage(consoleMessage);}}}
const _eventSymbol=Symbol('_events');var LogManager$1=Object.freeze({__proto__:null,LogManager:LogManager});const logManager=new LogManager();export{LogManager$1 as LogManager,logManager};