import * as dayjs from 'dayjs'
import { logger, OpResult } from "mslib"
/**
 * 日志构建器
 * @date 2021-05-28 14:24:45
 * @author 吴锋霖
 */
class LoggerBuilder {

    private log = ''

    /**
     * 添加日志
     * @param txt 文本内容
     */
    append(txt: string, showTime: boolean = true): LoggerBuilder {
        if (showTime) {
            logger.info(txt)
        }
        this.log += (showTime ? this.makeTime() + txt : txt)
        return this
    }

    /**
     * 添加日志并换行
     * @param txt 文本内容
     */
    appendln(txt: string, showTime: boolean = true): LoggerBuilder {
        this.append(txt + '\n', showTime)
        return this
    }

    makeTime(): string {
        return `[${dayjs().format('HH:mm:ss')}] `
    }

    toString(): string {
        return this.log;
    }
}

export { LoggerBuilder }