feat support log write
Some checks failed
linux-mips64-gcc / linux-gcc-mips64el (Release) (push) Failing after 1m28s
linux-mips64-gcc / linux-gcc-mips64el (Debug) (push) Successful in 1m31s
linux-aarch64-cpu-gcc / linux-gcc-aarch64 (push) Successful in 1m39s
linux-arm-gcc / linux-gcc-armhf (push) Successful in 1m38s
linux-x64-gcc / linux-gcc (Release) (push) Successful in 1m43s
linux-x64-gcc / linux-gcc (Debug) (push) Successful in 2m15s
Some checks failed
linux-mips64-gcc / linux-gcc-mips64el (Release) (push) Failing after 1m28s
linux-mips64-gcc / linux-gcc-mips64el (Debug) (push) Successful in 1m31s
linux-aarch64-cpu-gcc / linux-gcc-aarch64 (push) Successful in 1m39s
linux-arm-gcc / linux-gcc-armhf (push) Successful in 1m38s
linux-x64-gcc / linux-gcc (Release) (push) Successful in 1m43s
linux-x64-gcc / linux-gcc (Debug) (push) Successful in 2m15s
This commit is contained in:
parent
f2408b4aec
commit
91251d7771
@ -4,6 +4,7 @@
|
||||
#include <atomic>
|
||||
#include <ctime>
|
||||
#include <fmt/format.h>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
namespace sled {
|
||||
@ -97,6 +98,8 @@ GetCurrentUTCTime()
|
||||
}
|
||||
|
||||
static LogLevel g_log_level = LogLevel::kTrace;
|
||||
static std::string g_log_file_name;
|
||||
static std::ofstream g_log_stream;
|
||||
|
||||
void
|
||||
SetLogLevel(LogLevel level)
|
||||
@ -104,6 +107,13 @@ SetLogLevel(LogLevel level)
|
||||
g_log_level = level;
|
||||
}
|
||||
|
||||
void
|
||||
SetLogFileName(const char *file_name)
|
||||
{
|
||||
g_log_file_name = file_name;
|
||||
g_log_stream.open(file_name);
|
||||
}
|
||||
|
||||
static std::atomic<uint32_t> g_current_id(0);
|
||||
static std::atomic<uint32_t> g_request_id(0);
|
||||
|
||||
@ -138,6 +148,7 @@ Log(LogLevel level, const char *tag, const char *fmt, const char *file_name, int
|
||||
|
||||
Waiter waiter(g_request_id.fetch_add(1), g_current_id);
|
||||
waiter.wait();
|
||||
if (g_log_stream.is_open()) { g_log_stream << msg << std::endl; }
|
||||
std::cout << GetConsoleColorPrefix(level) << msg << GetConsoleColorSuffix() << std::endl;
|
||||
}
|
||||
|
||||
|
@ -58,6 +58,7 @@ enum class LogLevel {
|
||||
kFatal = 5,
|
||||
};
|
||||
void SetLogLevel(LogLevel level);
|
||||
void SetLogFileName(const char *file_name);
|
||||
|
||||
void Log(LogLevel level, const char *tag, const char *fmt, const char *file_name, int line, const char *func_name, ...);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user