From 1fdd4379a747950065ccd6232586a8e0e04ce2dd Mon Sep 17 00:00:00 2001 From: k1-801 Date: Wed, 24 Mar 2021 17:33:54 +0400 Subject: [PATCH] Small adjustments in LogManager --- LogManager.cpp | 37 ++++++++++++++++++++++--------------- LogManager.h | 1 - ProfileManager.cpp | 3 +++ ResourceManager.cpp | 3 +-- 4 files changed, 26 insertions(+), 18 deletions(-) diff --git a/LogManager.cpp b/LogManager.cpp index 0b8dcaaab..9d7fca80e 100644 --- a/LogManager.cpp +++ b/LogManager.cpp @@ -63,30 +63,42 @@ void LogManager::configure(json config, const std::string &defaultDir) | If the # symbol is found in the log file name, | | replace it with a timestamp | \*-------------------------------------------------*/ + time_t t = time(0); + struct tm* tmp = localtime(&t); + char time_string[64]; + snprintf(time_string, 64, "%04d%02d%02d_%02d%02d%02d", 1900 + tmp->tm_year, tmp->tm_mon + 1, tmp->tm_mday, tmp->tm_hour, tmp->tm_min, tmp->tm_sec); + size_t oct = logname.find("#"); if(oct != logname.npos) { - time_t t = time(0); - struct tm* tmp = localtime(&t); - char buf[64]; - snprintf(buf, 64, "%04d%02d%02d_%02d%02d%02d", 1900 + tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_hour, tmp->tm_min, tmp->tm_sec); - logname.replace(oct, 1, buf); + logname.replace(oct, 1, time_string); } /*-------------------------------------------------*\ - | If the path is relative, use configuration dir | + | If the path is relative, use logs dir | \*-------------------------------------------------*/ fs::path p = logname; if(p.is_relative()) { p = defaultDir; + p.append("/logs/"); p.append(logname); } + fs::create_directories(p.parent_path()); /*-------------------------------------------------*\ | Open the logfile | \*-------------------------------------------------*/ log_stream.open(p); + + /*-------------------------------------------------*\ + | Print Git Commit info, version, etc. | + \*-------------------------------------------------*/ + log_stream << " OpenRGB v" << VERSION_STRING << std::endl; + log_stream << " Commit: " << GIT_COMMIT_ID << " from " << GIT_COMMIT_DATE << std::endl; + log_stream << " Launched: " << time_string << std::endl; + log_stream << "====================================================================================================" << std::endl; + log_stream << std::endl; } /*-------------------------------------------------*\ @@ -174,9 +186,11 @@ void LogManager::_append(const char* filename, int line, unsigned int level, con /*-------------------------------------------------*\ | Resize the buffer, then fill in the message text | \*-------------------------------------------------*/ + va_list va2; + va_copy(va2, va); int len = vsnprintf(nullptr, 0, fmt, va); - mes->buffer.resize(len); - vsnprintf(&mes->buffer[0], len + 1, fmt, va); + mes->buffer.resize(len + 1); + vsnprintf(&(mes->buffer[0]), len + 1, fmt, va2); /*-------------------------------------------------*\ | Fill in message information | @@ -223,13 +237,6 @@ void LogManager::_append(const char* filename, int line, unsigned int level, con _flush(); } -void LogManager::append(const char* filename, int line, unsigned int level, const char* fmt, va_list va) -{ - std::lock_guard grd(entry_mutex); - - _append(filename, line, level, fmt, va); -} - void LogManager::append(const char* filename, int line, unsigned int level, const char* fmt, ...) { va_list va; diff --git a/LogManager.h b/LogManager.h index 5098a71c3..116973779 100644 --- a/LogManager.h +++ b/LogManager.h @@ -68,7 +68,6 @@ public: static LogManager* get(); void configure(json config, const std::string& defaultDir); void flush(); - void append(const char* filename, int line, unsigned int level, const char* fmt, va_list va); void append(const char* filename, int line, unsigned int level, const char* fmt, ...); void setLoglevel(unsigned int); void setVerbosity(unsigned int); diff --git a/ProfileManager.cpp b/ProfileManager.cpp index 4cddf5970..2ee5b9ebe 100644 --- a/ProfileManager.cpp +++ b/ProfileManager.cpp @@ -1,6 +1,7 @@ #include "ProfileManager.h" #include "ResourceManager.h" #include "RGBController_Dummy.h" +#include "LogManager.h" #define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING #include #include @@ -379,6 +380,8 @@ void ProfileManager::UpdateProfileList() { std::string filename = entry.path().filename().string(); + LOG_NOTICE("Loading profile: %s", filename.c_str()); + if(filename.find(".orp") != std::string::npos) { /*---------------------------------------------------------*\ diff --git a/ResourceManager.cpp b/ResourceManager.cpp index c22f5935a..5f383ee75 100644 --- a/ResourceManager.cpp +++ b/ResourceManager.cpp @@ -74,8 +74,7 @@ ResourceManager::~ResourceManager() void ResourceManager::RegisterI2CBus(i2c_smbus_interface *bus) { - std::string bus_name = bus->device_name; - LOG_NOTICE("Registering I2C interface: %s", bus_name.c_str()); + LOG_NOTICE("Registering I2C interface: %s", bus->device_name); busses.push_back(bus); }