/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import e from"../config.js";import"./has.js";import{numericHash as t}from"./string.js";const r={info:0,warn:1,error:2,none:3};class i{constructor(e){this.level=null,this._module="",this._parent=null,this.writer=null,this._loggedMessages={error:new Map,warn:new Map,info:new Map},null!=e.level&&(this.level=e.level),null!=e.writer&&(this.writer=e.writer),this._module=e.module,i._loggers.set(this.module,this);const t=this.module.lastIndexOf(".");-1!==t&&(this._parent=i.getLogger(this.module.slice(0,t)))}get module(){return this._module}get parent(){return this._parent}error(...e){this._log("error","always",...e)}warn(...e){this._log("warn","always",...e)}info(...e){this._log("info","always",...e)}errorOnce(...e){this._log("error","once",...e)}warnOnce(...e){this._log("warn","once",...e)}infoOnce(...e){this._log("info","once",...e)}errorOncePerTick(...e){this._log("error","oncePerTick",...e)}warnOncePerTick(...e){this._log("warn","oncePerTick",...e)}infoOncePerTick(...e){this._log("info","oncePerTick",...e)}get test(){}static get test(){}static getLogger(e){return e="string"!=typeof e?e.declaredClass:e,i._loggers.get(e)||new i({module:e})}static{this._loggers=new Map}static{this._tickCounter=0}static{this._tickCounterScheduled=!1}static{this._throttlingDisabled=!1}_log(t,r,...n){if(!this._matchLevel(t))return;if("always"!==r&&!i._throttlingDisabled){const e=o(n),s=this._loggedMessages[t].get(e);if("once"===r&&null!=s||"oncePerTick"===r&&s&&s>=i._tickCounter)return;this._loggedMessages[t].set(e,i._tickCounter),i._scheduleTickCounterIncrement()}for(const i of e.log.interceptors)if(i(t,this.module,...n))return;this._inheritedWriter()(t,this.module,...n)}_parentWithMember(e,t){let r=this;for(;null!=r;){const t=r[e];if(null!=t)return t;r=r.parent}return t}_inheritedWriter(){return this._parentWithMember("writer",n)}_matchLevel(t){const i=e.log.level||"warn";return r[this._parentWithMember("level",i)]<=r[t]}static _scheduleTickCounterIncrement(){i._tickCounterScheduled||(i._tickCounterScheduled=!0,Promise.resolve().then(()=>{i._tickCounter++,i._tickCounterScheduled=!1}))}}function n(e,t,...r){console[e](`[${t}]`,...r)}function o(...e){const r=(e,t)=>"object"!=typeof t||Array.isArray(t)?t:"[Object]";return t(JSON.stringify(e,r))}export{i as default};
