Skip to content

Commit

Permalink
dev: Improve logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmin42 committed Sep 8, 2024
1 parent 9073931 commit e120015
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
9 changes: 9 additions & 0 deletions PB/include/pb/Config.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#pragma once

#pragma warning(push)
#pragma warning(disable : 4996)
#include <spdlog/sinks/msvc_sink.h>
#include <spdlog/sinks/stdout_color_sinks.h>
#include <spdlog/spdlog.h>
#pragma warning(pop)

#include <pb/AspectRatio.h>
#include <pb/project/PaperSettings.h>

Expand Down Expand Up @@ -83,6 +90,8 @@ static constexpr const char *DATABASE_NAME = "databasev2.db";

static constexpr unsigned MAX_HASH_CONFLICTS = 200;

static std::shared_ptr<spdlog::logger> LOGGER = nullptr;

} // namespace OneConfig

} // namespace PB
2 changes: 2 additions & 0 deletions PB/include/pb/PhotoBook.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class Photobook final : public PersistenceServiceListener,
std::pair<unsigned, unsigned> screenSize);
~Photobook() = default;

void initLogger();

void configure(PhotobookListener *listener);
void configure(StagedImagesListener *listener);
void configure(ImageMonitorListener *listener);
Expand Down
18 changes: 18 additions & 0 deletions PB/src/PhotoBook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ Photobook::Photobook(Path localStatePath, Path installationPath,
std::make_shared<DirectoryInspectionService>()),
mOGLEngine(std::make_shared<OGLEngine>())
{

initLogger();

ImageFactory::inst().configurePlatformInfo(mPlatformInfo);
ImageFactory::inst().configurePersistenceService(mPersistenceService);

Expand Down Expand Up @@ -108,6 +111,21 @@ Photobook::Photobook(Path localStatePath, Path installationPath,
mImageToPaperService->configureTaskCruncher(mTaskCruncher);
}

void Photobook::initLogger()
{
try {
#ifdef WIN32
OneConfig::LOGGER = std::make_shared<spdlog::logger>(
"msvc_logger", std::make_shared<spdlog::sinks::msvc_sink_mt>());
OneConfig::LOGGER->set_level(spdlog::level::debug);
OneConfig::LOGGER->info("Log init succeeded");
#endif
}
catch (const spdlog::spdlog_ex &ex) {
std::cout << "Log init failed: " << ex.what() << std::endl;
}
}

void Photobook::configure(PhotobookListener *listener) { mParent = listener; }

void Photobook::configure(StagedImagesListener *listener)
Expand Down
12 changes: 12 additions & 0 deletions PB/tests/TestMain.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
#include <gtest/gtest.h>

#include <pb/Config.h>

int main(int argc, char **argv)
{
try {
PB::OneConfig::LOGGER = std::make_shared<spdlog::logger>(
"console_logger",
std::make_shared<spdlog::sinks::stdout_color_sink_mt>());
PB::OneConfig::LOGGER->set_level(spdlog::level::debug);
PB::OneConfig::LOGGER->info("Log init succeeded");
}
catch (const spdlog::spdlog_ex &ex) {
std::cout << "Log init failed: " << ex.what() << std::endl;
}
::testing::GTEST_FLAG(filter) = "TestProjectManagementSystem.*";
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
Expand Down

0 comments on commit e120015

Please sign in to comment.