Small adjustments in LogManager

This commit is contained in:
k1-801 2021-03-24 17:33:54 +04:00 committed by Adam Honse
parent 460e53368d
commit 1fdd4379a7
4 changed files with 26 additions and 18 deletions

View file

@ -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<std::mutex> 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;

View file

@ -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);

View file

@ -1,6 +1,7 @@
#include "ProfileManager.h"
#include "ResourceManager.h"
#include "RGBController_Dummy.h"
#include "LogManager.h"
#define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING
#include <experimental/filesystem>
#include <fstream>
@ -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)
{
/*---------------------------------------------------------*\

View file

@ -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);
}