From f36d94183aaefd32ea0a0937ed66cfb8fd91eaac Mon Sep 17 00:00:00 2001 From: Vectozavr <60608292+vectozavr@users.noreply.github.com> Date: Sun, 17 Oct 2021 14:27:19 +0700 Subject: [PATCH] Code refactoring. --- engine/Consts.h | 1 + engine/utils/Log.cpp | 15 +++++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/engine/Consts.h b/engine/Consts.h index e9dbc4e..eb0798f 100644 --- a/engine/Consts.h +++ b/engine/Consts.h @@ -12,6 +12,7 @@ namespace Consts { const int STANDARD_SCREEN_HEIGHT = 1920; const sf::Color BACKGROUND_COLOR = sf::Color(255, 255, 255); const std::string PROJECT_NAME = "engine"; + const bool USE_LOG_FILE = true; const double PI = 3.14159265358979323846264338327950288; const double EPS = 0.000001; diff --git a/engine/utils/Log.cpp b/engine/utils/Log.cpp index 36c2065..2326b3f 100644 --- a/engine/utils/Log.cpp +++ b/engine/utils/Log.cpp @@ -10,16 +10,19 @@ #include #include #include +#include "../Consts.h" namespace Log { void log(const std::string& message) { - std::time_t const now_c = std::time(nullptr); - auto dt = std::put_time(std::localtime(&now_c), "%F %T"); + if(Consts::USE_LOG_FILE) { + std::time_t const now_c = std::time(nullptr); + auto dt = std::put_time(std::localtime(&now_c), "%F %T"); - std::fstream file("engine_log.txt", std::ios::out | std::ios::app); - file << dt << "\t" << message << " (" << Time::fps() << " fps)" << std::endl; - std::cout << dt << "\t" << message << " (" << Time::fps() << " fps)" << std::endl; - file.close(); + std::fstream file("engine_log.txt", std::ios::out | std::ios::app); + file << dt << "\t" << message << " (" << Time::fps() << " fps)" << std::endl; + std::cout << dt << "\t" << message << " (" << Time::fps() << " fps)" << std::endl; + file.close(); + } } }