Skip to content

Commit

Permalink
Reduce useless log spam
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Jun 23, 2023
1 parent aeb16f1 commit c6d8c7f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/mods/vr/D3D11Component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace pixel_shader1 {
}

#include <utility/ScopeGuard.hpp>
#include <utility/Logging.hpp>

#include "Framework.hpp"
#include "../VR.hpp"
Expand Down Expand Up @@ -784,7 +785,7 @@ void D3D11Component::copy_tex(ID3D11Resource* src, ID3D11Resource* dst) {
}

bool D3D11Component::setup() {
spdlog::info("[VR] Setting up D3D11 textures...");
SPDLOG_INFO_EVERY_N_SEC(1, "[VR] Setting up D3D11 textures...");

on_reset(VR::get().get());

Expand All @@ -809,7 +810,7 @@ bool D3D11Component::setup() {
}

if (backbuffer == nullptr) {
spdlog::error("[VR] Failed to get back buffer (D3D11).");
SPDLOG_ERROR_EVERY_N_SEC(1, "[VR] Failed to get back buffer (D3D11).");
return false;
}

Expand Down
7 changes: 4 additions & 3 deletions src/mods/vr/D3D12Component.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <openvr.h>
#include <utility/String.hpp>
#include <utility/ScopeGuard.hpp>
#include <utility/Logging.hpp>

#include "Framework.hpp"
#include "../VR.hpp"
Expand Down Expand Up @@ -820,7 +821,7 @@ void D3D12Component::on_reset(VR* vr) {
}

bool D3D12Component::setup() {
spdlog::info("[VR] Setting up d3d12 textures...");
SPDLOG_INFO_EVERY_N_SEC(1, "[VR] Setting up d3d12 textures...");

auto vr = VR::get();
on_reset(vr.get());
Expand All @@ -841,7 +842,7 @@ bool D3D12Component::setup() {
}

if (backbuffer == nullptr) {
spdlog::error("[VR] Failed to get back buffer (D3D12).");
SPDLOG_ERROR_EVERY_N_SEC(1, "[VR] Failed to get back buffer (D3D12).");
return false;
}

Expand All @@ -851,7 +852,7 @@ bool D3D12Component::setup() {

ComPtr<ID3D12Resource> real_backbuffer{};
if (FAILED(swapchain->GetBuffer(0, IID_PPV_ARGS(&real_backbuffer)))) {
spdlog::error("[VR] Failed to get back buffer (D3D12).");
spdlog::error("[VR] Failed to get real back buffer (D3D12).");
return false;
}

Expand Down
8 changes: 7 additions & 1 deletion src/utility/Logging.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
#pragma once

#include <chrono>

#include <spdlog/spdlog.h>

#define SPDLOG_INFO_ONCE(...) {static bool once = true; if (once) { SPDLOG_INFO(__VA_ARGS__); once = false; }}
#define SPDLOG_WARN_ONCE(...) {static bool once = true; if (once) { SPDLOG_WARN(__VA_ARGS__); once = false; }}
#define SPDLOG_ERROR_ONCE(...) {static bool once = true; if (once) { SPDLOG_ERROR(__VA_ARGS__); once = false; }}
#define SPDLOG_ERROR_ONCE(...) {static bool once = true; if (once) { SPDLOG_ERROR(__VA_ARGS__); once = false; }}

#define SPDLOG_INFO_EVERY_N_SEC(n, ...) {static auto last = std::chrono::steady_clock::now(); auto now = std::chrono::steady_clock::now(); if (now - last >= std::chrono::seconds(n)) { SPDLOG_INFO(__VA_ARGS__); last = now; }}
#define SPDLOG_WARNING_EVERY_N_SEC(n, ...) {static auto last = std::chrono::steady_clock::now(); auto now = std::chrono::steady_clock::now(); if (now - last >= std::chrono::seconds(n)) { SPDLOG_WARN(__VA_ARGS__); last = now; }}
#define SPDLOG_ERROR_EVERY_N_SEC(n, ...) {static auto last = std::chrono::steady_clock::now(); auto now = std::chrono::steady_clock::now(); if (now - last >= std::chrono::seconds(n)) { SPDLOG_ERROR(__VA_ARGS__); last = now; }}

0 comments on commit c6d8c7f

Please sign in to comment.