import { config } from '../config/config'
export class log {
	public static Debug(msg:any,...other){
		if(config.LOG_OPEN){
			console.log(msg,other.length>0?other[0]:"",log.stack())
		}
	}
	
	private static stack(){
		 let callingLocation = ''
		 try {
		    throw new Error(); // 创建一个新的Error对象，但不实际抛出它
		  } catch (e) {
		    const stack = e.stack; // 获取堆栈跟踪信息
		    // console.log(stack); // 打印堆栈跟踪
		    // 分析堆栈跟踪，找到log的调用位置
		    const lines = stack.split('\n');
			if(lines.length>=4){
				callingLocation = lines[3];
			}
		  }
		  return callingLocation
	}
	
	public static Error(msg:any,...other){
		if(config.LOG_OPEN){
			console.error(msg,other.length>0?other[0]:"")
		}
	}
	
	public static Info(msg:any,...other){
		if(config.LOG_OPEN){
			console.info(msg,other.length>0?other[0]:"")
		}
	}
}