import { logger } from "mslib";
import { Container, Inject, Singleton } from "typescript-ioc";
/**
 * 日志规范工具
 * @date 2023-09-15 11:38:20
 * @author 郁忠彪
 */
 class LogUtils {


    static fatal(param: LogTempaleBean) {
        return logger.fatal(this.getlogString(param))
    }

    static error(param: LogTempaleBean) {
        return logger.error(this.getlogString(param))
    }

    static info(param: LogTempaleBean) {
        return logger.info(this.getlogString(param))
    }

    static debug(param: LogTempaleBean) {
        return logger.debug(this.getlogString(param))
    }

    static warn(param: LogTempaleBean) {
        return logger.warn(this.getlogString(param))
    }


    private static getlogString(param) {
        if (!param.msgName && !param.msg && !param.parkId) {
            return '日志格式错误：msgName,msg,parkId为空！'
        }
        let logString = `[${param.msgName}：${param.msg}]`
        if (param.toMethod) {
            logString = logString + `----路由：[${param.toMethod}]`
        }
        if (param.url) {
            logString = logString + `----请求地址：[${param.url}]`
        }
        logString = logString + `----车场id：[${param.parkId}]`

        return logString
    }

}

export { LogUtils }
@Singleton
export class LogTempaleBean {
    /**
     * 日志级别
     */
    // logLLevel?: string;

    /**
 * 目标方法
 */
    toMethod?: string;

    /**
* 目标地址
*/
    url?: string;


    /**
      * 消息名称
      */
    msgName: string;

    /**
  * 消息体
  */
    msg: string;

    /**
* 车场id
*/
    parkId: string;



}
