package_build_report.cpp 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #include <array>
  2. #include <atomic>
  3. #include <cstdio>
  4. #include "../../../../core/logging/log.h"
  5. #include "internal.h"
  6. namespace sunrise::client::content::items::packages {
  7. namespace {
  8. std::atomic<bool> g_reported{};
  9. } // namespace
  10. /** @param slot Requested-set position. @param definitionIndex Native item index that failed. */
  11. void report_detail_failure(std::size_t slot, std::uint16_t definitionIndex) noexcept {
  12. std::array<char, 96> line{};
  13. const int written = std::snprintf(line.data(),
  14. line.size(),
  15. "ev=pkg stage=details result=fail slot=%zu index=%u",
  16. slot,
  17. static_cast<unsigned>(definitionIndex));
  18. if (written > 0) {
  19. core::log::write(core::log::Channel::client,
  20. core::log::Level::warn,
  21. {line.data(), static_cast<std::size_t>(written)});
  22. }
  23. }
  24. /** @param count Ability bucket rows the pass built, one per subclass and movement selection. */
  25. void report_ability_count(std::size_t count) noexcept {
  26. std::array<char, 96> line{};
  27. const int written =
  28. std::snprintf(line.data(), line.size(), "ev=pkg stage=abilities result=ok rows=%zu", count);
  29. if (written > 0) {
  30. core::log::write(core::log::Channel::client,
  31. core::log::Level::info,
  32. {line.data(), static_cast<std::size_t>(written)});
  33. }
  34. }
  35. /** @param count Detail rows the pass built, covering equipped items and every plug they socket. */
  36. void report_detail_count(std::size_t count) noexcept {
  37. std::array<char, 96> line{};
  38. const int written =
  39. std::snprintf(line.data(), line.size(), "ev=pkg stage=details result=ok rows=%zu", count);
  40. if (written > 0) {
  41. core::log::write(core::log::Channel::client,
  42. core::log::Level::info,
  43. {line.data(), static_cast<std::size_t>(written)});
  44. }
  45. }
  46. /** Reports the pass outcome once. @param published Rows published, or zero on failure. */
  47. void report(std::size_t published, const char* reason) noexcept {
  48. if (g_reported.exchange(true, std::memory_order_relaxed)) {
  49. return;
  50. }
  51. std::array<char, 96> line{};
  52. const int written = published != 0
  53. ? std::snprintf(line.data(),
  54. line.size(),
  55. "ev=build_data stage=items result=ok rows=%zu",
  56. published)
  57. : std::snprintf(line.data(),
  58. line.size(),
  59. "ev=build_data stage=items result=fail reason=%s",
  60. reason);
  61. if (written > 0) {
  62. core::log::write(core::log::Channel::client,
  63. published != 0 ? core::log::Level::info : core::log::Level::warn,
  64. {line.data(), static_cast<std::size_t>(written)});
  65. }
  66. }
  67. } // namespace sunrise::client::content::items::packages