package com.ruoyi.file.object;

import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public final class UploadLog
{
    private static final ThreadLocal<StringBuilder> _logPool = new ThreadLocal<>();

    private static StringBuilder Instance()
    {
        StringBuilder builder = _logPool.get();
        if(null == builder)
            builder = new StringBuilder();
        _logPool.set(builder);
        return builder;
    }

    public static void Append(String str, Object...args)
    {
        Instance().append(StrUtil.format(str, args));
    }

    public static void AppendCStyle(String str, Object...args)
    {
        Instance().append(String.format(str, args));
    }

    public static void Appendln(String str, Object...args)
    {
        Instance().append(StrUtil.format(str, args)).append('\n');
    }

    public static void AppendCStyleln(String str, Object...args)
    {
        Instance().append(String.format(str, args)).append('\n');
    }

    public static void Output()
    {
        StringBuilder builder = _logPool.get();
        if(null == builder)
            Log("");
        Log(builder.toString());
        _logPool.remove();
    }

    public static void Clear()
    {
        _logPool.remove();
    }

    public static void Log(String str)
    {
        log.info(str);
    }
}
