Commit 45b1c02b authored by tqcq's avatar tqcq
Browse files

feat add log on update log_file

parent 0330fd7b
Loading
Loading
Loading
Loading
+25 −21
Original line number Diff line number Diff line
@@ -97,27 +97,6 @@ GetCurrentUTCTime()
    return result;
}

static LogLevel g_log_level = LogLevel::kTrace;
// static std::string g_log_file_name;
static std::ofstream g_log_stream;

void
SetLogLevel(LogLevel level)
{
    g_log_level = level;
}

void
SetLogFileName(const char *file_name)
{
    std::ofstream tmp_stream(file_name, std::ios_base::app);
    if (tmp_stream.is_open()) {
        g_log_stream.open(file_name, std::ios_base::app);
    } else {
        LOGE("log", "can't open new log file [{}]", file_name);
    }
}

static std::atomic<uint32_t> g_current_id(0);
static std::atomic<uint32_t> g_request_id(0);

@@ -138,6 +117,31 @@ private:
    std::atomic<uint32_t> &current_id_;
};

static LogLevel g_log_level = LogLevel::kTrace;
// static std::string g_log_file_name;
static std::ofstream g_log_stream;

void
SetLogLevel(LogLevel level)
{
    g_log_level = level;
}

void
SetLogFileName(const char *file_name)
{
    std::ofstream tmp_stream(file_name, std::ios_base::app);
    if (tmp_stream.is_open()) {
        // g_log_stream.open(file_name, std::ios_base::app);
        // g_log_stream = std::move(tmp_stream);
        Waiter waiter(g_request_id.fetch_add(1), g_current_id);
        std::swap(g_log_stream, tmp_stream);
    } else {
        LOGE("log", "can't open new log file [{}]", file_name);
    }
    LOGD("log", "log to new file [{}]", file_name);
}

void
Log(LogLevel level, const char *tag, const char *fmt, const char *file_name, int line, const char *func_name, ...)
{