Log to file
Bigfoot / Sonarqube (push) Skipped
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: game) (push) Successful in 34s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang (Unity Build: ON, Variant: game) (push) Successful in 23s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: toolmode) (push) Successful in 36s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang (Unity Build: ON, Variant: toolmode) (push) Successful in 25s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: game) (push) Successful in 56s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: game) (push) Successful in 44s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: toolmode) (push) Successful in 1m1s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: toolmode) (push) Successful in 49s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: game) (push) Successful in 36s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang (Unity Build: ON, Variant: game) (push) Successful in 26s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: toolmode) (push) Successful in 40s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang (Unity Build: ON, Variant: toolmode) (push) Successful in 28s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: game) (push) Successful in 58s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: game) (push) Successful in 45s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: toolmode) (push) Successful in 1m4s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: toolmode) (push) Successful in 52s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: game) (push) Successful in 28s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang (Unity Build: ON, Variant: game) (push) Successful in 25s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: toolmode) (push) Successful in 46s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang (Unity Build: ON, Variant: toolmode) (push) Successful in 38s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: game) (push) Successful in 43s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: game) (push) Successful in 37s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: toolmode) (push) Successful in 47s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: toolmode) (push) Successful in 41s
Bigfoot / Clang Format Checks (push) Successful in 9s
Bigfoot / Sonarqube (push) Skipped
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: game) (push) Successful in 34s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang (Unity Build: ON, Variant: game) (push) Successful in 23s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: toolmode) (push) Successful in 36s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang (Unity Build: ON, Variant: toolmode) (push) Successful in 25s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: game) (push) Successful in 56s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: game) (push) Successful in 44s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: toolmode) (push) Successful in 1m1s
Bigfoot / Build & Test Debug with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: toolmode) (push) Successful in 49s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: game) (push) Successful in 36s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang (Unity Build: ON, Variant: game) (push) Successful in 26s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: toolmode) (push) Successful in 40s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang (Unity Build: ON, Variant: toolmode) (push) Successful in 28s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: game) (push) Successful in 58s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: game) (push) Successful in 45s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: toolmode) (push) Successful in 1m4s
Bigfoot / Build & Test RelWithDebInfo with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: toolmode) (push) Successful in 52s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: game) (push) Successful in 28s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang (Unity Build: ON, Variant: game) (push) Successful in 25s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang (Unity Build: OFF, Variant: toolmode) (push) Successful in 46s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang (Unity Build: ON, Variant: toolmode) (push) Successful in 38s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: game) (push) Successful in 43s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: game) (push) Successful in 37s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang_asan (Unity Build: OFF, Variant: toolmode) (push) Successful in 47s
Bigfoot / Build & Test Release with ./ConanProfiles/host/clang_asan (Unity Build: ON, Variant: toolmode) (push) Successful in 41s
Bigfoot / Clang Format Checks (push) Successful in 9s
This commit is contained in:
@@ -2,7 +2,8 @@ namespace Bigfoot.Flat;
|
||||
|
||||
enum LogSinkType: byte
|
||||
{
|
||||
Console
|
||||
Console,
|
||||
File
|
||||
}
|
||||
|
||||
enum LogLevel: byte
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <Utils/Log/Log_generated.hpp>
|
||||
|
||||
#include <EASTL/array.h>
|
||||
#include <EASTL/string_view.h>
|
||||
|
||||
#ifdef BIGFOOT_WINDOWS
|
||||
#pragma warning(disable: 4702)
|
||||
@@ -21,6 +22,7 @@
|
||||
#include <quill/LogMacros.h>
|
||||
#include <quill/Logger.h>
|
||||
#include <quill/sinks/ConsoleSink.h>
|
||||
#include <quill/sinks/FileSink.h>
|
||||
#if defined BIGFOOT_WINDOWS
|
||||
#pragma warning(default: 4702)
|
||||
#endif
|
||||
@@ -36,6 +38,11 @@ class Log
|
||||
Flat::LogLevel m_level;
|
||||
};
|
||||
|
||||
/**
|
||||
* The path of the file the File sink writes to
|
||||
*/
|
||||
static constexpr eastl::string_view FILE_SINK_PATH = "Bigfoot.log";
|
||||
|
||||
Log();
|
||||
|
||||
Log(const Log& p_logger) = delete;
|
||||
@@ -95,7 +102,7 @@ class Log
|
||||
/*
|
||||
* The sinks
|
||||
*/
|
||||
eastl::array<std::shared_ptr<quill::Sink>, 1> m_sinks;
|
||||
eastl::array<std::shared_ptr<quill::Sink>, 2> m_sinks;
|
||||
};
|
||||
} // namespace Bigfoot
|
||||
#endif
|
||||
|
||||
@@ -101,4 +101,58 @@
|
||||
#define BIGFOOT_LOG_ERROR(loggerName, fmt, ...)
|
||||
#define BIGFOOT_LOG_FATAL(loggerName, fmt, ...)
|
||||
#endif
|
||||
|
||||
#define BIGFOOT_LOG_DEBUG_IF(condition, loggerName, fmt, ...) \
|
||||
do \
|
||||
{ \
|
||||
if (condition) \
|
||||
{ \
|
||||
BIGFOOT_LOG_DEBUG(loggerName, fmt __VA_OPT__(, ) __VA_ARGS__); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define BIGFOOT_LOG_TRACE_IF(condition, loggerName, fmt, ...) \
|
||||
do \
|
||||
{ \
|
||||
if (condition) \
|
||||
{ \
|
||||
BIGFOOT_LOG_TRACE(loggerName, fmt __VA_OPT__(, ) __VA_ARGS__); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define BIGFOOT_LOG_INFO_IF(condition, loggerName, fmt, ...) \
|
||||
do \
|
||||
{ \
|
||||
if (condition) \
|
||||
{ \
|
||||
BIGFOOT_LOG_INFO(loggerName, fmt __VA_OPT__(, ) __VA_ARGS__); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define BIGFOOT_LOG_WARN_IF(condition, loggerName, fmt, ...) \
|
||||
do \
|
||||
{ \
|
||||
if (condition) \
|
||||
{ \
|
||||
BIGFOOT_LOG_WARN(loggerName, fmt __VA_OPT__(, ) __VA_ARGS__); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define BIGFOOT_LOG_ERROR_IF(condition, loggerName, fmt, ...) \
|
||||
do \
|
||||
{ \
|
||||
if (condition) \
|
||||
{ \
|
||||
BIGFOOT_LOG_ERROR(loggerName, fmt __VA_OPT__(, ) __VA_ARGS__); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define BIGFOOT_LOG_FATAL_IF(condition, loggerName, fmt, ...) \
|
||||
do \
|
||||
{ \
|
||||
if (condition) \
|
||||
{ \
|
||||
BIGFOOT_LOG_FATAL(loggerName, fmt __VA_OPT__(, ) __VA_ARGS__); \
|
||||
} \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
@@ -29,27 +29,30 @@ namespace Flat {
|
||||
|
||||
enum class LogSinkType : int8_t {
|
||||
Console = 0,
|
||||
File = 1,
|
||||
MIN = Console,
|
||||
MAX = Console
|
||||
MAX = File
|
||||
};
|
||||
|
||||
inline const LogSinkType (&EnumValuesLogSinkType())[1] {
|
||||
inline const LogSinkType (&EnumValuesLogSinkType())[2] {
|
||||
static const LogSinkType values[] = {
|
||||
LogSinkType::Console
|
||||
LogSinkType::Console,
|
||||
LogSinkType::File
|
||||
};
|
||||
return values;
|
||||
}
|
||||
|
||||
inline const char * const *EnumNamesLogSinkType() {
|
||||
static const char * const names[2] = {
|
||||
static const char * const names[3] = {
|
||||
"Console",
|
||||
"File",
|
||||
nullptr
|
||||
};
|
||||
return names;
|
||||
}
|
||||
|
||||
inline const char *EnumNameLogSinkType(LogSinkType e) {
|
||||
if (::flatbuffers::IsOutRange(e, LogSinkType::Console, LogSinkType::Console)) return "";
|
||||
if (::flatbuffers::IsOutRange(e, LogSinkType::Console, LogSinkType::File)) return "";
|
||||
const size_t index = static_cast<size_t>(e);
|
||||
return EnumNamesLogSinkType()[index];
|
||||
}
|
||||
@@ -98,13 +101,14 @@ inline const char *EnumNameLogLevel(LogLevel e) {
|
||||
|
||||
inline const ::flatbuffers::TypeTable *LogSinkTypeTypeTable() {
|
||||
static const ::flatbuffers::TypeCode type_codes[] = {
|
||||
{ ::flatbuffers::ET_CHAR, 0, 0 },
|
||||
{ ::flatbuffers::ET_CHAR, 0, 0 }
|
||||
};
|
||||
static const ::flatbuffers::TypeFunction type_refs[] = {
|
||||
Bigfoot::Flat::LogSinkTypeTypeTable
|
||||
};
|
||||
static const ::flatbuffers::TypeTable tt = {
|
||||
::flatbuffers::ST_ENUM, 1, type_codes, type_refs, nullptr, nullptr, nullptr
|
||||
::flatbuffers::ST_ENUM, 2, type_codes, type_refs, nullptr, nullptr, nullptr
|
||||
};
|
||||
return &tt;
|
||||
}
|
||||
|
||||
@@ -17,6 +17,12 @@ Log::Log()
|
||||
m_sinks[static_cast<std::size_t>(Flat::LogSinkType::Console)] =
|
||||
quill::Frontend::create_or_get_sink<quill::ConsoleSink>(
|
||||
std::string {Flat::EnumNameLogSinkType(Flat::LogSinkType::Console)});
|
||||
|
||||
quill::FileSinkConfig fileSinkConfig;
|
||||
fileSinkConfig.set_open_mode('w');
|
||||
m_sinks[static_cast<std::size_t>(Flat::LogSinkType::File)] = quill::Frontend::create_or_get_sink<quill::FileSink>(
|
||||
std::string {FILE_SINK_PATH.data()},
|
||||
fileSinkConfig);
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
@@ -25,7 +31,8 @@ quill::Logger* Log::RegisterLogger(const LoggerInfo& p_loggerInfo)
|
||||
{
|
||||
quill::Logger* logger = quill::Frontend::create_or_get_logger(
|
||||
p_loggerInfo.m_name,
|
||||
m_sinks[static_cast<std::size_t>(Flat::LogSinkType::Console)]);
|
||||
{m_sinks[static_cast<std::size_t>(Flat::LogSinkType::Console)],
|
||||
m_sinks[static_cast<std::size_t>(Flat::LogSinkType::File)]});
|
||||
SetLoggerLevel(p_loggerInfo);
|
||||
|
||||
return logger;
|
||||
|
||||
@@ -6,59 +6,80 @@
|
||||
*********************************************************************/
|
||||
#include <Utils/Log/LogMacros.hpp>
|
||||
|
||||
#include <Utils/Singleton.hpp>
|
||||
|
||||
#include <UtilsTests/UtilsTestsLogger_generated.hpp>
|
||||
|
||||
#if defined BIGFOOT_NOT_OPTIMIZED
|
||||
|
||||
#include <EASTL/string.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
namespace Bigfoot
|
||||
{
|
||||
class LogMacrosFixture: public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
eastl::string ReadFileSinkContent()
|
||||
{
|
||||
Singleton<Log>::GetInstance().Flush();
|
||||
|
||||
std::ifstream file {std::string {Log::FILE_SINK_PATH.data()}};
|
||||
std::stringstream buffer;
|
||||
buffer << file.rdbuf();
|
||||
return eastl::string {buffer.str().c_str()};
|
||||
}
|
||||
};
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(LogMacrosFixture, LogDebug)
|
||||
{
|
||||
BIGFOOT_LOG_DEBUG(UTILSTESTS_LOGGER, "Hello");
|
||||
BIGFOOT_LOG_DEBUG(UTILSTESTS_LOGGER, "Hello Debug");
|
||||
EXPECT_NE(ReadFileSinkContent().find("Hello Debug"), eastl::string::npos);
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(LogMacrosFixture, LogTrace)
|
||||
{
|
||||
BIGFOOT_LOG_TRACE(UTILSTESTS_LOGGER, "Hello");
|
||||
BIGFOOT_LOG_TRACE(UTILSTESTS_LOGGER, "Hello Trace");
|
||||
EXPECT_NE(ReadFileSinkContent().find("Hello Trace"), eastl::string::npos);
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(LogMacrosFixture, LogInfo)
|
||||
{
|
||||
BIGFOOT_LOG_INFO(UTILSTESTS_LOGGER, "Hello");
|
||||
BIGFOOT_LOG_INFO(UTILSTESTS_LOGGER, "Hello Info");
|
||||
EXPECT_NE(ReadFileSinkContent().find("Hello Info"), eastl::string::npos);
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(LogMacrosFixture, LogWarn)
|
||||
{
|
||||
BIGFOOT_LOG_WARN(UTILSTESTS_LOGGER, "Hello");
|
||||
BIGFOOT_LOG_WARN(UTILSTESTS_LOGGER, "Hello Warn");
|
||||
EXPECT_NE(ReadFileSinkContent().find("Hello Warn"), eastl::string::npos);
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(LogMacrosFixture, LogError)
|
||||
{
|
||||
BIGFOOT_LOG_ERROR(UTILSTESTS_LOGGER, "Hello");
|
||||
BIGFOOT_LOG_ERROR(UTILSTESTS_LOGGER, "Hello Error");
|
||||
EXPECT_NE(ReadFileSinkContent().find("Hello Error"), eastl::string::npos);
|
||||
}
|
||||
|
||||
/****************************************************************************************/
|
||||
|
||||
TEST_F(LogMacrosFixture, LogFatal)
|
||||
{
|
||||
BIGFOOT_LOG_FATAL(UTILSTESTS_LOGGER, "Hello");
|
||||
BIGFOOT_LOG_FATAL(UTILSTESTS_LOGGER, "Hello Fatal");
|
||||
EXPECT_NE(ReadFileSinkContent().find("Hello Fatal"), eastl::string::npos);
|
||||
}
|
||||
} // namespace Bigfoot
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user