Skip to content

Commit

Permalink
dev: Guard logs to be able to use clang-uml.
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmin42 committed Sep 15, 2024
1 parent d555e20 commit a9f6843
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 10 deletions.
15 changes: 10 additions & 5 deletions PB/include/pb/persistence/SerializationStrategy.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ std::variant<Json, PBDev::Error> serialize(int depth, T object)
#else
Json json = object;
#endif

#ifndef _CLANG_UML_
spdlog::info("{}T {}\n", std::string(depth * 2, ' '), json.dump());
#endif
return json;
}

Expand All @@ -94,7 +95,9 @@ serialize(int depth, std::pair<std::string, T> const &entry)
#else
json[entry.first] = entry.second;
#endif
#ifndef _CLANG_UML_
spdlog::info("{}T {}\n", std::string(depth * 2, ' '), json.dump());
#endif
return json;
}

Expand All @@ -109,23 +112,25 @@ serialize(int depth, std::pair<std::string, Head> const &head,
if (std::holds_alternative<PBDev::Error>(jsonOrError)) {
return jsonOrError;
}
#ifndef _CLANG_UML_
spdlog::info("{}T {}\n", std::string(depth * 2, ' '),
std::get<Json>(jsonOrError).dump());

#endif
std::variant<Json, PBDev::Error> headJsonOrError =
serialize<Head>(depth + 1, head);

if (std::holds_alternative<PBDev::Error>(headJsonOrError)) {
return headJsonOrError;
}

#ifndef _CLANG_UML_
spdlog::info("{}T {}\n", std::string(depth * 2, ' '),
std::get<Json>(headJsonOrError).dump());

#endif
std::get<Json>(jsonOrError).update(std::get<Json>(headJsonOrError));

#ifndef _CLANG_UML_
spdlog::info("{}T {}\n", std::string(depth * 2, ' '),
std::get<Json>(jsonOrError).dump());
#endif
return jsonOrError;
}

Expand Down
2 changes: 2 additions & 0 deletions PB/src/CollageLibraryAssistant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ Path CollageLibraryAssistant::createNumberedImage(cv::Size pageSize,
auto imagePath = mOutputFolder / Path(name);
bool success = cv::imwrite(imagePath.string(), *image);
PBDev::basicAssert(success);
#ifndef _CLANG_UML_
spdlog::info("Image created: {}", (mOutputFolder / Path(name)).string());
#endif
return Path(name);
}
} // namespace PB
8 changes: 6 additions & 2 deletions PB/src/CollageThumbnailsMakerJob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,11 @@ void CollageThumbnailsMakerJob::createCustomSVGTemplate(unsigned i)
mProject->paperSettings.height / 2};

Path path = mSourceTemplates.at(i).path;
#ifndef _CLANG_UML_
spdlog::info("Generating thumbnail for template: {}", path.string());
auto processedPath = mAssistant->createTemplateThumbnail(mNumberedImages, path,
{4, 3}, imageSize);
#endif
auto processedPath = mAssistant->createTemplateThumbnail(
mNumberedImages, path, {4, 3}, imageSize);

mProcessedSVGPaths.push_back(processedPath);
}
Expand Down Expand Up @@ -175,8 +177,10 @@ void CollageThumbnailsMakerJob::mapJobs()
mNumberedImages = mAssistant->createNumberedImages(imageSize);

for (auto &collageTemplateInfo : templatesList) {
#ifndef _CLANG_UML_
spdlog::info("Generating thumbnail for template: {}",
collageTemplateInfo.path.string());
#endif
auto processedPath = mAssistant->createTemplateThumbnail(
mNumberedImages, collageTemplateInfo.path, {4, 3}, imageSize);

Expand Down
2 changes: 2 additions & 0 deletions PB/src/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ void basicAssert(int shouldBetrue, const std::source_location location)
std::string message = std::string(location.function_name()) + ":" +
std::to_string(location.line());

#ifndef _CLANG_UML_
spdlog::info("{}\n", message);
#endif
}
#ifdef _DEBUG
assert(shouldBetrue);
Expand Down
6 changes: 6 additions & 0 deletions PB/src/ImageOperations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,9 @@ void writeImageOnDisk(std::shared_ptr<cv::Mat> image, Path full)
{
bool success = cv::imwrite(full.string(), *image);
PBDev::basicAssert(success);
#ifndef _CLANG_UML_
spdlog::info("Image written to {}", full.string());
#endif
}

void imageWriteThumbnail(int screenWidth, int screenHeight,
Expand All @@ -396,7 +398,9 @@ void imageWriteThumbnail(int screenWidth, int screenHeight,

bool success = cv::imwrite(medium.string(), *mediumImagePointer);
PBDev::basicAssert(success);
#ifndef _CLANG_UML_
spdlog::info("Medium thumbnail written to {}", medium.string());
#endif

auto smallImagePointer = PB::Process::resize(
image,
Expand All @@ -405,7 +409,9 @@ void imageWriteThumbnail(int screenWidth, int screenHeight,

success = cv::imwrite(small.string(), *smallImagePointer);
PBDev::basicAssert(success);
#ifndef _CLANG_UML_
spdlog::info("Small thumbnail written to {}", small.string());
#endif
}

unsigned pointsFromPixels(double points, unsigned ppi)
Expand Down
2 changes: 2 additions & 0 deletions PB/src/SVGInflater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ std::optional<std::string> SVGInflater::inflate(BasicSVGModel svgModel,
return inja::render(content, model);
}
catch (const std::exception ex) {
#ifndef _CLANG_UML_
spdlog::error("Error rendering SVG: {}", ex.what());
#endif
return std::nullopt;
}
}
Expand Down
17 changes: 14 additions & 3 deletions PB/src/SerializationStrategy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,10 @@ serialize(int depth, std::pair<std::string, boost::uuids::uuid> const &entry)
{
Json json;
json[entry.first] = boost::uuids::to_string(entry.second);
#ifndef _CLANG_UML_
spdlog::info("{}(string, uuid) {}\n", std::string(depth * 2, ' '),
json.dump());
#endif
return json;
}

Expand All @@ -260,8 +262,10 @@ serialize(int depth, std::pair<std::string, std::vector<Path>> const &entry)
}
json[entry.first].push_back(std::get<Json>(jasonOrError));
}
#ifndef _CLANG_UML_
spdlog::info("{}(string, vector) {}\n", std::string(depth * 2, ' '),
json.dump());
#endif
return json;
}

Expand All @@ -277,9 +281,10 @@ serialize(int depth,
for (auto bimapEntry : entry.second) {
json[entry.first][bimapEntry.left.string()] = bimapEntry.right;
}

#ifndef _CLANG_UML_
spdlog::info("{}(bimap<Path, string>) {}\n", std::string(depth * 2, ' '),
json.dump());
#endif
return json;
}

Expand All @@ -298,8 +303,10 @@ serialize(int depth, std::pair<std::string, PaperSettings> const &entry)
}
Json json;
json[key] = std::get<Json>(jsonOrError);
#ifndef _CLANG_UML_
spdlog::info("{}(string, PaperSettings) {}\n", std::string(depth * 2, ' '),
json.dump());
#endif
return json;
}

Expand All @@ -318,8 +325,10 @@ serialize(int depth, std::pair<std::string, Project> const &entry)

Json json;
json[key] = std::get<Json>(jsonOrError);
#ifndef _CLANG_UML_
spdlog::info("{}(string, Project) {}\n", std::string(depth * 2, ' '),
json.dump());
#endif
return json;
}

Expand All @@ -332,10 +341,10 @@ serialize(int depth, std::pair<std::string, VirtualImageType> const &entry)
Json json;

json[key] = magic_enum::enum_name(imageType);

#ifndef _CLANG_UML_
spdlog::info("%s(string, RegularImage) %s\n",
std::string(depth * 2, ' ').c_str(), json.dump().c_str());

#endif
return json;
}

Expand All @@ -362,8 +371,10 @@ serialize(int depth,

Json json;
json[key] = std::get<Json>(jsonOrError);
#ifndef _CLANG_UML_
spdlog::info("%s(string, RegularImage) %s\n",
std::string(depth * 2, ' ').c_str(), json.dump());
#endif
return json;
}

Expand Down

0 comments on commit a9f6843

Please sign in to comment.