"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.log=void 0;const e=require("../tools/posh"),o=require("../common/message"),r=require("log4js");r.configure({levels:{DEBUG:{value:1e4,colour:"grey"},INFO:{value:2e4,colour:"green"},WARN:{value:3e4,colour:"yellow"},ERROR:{value:4e4,colour:"red"}},appenders:{console:{type:"console",layout:{type:"pattern",pattern:"%c %[%p: %]%m"}}},categories:{default:{appenders:["console"],level:"debug"},ohpm:{appenders:["console"],level:"debug"}}});exports.log=new class{constructor(){this.spilter=/{\s*}/,this.ohpmLog=r.getLogger("ohpm")}setup(e){"string"==typeof e&&(this.ohpmLog.level=e);const o=process.stdout.isTTY;process.env.COLOR=o?"1":"0"}shutdown(e){r.shutdown(e)}log(e,o,...r){this.ohpmLog.log(e,o,...r)}debug(e,o,...r){this.ohpmLog.debug(this.concatLogAndColoring(e,o,"grey",...r))}info(e,o,...r){this.ohpmLog.info(this.concatLogAndColoring(e,o,"green",...r))}warn(e,o,...r){this.ohpmLog.warn(this.concatLogAndColoring(e,o,"yellow",...r))}error(e,o,...r){this.ohpmLog.error(this.concatLogAndColoring(e,o,"red",...r))}concatLogAndColoring(e,o,r,...t){let s=this.concatPrefix(e,o);return t&&t.length&&(s=this.replacePlaceHolder(s,t)),this.withColor(s,r)}concatPrefix(e,o){return e&&e.length?e.concat(" ").concat(o):o}replacePlaceHolder(r,t){if(!t||!t.length)return r;if(!this.spilter.test(r))throw this.ohpmLog.error(e.posh.red('The "{}" placeholder is missing in the message content.')),new Error(o.Messages.Log.ReplacePlaceHolderFailed);const s=r.split(this.spilter);if(s.length<=t.length)throw this.ohpmLog.error(e.posh.red('The number of placeholders "{}" must be equal to the length of parameter args.')),new Error(o.Messages.Log.ReplacePlaceHolderFailed);let l="";for(let e=0;e<t.length;e++)l=0===e?`${s[e]}${t[e]}${s[e+1]}`:`${l}${t[e]}${s[e+1]}`;return l}withColor(o,r){switch(r){case"grey":default:return e.posh.blackBright(o);case"green":return e.posh.green(o);case"yellow":return e.posh.yellow(o);case"red":return e.posh.red(o)}}};