Skip to content

Commit 3ac9169

Browse files
committed
-Dev: added a proper logger
1 parent a959789 commit 3ac9169

File tree

13 files changed

+206
-52
lines changed

13 files changed

+206
-52
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ add_subdirectory(thirdparty/tiny_obj_loader)
5050
add_subdirectory(thirdparty/tinyply)
5151
add_subdirectory(thirdparty/tinyxml)
5252
add_subdirectory(thirdparty/optick-1.4.0)
53+
add_subdirectory(thirdparty/logger)
5354
add_subdirectory(thirdparty/ImGuiFileDialog)
5455
target_link_libraries(ImGuiFileDialog PUBLIC imgui )
5556

@@ -85,6 +86,7 @@ target_link_libraries(VulkanEngine PUBLIC
8586
tinyply
8687
tinyxml
8788
optick
89+
logger
8890
ImGuiFileDialog)
8991

9092
# Set dependencies inside folder

include/engine/common.h

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
#include <vector>
5353
#include <vma/vk_mem_alloc.h>
5454
#include <memory>
55+
#include <logger.h>
5556

5657
// ENGINE DEFINITIONS
5758

@@ -66,25 +67,14 @@
6667
#define PROFILING_FRAME()
6768
#endif
6869

69-
#define _LOG(msg) \
70-
{ \
71-
std::cout << "[VKEngine Log] " << msg << std::endl; \
72-
}
73-
#define DEBUG_LOG(msg) \
74-
{ \
75-
std::cout << "[VKEngine Debug] " << msg << std::endl; \
76-
}
77-
#define ERR_LOG(msg) \
78-
{ \
79-
std::cerr << "[VKEngine Error] " << msg << std::endl; \
80-
}
70+
8171
#define VK_CHECK(x) \
8272
do \
8373
{ \
8474
VkResult err = x; \
8575
if (err) \
8676
{ \
87-
std::cout << "VKEngine detected a Vulkan error: " << err << std::endl; \
77+
LOG_ERROR("VKEngine detected a Vulkan error: " + std::to_string(err)); \
8878
abort(); \
8979
} \
9080
} while (0)

include/engine/graphics/utilities/bootstrap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ inline static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(VkDebugUtilsMessageSe
2929
const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData,
3030
void* pUserData) {
3131

32-
DEBUG_LOG("(Validation Layer) " << pCallbackData->pMessage);
32+
LOG_DEBUG("(Validation Layer) " + std::string(pCallbackData->pMessage));
3333

3434
return VK_FALSE;
3535
}

src/core/scene/mesh.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ bool AABB::is_on_frustrum(const Frustum& frustum) const {
5151
IMaterial* Mesh::change_material(IMaterial* m, size_t id) {
5252
if (m_material.size() < id + 1)
5353
{
54-
ERR_LOG("Not enough material slots");
54+
LOG_ERROR("Not enough material slots");
5555
return nullptr;
5656
}
5757

src/core/windows/windowGLFW.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ void WindowGLFW::init() {
1414
if (!m_handle)
1515
{
1616
glfwTerminate();
17-
ERR_LOG("Failed to create GLFW window");
17+
LOG_ERROR("Failed to create GLFW window");
1818
}
1919

2020
glfwSetWindowPos(m_handle, (int)m_screenPos.x, (int)m_screenPos.y);
@@ -86,7 +86,7 @@ void WindowGLFW::set_window_icon(const char* iconPath) {
8686
unsigned char* pixels = stbi_load(iconPath, &width, &height, &channels, 4); // Force 4 channels (RGBA)
8787
if (!pixels)
8888
{
89-
ERR_LOG("failed to load window ICON");
89+
LOG_ERROR("failed to load window ICON");
9090
return;
9191
}
9292

src/graphics/extensions.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,64 +16,64 @@ void load_extensions(VkDevice& device, VkInstance& instance) {
1616

1717
if (!vkCmdSetPolygonMode)
1818
{
19-
ERR_LOG("Failed to load vkCmdSetPolygonModeEXT!");
19+
LOG_ERROR("Failed to load vkCmdSetPolygonModeEXT!");
2020
}
2121

2222
vkCmdSetRasterizationSamples =
2323
(PFN_vkCmdSetRasterizationSamplesEXT)vkGetDeviceProcAddr(device, "vkCmdSetRasterizationSamplesEXT");
2424

2525
if (!vkCmdSetRasterizationSamples)
2626
{
27-
ERR_LOG("Failed to load vkCmdSetRasterizationSamplesEXT!");
27+
LOG_ERROR("Failed to load vkCmdSetRasterizationSamplesEXT!");
2828
}
2929

3030
vkCreateAccelerationStructure = reinterpret_cast<PFN_vkCreateAccelerationStructureKHR>(
3131
vkGetDeviceProcAddr(device, "vkCreateAccelerationStructureKHR"));
3232

3333
if (!vkCreateAccelerationStructure)
3434
{
35-
ERR_LOG("Failed to load vkCreateAccelerationStructureKHR!");
35+
LOG_ERROR("Failed to load vkCreateAccelerationStructureKHR!");
3636
}
3737
vkDestroyAccelerationStructure = reinterpret_cast<PFN_vkDestroyAccelerationStructureKHR>(
3838
vkGetDeviceProcAddr(device, "vkDestroyAccelerationStructureKHR"));
3939

4040
if (!vkDestroyAccelerationStructure)
4141
{
42-
ERR_LOG("Failed to load vkDestroyAccelerationStructureKHR!");
42+
LOG_ERROR("Failed to load vkDestroyAccelerationStructureKHR!");
4343
}
4444
vkGetAccelerationStructureBuildSizes = reinterpret_cast<PFN_vkGetAccelerationStructureBuildSizesKHR>(
4545
vkGetDeviceProcAddr(device, "vkGetAccelerationStructureBuildSizesKHR"));
4646

4747
if (!vkGetAccelerationStructureBuildSizes)
4848
{
49-
ERR_LOG("Failed to load vkGetAccelerationStructureBuildSizesKHR!");
49+
LOG_ERROR("Failed to load vkGetAccelerationStructureBuildSizesKHR!");
5050
}
5151
vkGetAccelerationStructureDeviceAddress = reinterpret_cast<PFN_vkGetAccelerationStructureDeviceAddressKHR>(
5252
vkGetDeviceProcAddr(device, "vkGetAccelerationStructureDeviceAddressKHR"));
5353

5454
if (!vkGetAccelerationStructureDeviceAddress)
5555
{
56-
ERR_LOG("Failed to load vkGetAccelerationStructureDeviceAddressKHR!");
56+
LOG_ERROR("Failed to load vkGetAccelerationStructureDeviceAddressKHR!");
5757
}
5858
vkCmdBuildAccelerationStructures = reinterpret_cast<PFN_vkCmdBuildAccelerationStructuresKHR>(
5959
vkGetDeviceProcAddr(device, "vkCmdBuildAccelerationStructuresKHR"));
6060

6161
if (!vkCmdBuildAccelerationStructures)
6262
{
63-
ERR_LOG("Failed to load vkCmdBuildAccelerationStructuresKHR!");
63+
LOG_ERROR("Failed to load vkCmdBuildAccelerationStructuresKHR!");
6464
}
6565
vkBuildAccelerationStructures = reinterpret_cast<PFN_vkBuildAccelerationStructuresKHR>(
6666
vkGetDeviceProcAddr(device, "vkBuildAccelerationStructuresKHR"));
6767

6868
if (!vkBuildAccelerationStructures)
6969
{
70-
ERR_LOG("Failed to load vkBuildAccelerationStructuresKHR!");
70+
LOG_ERROR("Failed to load vkBuildAccelerationStructuresKHR!");
7171
}
7272

7373
vkSetDebugUtilsObjectName =
7474
reinterpret_cast<PFN_vkSetDebugUtilsObjectNameEXT>(vkGetInstanceProcAddr(instance, "vkSetDebugUtilsObjectNameEXT"));
7575
if (!vkSetDebugUtilsObjectName)
7676
{
77-
ERR_LOG("Failed to load vkSetDebugUtilsObjectNameEXT!");
77+
LOG_ERROR("Failed to load vkSetDebugUtilsObjectNameEXT!");
7878
}
7979
}

src/graphics/shaderpass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ ShaderSource::compile_shader(const std::string src, const std::string shaderName
9393
shaderc::SpvCompilationResult result = compiler.CompileGlslToSpv(src, kind, shaderName.c_str(), options);
9494
if (result.GetCompilationStatus() != shaderc_compilation_status_success)
9595
{
96-
DEBUG_LOG("Error compiling module - " << result.GetErrorMessage());
96+
LOG_ERROR("Error compiling module - " + std::string(result.GetErrorMessage()));
9797
}
9898

9999
std::vector<uint32_t> spirv = {result.cbegin(), result.cend()};

src/graphics/utilities/bootstrap.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -518,26 +518,26 @@ bool Booter::is_device_extension_supported(VkPhysicalDevice physicalDevice, cons
518518
return false;
519519
}
520520
void Booter::log_available_extensions(std::vector<VkExtensionProperties> ext) {
521-
DEBUG_LOG("---------------------");
522-
DEBUG_LOG("Available extensions");
523-
DEBUG_LOG("---------------------");
521+
LOG_DEBUG("---------------------");
522+
LOG_DEBUG("Available extensions");
523+
LOG_DEBUG("---------------------");
524524
for (const auto& extension : ext)
525525
{
526-
DEBUG_LOG(extension.extensionName);
526+
LOG_DEBUG(extension.extensionName);
527527
}
528-
DEBUG_LOG("---------------------");
528+
LOG_DEBUG("---------------------");
529529
}
530530
void Booter::log_available_gpus(std::multimap<int, VkPhysicalDevice> candidates) {
531-
DEBUG_LOG("---------------------");
532-
DEBUG_LOG("Suitable Devices");
533-
DEBUG_LOG("---------------------");
531+
LOG_DEBUG("---------------------");
532+
LOG_DEBUG("Suitable Devices");
533+
LOG_DEBUG("---------------------");
534534
for (const auto& candidate : candidates)
535535
{
536536
VkPhysicalDeviceProperties deviceProperties;
537537
vkGetPhysicalDeviceProperties(candidate.second, &deviceProperties);
538-
DEBUG_LOG(deviceProperties.deviceName);
538+
LOG_DEBUG(deviceProperties.deviceName);
539539
}
540-
DEBUG_LOG("---------------------");
540+
LOG_DEBUG("---------------------");
541541
}
542542

543543
} // namespace Graphics

src/tools/loaders.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ void VKFW::Tools::Loaders::load_OBJ(Core::Mesh* const mesh, const std::string fi
1717
// Check for errors
1818
if (!warn.empty())
1919
{
20-
DEBUG_LOG("WARN: " + warn);
20+
LOG_WARN("WARN: " + warn);
2121
}
2222
if (!err.empty())
2323
{
24-
ERR_LOG(err);
25-
DEBUG_LOG("ERROR: Couldn't load mesh");
24+
LOG_ERROR(err);
25+
LOG_ERROR("ERROR: Couldn't load mesh");
2626
return;
2727
}
2828

@@ -154,12 +154,12 @@ void VKFW::Tools::Loaders::load_OBJ_topology(Core::Mesh* const mesh,
154154
// Check for errors
155155
if (!warn.empty())
156156
{
157-
DEBUG_LOG("WARN: " + warn);
157+
LOG_WARN("WARN: " + warn);
158158
}
159159
if (!err.empty())
160160
{
161-
ERR_LOG(err);
162-
DEBUG_LOG("ERROR: Couldn't load mesh");
161+
LOG_ERROR(err);
162+
LOG_ERROR("ERROR: Couldn't load mesh");
163163
return;
164164
}
165165

@@ -838,12 +838,12 @@ void VKFW::Tools::Loaders::load_PNG(Core::TextureLDR* const texture, const std::
838838
} else
839839
{
840840
#ifndef NDEBUG
841-
ERR_LOG("Failed to load texture PNG file" + fileName);
841+
LOG_ERROR("Failed to load texture PNG file" + fileName);
842842
#endif
843843
return;
844844
};
845845
#ifndef NDEBUG
846-
DEBUG_LOG("PNG Texture loaded successfully");
846+
LOG_DEBUG("PNG Texture loaded successfully");
847847
#endif // DEBUG
848848
}
849849

@@ -860,12 +860,12 @@ void VKFW::Tools::Loaders::load_HDRi(Core::TextureHDR* const texture, const std:
860860
} else
861861
{
862862
#ifndef NDEBUG
863-
ERR_LOG("Failed to load texture HDRi file" + fileName);
863+
LOG_ERROR("Failed to load texture HDRi file" + fileName);
864864
#endif
865865
return;
866866
};
867867
#ifndef NDEBUG
868-
DEBUG_LOG("HDRi Texture loaded successfully");
868+
LOG_DEBUG("HDRi Texture loaded successfully");
869869
#endif // DEBUG
870870
}
871871
void VKFW::Tools::Loaders::load_3D_texture(Core::ITexture* const texture, const std::string fileName, uint16_t depth, TextureFormatType textureFormat) {
@@ -901,12 +901,12 @@ void VKFW::Tools::Loaders::load_3D_texture(Core::ITexture* const texture, const
901901
} else
902902
{
903903
#ifndef NDEBUG
904-
ERR_LOG("Failed to load texture PNG file" + fileName);
904+
LOG_ERROR("Failed to load texture PNG file" + fileName);
905905
#endif
906906
return;
907907
};
908908
#ifndef NDEBUG
909-
DEBUG_LOG("PNG Texture loaded successfully");
909+
LOG_DEBUG("PNG Texture loaded successfully");
910910
#endif // DEBUG
911911
}
912912

tests/skin/main.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,19 @@
33

44
int main(int argc, char* argv[])
55
{
6+
Logger::init(LogLevel::Debug, "skinTest.log");
67
Application app;
78
try
89
{
910
app.run(argc,argv);
1011
}
1112
catch (const std::exception &e)
1213
{
13-
std::cerr << e.what() << std::endl;
14+
LOG_ERROR(e.what());
15+
Logger::shutdown();
1416
return EXIT_FAILURE;
1517
}
16-
18+
19+
Logger::shutdown();
1720
return EXIT_SUCCESS;
1821
}

0 commit comments

Comments
 (0)