zlog
This commit is contained in:
parent
68148a475e
commit
e27b1aeda9
88
engine/3rdparty/zlog/include/source_location.h
vendored
Normal file
88
engine/3rdparty/zlog/include/source_location.h
vendored
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
#ifndef NOSTD_SOURCE_LOCATION_HPP
|
||||||
|
#define NOSTD_SOURCE_LOCATION_HPP
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
namespace zlog {
|
||||||
|
struct source_location {
|
||||||
|
public:
|
||||||
|
#if not defined(__apple_build_version__) and defined(__clang__) and (__clang_major__ >= 9)
|
||||||
|
static constexpr source_location current(const char* fileName = __builtin_FILE(),
|
||||||
|
const char* functionName = __builtin_FUNCTION(),
|
||||||
|
const uint_least32_t lineNumber = __builtin_LINE(),
|
||||||
|
const uint_least32_t columnOffset = __builtin_COLUMN()) noexcept
|
||||||
|
#elif defined(__GNUC__) and (__GNUC__ > 4 or (__GNUC__ == 4 and __GNUC_MINOR__ >= 8))
|
||||||
|
static constexpr source_location current(const char* fileName = __builtin_FILE(),
|
||||||
|
const char* functionName = __builtin_FUNCTION(),
|
||||||
|
const uint_least32_t lineNumber = __builtin_LINE(),
|
||||||
|
const uint_least32_t columnOffset = 0) noexcept
|
||||||
|
#else
|
||||||
|
static constexpr source_location current(const char* fileName = "unsupported",
|
||||||
|
const char* functionName = "unsupported",
|
||||||
|
const uint_least32_t lineNumber = 0,
|
||||||
|
const uint_least32_t columnOffset = 0) noexcept
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
return source_location(fileName, functionName, lineNumber, columnOffset);
|
||||||
|
}
|
||||||
|
|
||||||
|
source_location(const source_location&) = default;
|
||||||
|
source_location(source_location&&) = default;
|
||||||
|
|
||||||
|
constexpr const char* file_name() const noexcept
|
||||||
|
{
|
||||||
|
return fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr const char* function_name() const noexcept
|
||||||
|
{
|
||||||
|
return functionName;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr uint_least32_t line() const noexcept
|
||||||
|
{
|
||||||
|
return lineNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr std::uint_least32_t column() const noexcept
|
||||||
|
{
|
||||||
|
return columnOffset;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
constexpr source_location(const char* fileName, const char* functionName, const uint_least32_t lineNumber,
|
||||||
|
const uint_least32_t columnOffset) noexcept
|
||||||
|
: fileName(fileName)
|
||||||
|
, functionName(functionName)
|
||||||
|
, lineNumber(lineNumber)
|
||||||
|
, columnOffset(columnOffset)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* fileName;
|
||||||
|
const char* functionName;
|
||||||
|
const std::uint_least32_t lineNumber;
|
||||||
|
const std::uint_least32_t columnOffset;
|
||||||
|
};
|
||||||
|
|
||||||
|
[[nodiscard]] constexpr auto get_log_source_location(
|
||||||
|
const source_location& location) {
|
||||||
|
return spdlog::source_loc{location.file_name(),
|
||||||
|
static_cast<std::int32_t>(location.line()),
|
||||||
|
location.function_name()};
|
||||||
|
}
|
||||||
|
|
||||||
|
struct format_with_location {
|
||||||
|
std::string_view value;
|
||||||
|
spdlog::source_loc loc;
|
||||||
|
|
||||||
|
template <typename String>
|
||||||
|
format_with_location(const String& s, const source_location& location =
|
||||||
|
source_location::current())
|
||||||
|
: value{ s }, loc{ get_log_source_location(location) } {}
|
||||||
|
};
|
||||||
|
} // namespace nostd
|
||||||
|
|
||||||
|
#endif
|
||||||
99
engine/3rdparty/zlog/include/zlog.h
vendored
99
engine/3rdparty/zlog/include/zlog.h
vendored
@ -1,72 +1,43 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "spdlog/spdlog.h"
|
#include "spdlog/spdlog.h"
|
||||||
|
#include "source_location.h"
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
namespace zlog {
|
||||||
class zlog final
|
using level_enum = spdlog::level::level_enum;
|
||||||
{
|
class zloger {
|
||||||
public:
|
|
||||||
enum class LogLevel : uint8_t
|
|
||||||
{
|
|
||||||
debug,
|
|
||||||
info,
|
|
||||||
warn,
|
|
||||||
error,
|
|
||||||
fatal
|
|
||||||
};
|
|
||||||
|
|
||||||
public:
|
|
||||||
zlog();
|
|
||||||
~zlog();
|
|
||||||
|
|
||||||
template<typename... TARGS>
|
|
||||||
void log(LogLevel level, TARGS&&... args)
|
|
||||||
{
|
|
||||||
switch (level)
|
|
||||||
{
|
|
||||||
case LogLevel::debug:
|
|
||||||
m_logger->debug(std::forward<TARGS>(args)...);
|
|
||||||
break;
|
|
||||||
case LogLevel::info:
|
|
||||||
m_logger->info(std::forward<TARGS>(args)...);
|
|
||||||
break;
|
|
||||||
case LogLevel::warn:
|
|
||||||
m_logger->warn(std::forward<TARGS>(args)...);
|
|
||||||
break;
|
|
||||||
case LogLevel::error:
|
|
||||||
m_logger->error(std::forward<TARGS>(args)...);
|
|
||||||
break;
|
|
||||||
case LogLevel::fatal:
|
|
||||||
m_logger->critical(std::forward<TARGS>(args)...);
|
|
||||||
fatalCallback(std::forward<TARGS>(args)...);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename... TARGS>
|
|
||||||
void fatalCallback(TARGS&&... args)
|
|
||||||
{
|
|
||||||
const std::string format_str = fmt::format(std::forward<TARGS>(args)...);
|
|
||||||
throw std::runtime_error(format_str);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<spdlog::logger> m_logger;
|
std::shared_ptr<spdlog::logger> m_logger;
|
||||||
|
public:
|
||||||
|
zloger();
|
||||||
|
~zloger();
|
||||||
|
template <typename... Args>
|
||||||
|
void log(level_enum level, format_with_location& fmt, Args &&...args) {
|
||||||
|
m_logger->log(fmt.loc, level, fmt::runtime(fmt.value), std::forward<Args>(args)...);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
extern zloger zlog;
|
||||||
|
template <typename... Args>
|
||||||
|
void info(format_with_location fmt, Args &&...args) {
|
||||||
|
zlog.log(level_enum::info, fmt, std::forward<Args>(args)...);
|
||||||
|
};
|
||||||
|
template <typename... Args>
|
||||||
|
void debug(format_with_location fmt, Args &&...args) {
|
||||||
|
zlog.log(level_enum::debug, fmt, std::forward<Args>(args)...);
|
||||||
|
};
|
||||||
|
template <typename... Args>
|
||||||
|
void warn(format_with_location fmt, Args &&...args) {
|
||||||
|
zlog.log(level_enum::warn, fmt, std::forward<Args>(args)...);
|
||||||
|
};
|
||||||
|
template <typename... Args>
|
||||||
|
void error(format_with_location fmt, Args &&...args) {
|
||||||
|
zlog.log(level_enum::err, fmt, std::forward<Args>(args)...);
|
||||||
|
};
|
||||||
|
template <typename... Args>
|
||||||
|
void fatal(format_with_location fmt, Args &&...args) {
|
||||||
|
zlog.log(level_enum::critical, fmt, std::forward<Args>(args)...);
|
||||||
|
const std::string format_str = fmt::format(std::forward<Args>(args)...);
|
||||||
|
throw std::runtime_error(format_str);
|
||||||
|
};
|
||||||
};
|
};
|
||||||
extern zlog gLog;
|
|
||||||
#define LOG_HELPER(LOG_LEVEL, ...) \
|
|
||||||
gLog.log(LOG_LEVEL, "[" + std::string(__FUNCTION__) + "] " + __VA_ARGS__);
|
|
||||||
|
|
||||||
#define LOG_DEBUG(...) LOG_HELPER(zlog::LogLevel::debug, __VA_ARGS__);
|
|
||||||
|
|
||||||
#define LOG_INFO(...) LOG_HELPER(zlog::LogLevel::info, __VA_ARGS__);
|
|
||||||
|
|
||||||
#define LOG_WARN(...) LOG_HELPER(zlog::LogLevel::warn, __VA_ARGS__);
|
|
||||||
|
|
||||||
#define LOG_ERROR(...) LOG_HELPER(zlog::LogLevel::error, __VA_ARGS__);
|
|
||||||
|
|
||||||
#define LOG_FATAL(...) LOG_HELPER(zlog::LogLevel::fatal, __VA_ARGS__);
|
|
||||||
21
engine/3rdparty/zlog/src/zlog.cpp
vendored
21
engine/3rdparty/zlog/src/zlog.cpp
vendored
@ -3,29 +3,34 @@
|
|||||||
#include <spdlog/sinks/basic_file_sink.h>
|
#include <spdlog/sinks/basic_file_sink.h>
|
||||||
#include <spdlog/sinks/stdout_color_sinks.h>
|
#include <spdlog/sinks/stdout_color_sinks.h>
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
zlog gLog;
|
namespace zlog {
|
||||||
zlog::zlog()
|
zloger zlog;
|
||||||
|
zloger::zloger()
|
||||||
{
|
{
|
||||||
auto console_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
|
auto console_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
|
||||||
console_sink->set_level(spdlog::level::trace);
|
console_sink->set_level(spdlog::level::trace);
|
||||||
console_sink->set_pattern("[%Y-%m-%d %H:%M:%S] %l %^%v%$");
|
console_sink->set_pattern("[%Y-%m-%d %H:%M:%S][%s:%#] %-8l %^%v%$");
|
||||||
|
|
||||||
const spdlog::sinks_init_list sink_list = {console_sink};
|
auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>("test.log", true);
|
||||||
|
file_sink->set_level(spdlog::level::trace);
|
||||||
|
//file_sink->set_pattern("[%Y-%m-%d %H:%M:%S][%s:%#] %-8l %^%v%$");
|
||||||
|
|
||||||
|
const spdlog::sinks_init_list sink_list = { console_sink, file_sink };
|
||||||
|
|
||||||
spdlog::init_thread_pool(8192, 1);
|
spdlog::init_thread_pool(8192, 1);
|
||||||
|
|
||||||
m_logger = std::make_shared<spdlog::async_logger>("muggle_logger",
|
m_logger = std::make_shared<spdlog::async_logger>("zlogger",
|
||||||
sink_list.begin(),
|
sink_list.begin(),
|
||||||
sink_list.end(),
|
sink_list.end(),
|
||||||
spdlog::thread_pool(),
|
spdlog::thread_pool(),
|
||||||
spdlog::async_overflow_policy::block);
|
spdlog::async_overflow_policy::block);
|
||||||
m_logger->set_level(spdlog::level::trace);
|
m_logger->set_level(spdlog::level::trace);
|
||||||
|
m_logger->set_pattern("[%Y-%m-%d %H:%M:%S][%s:%#] %-8l %^%v%$");
|
||||||
spdlog::register_logger(m_logger);
|
spdlog::register_logger(m_logger);
|
||||||
}
|
}
|
||||||
|
zloger::~zloger()
|
||||||
zlog::~zlog()
|
|
||||||
{
|
{
|
||||||
m_logger->flush();
|
m_logger->flush();
|
||||||
spdlog::drop_all();
|
spdlog::drop_all();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
8
engine/3rdparty/zlog/test/01file.cpp
vendored
Normal file
8
engine/3rdparty/zlog/test/01file.cpp
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include "zlog.h"
|
||||||
|
int main() {
|
||||||
|
zlog::info("hello info");
|
||||||
|
zlog::warn("hello {}", "warn");
|
||||||
|
zlog::error("hello {}", "error");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
8
engine/3rdparty/zlog/xmake.lua
vendored
8
engine/3rdparty/zlog/xmake.lua
vendored
@ -2,6 +2,12 @@ set_languages("cxx20")
|
|||||||
target("zlog")
|
target("zlog")
|
||||||
set_kind("static")
|
set_kind("static")
|
||||||
add_includedirs("include", {public = true})
|
add_includedirs("include", {public = true})
|
||||||
add_packages("spdlog")
|
add_packages("spdlog", {public = true})
|
||||||
add_files("src/*.cpp")
|
add_files("src/*.cpp")
|
||||||
add_headerfiles("include/*.h")
|
add_headerfiles("include/*.h")
|
||||||
|
|
||||||
|
target("zlog_test01_file")
|
||||||
|
set_languages("cxx20")
|
||||||
|
set_kind("binary")
|
||||||
|
add_deps("zlog")
|
||||||
|
add_files("test/01file.cpp")
|
||||||
@ -3,7 +3,8 @@
|
|||||||
|
|
||||||
namespace vulkanapi {
|
namespace vulkanapi {
|
||||||
Backend::Backend(const char* appName, int deviceIndex) {
|
Backend::Backend(const char* appName, int deviceIndex) {
|
||||||
mInstance = new Instance(appName);
|
auto instanceCreator = Instance::InstanceCreator();
|
||||||
|
mInstance = new Instance(instanceCreator);
|
||||||
std::vector<VkPhysicalDevice> available_devices;
|
std::vector<VkPhysicalDevice> available_devices;
|
||||||
mInstance->EnumerateAvailablePhysicalDevices(available_devices);
|
mInstance->EnumerateAvailablePhysicalDevices(available_devices);
|
||||||
int device_count = available_devices.size();
|
int device_count = available_devices.size();
|
||||||
|
|||||||
@ -12,9 +12,9 @@ namespace vulkanapi {
|
|||||||
|
|
||||||
#define _USE_GRAPHIC_DEBUG
|
#define _USE_GRAPHIC_DEBUG
|
||||||
|
|
||||||
#define LOG_VULKAN(VkResult, info) \
|
#define LOG_VULKAN(VkResult, info, ...) \
|
||||||
if (VkResult != VK_SUCCESS) { \
|
if (VkResult != VK_SUCCESS) { \
|
||||||
LOG_ERROR(info)\
|
LOG_ERROR(info,##__VA_ARGS__)\
|
||||||
}
|
}
|
||||||
|
|
||||||
using voidFn = std::function<void()>;
|
using voidFn = std::function<void()>;
|
||||||
|
|||||||
@ -10,7 +10,7 @@ namespace vulkanapi {
|
|||||||
#ifdef _USE_GRAPHIC_DEBUG
|
#ifdef _USE_GRAPHIC_DEBUG
|
||||||
, messageSeverity(VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT)
|
, messageSeverity(VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT)
|
||||||
, messageType(VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT)
|
, messageType(VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT)
|
||||||
, debugCallback(Instance::DebugCallback)
|
// , debugCallback(Instance::DebugCallback)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -56,7 +56,7 @@ namespace vulkanapi {
|
|||||||
static_cast<uint32_t>(extensions.size()), // uint32_t enabledExtensionCount
|
static_cast<uint32_t>(extensions.size()), // uint32_t enabledExtensionCount
|
||||||
extensions.data() // const char * const * ppEnabledExtensionNames
|
extensions.data() // const char * const * ppEnabledExtensionNames
|
||||||
};
|
};
|
||||||
LOG_VULKAN(vkCreateInstance(&instance_create_info, nullptr, &mPtr), "Failed to create instance.");
|
//LOG_VULKAN(vkCreateInstance(&instance_create_info, nullptr, &mPtr), "Failed to create instance.");
|
||||||
|
|
||||||
//调用vulkan接口,加载实例函数指针
|
//调用vulkan接口,加载实例函数指针
|
||||||
LoadInstanceLevelFunctions(mPtr, extensions);
|
LoadInstanceLevelFunctions(mPtr, extensions);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user