mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-08-04 09:44:10 +00:00
Added a LogDebug
- Added debug logging - Created vLog, a root function for all log functions - Placed failed to load script log under this new LogDebug function - Updated included config functions
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
#include "dLogger.h"
|
||||
|
||||
dLogger::dLogger(const std::string& outpath, bool logToConsole) {
|
||||
dLogger::dLogger(const std::string& outpath, bool logToConsole, bool logDebugStatements) {
|
||||
m_logToConsole = logToConsole;
|
||||
m_logDebugStatements = logDebugStatements;
|
||||
m_outpath = outpath;
|
||||
|
||||
#ifdef _WIN32
|
||||
@@ -24,39 +25,26 @@ dLogger::~dLogger() {
|
||||
#endif
|
||||
}
|
||||
|
||||
void dLogger::LogBasic(const std::string & message) {
|
||||
LogBasic(message.c_str());
|
||||
}
|
||||
|
||||
void dLogger::LogBasic(const char * format, ...) {
|
||||
void dLogger::vLog(const char* format, va_list args) {
|
||||
#ifdef _WIN32
|
||||
time_t t = time(NULL);
|
||||
struct tm time;
|
||||
localtime_s(&time, &t);
|
||||
|
||||
char timeStr[70];
|
||||
|
||||
strftime(timeStr, sizeof(timeStr), "%d-%m-%y %H:%M:%S", &time);
|
||||
|
||||
char message[2048];
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
vsprintf_s(message, format, args);
|
||||
va_end(args);
|
||||
|
||||
if (m_logToConsole) std::cout << "[" << "time machine broke" << "] " << message;
|
||||
mFile << "[" << "time" << "] " << message;
|
||||
if (m_logToConsole) std::cout << "[" << timeStr << "] " << message;
|
||||
mFile << "[" << timeStr << "] " << message;
|
||||
#else
|
||||
time_t t = time(NULL);
|
||||
struct tm * time = localtime(&t);
|
||||
char timeStr[70];
|
||||
strftime(timeStr, sizeof(timeStr), "%d-%m-%y %H:%M:%S", time);
|
||||
|
||||
struct tm time;
|
||||
localtime_s(&time, &t);
|
||||
char timeStr[70];
|
||||
strftime(timeStr, sizeof(timeStr), "%d-%m-%y %H:%M:%S", &time);
|
||||
char message[2048];
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
vsprintf(message, format, args);
|
||||
va_end(args);
|
||||
|
||||
if (m_logToConsole) {
|
||||
fputs("[", stdout);
|
||||
@@ -76,62 +64,42 @@ void dLogger::LogBasic(const char * format, ...) {
|
||||
#endif
|
||||
}
|
||||
|
||||
void dLogger::Log(const char * className, const char * format, ...) {
|
||||
#ifdef _WIN32
|
||||
time_t t = time(NULL);
|
||||
struct tm time;
|
||||
localtime_s(&time, &t);
|
||||
|
||||
char timeStr[70];
|
||||
strftime(timeStr, sizeof(timeStr), "%d-%m-%y %H:%M:%S", &time);
|
||||
|
||||
char message[2048];
|
||||
void dLogger::LogBasic(const char * format, ...) {
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
vsprintf_s(message, format, args);
|
||||
|
||||
vLog(format, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
if (m_logToConsole) std::cout << "[" << timeStr << "] [" << className << "]: " << message;
|
||||
mFile << "[" << timeStr << "] [" << className << "]: " << message;
|
||||
#else
|
||||
time_t t = time(NULL);
|
||||
struct tm * time = localtime(&t);
|
||||
char timeStr[70];
|
||||
strftime(timeStr, sizeof(timeStr), "%d-%m-%y %H:%M:%S", time);
|
||||
|
||||
char message[2048];
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
vsprintf(message, format, args);
|
||||
va_end(args);
|
||||
|
||||
if (m_logToConsole) {
|
||||
fputs("[", stdout);
|
||||
fputs(timeStr, stdout);
|
||||
fputs("] ", stdout);
|
||||
fputs("[", stdout);
|
||||
fputs(className, stdout);
|
||||
fputs("]: ", stdout);
|
||||
fputs(message, stdout);
|
||||
}
|
||||
|
||||
if (fp != NULL) {
|
||||
fputs("[", fp);
|
||||
fputs(timeStr, fp);
|
||||
fputs("] ", fp);
|
||||
fputs("[", fp);
|
||||
fputs(className, fp);
|
||||
fputs("]: ", fp);
|
||||
fputs(message, fp);
|
||||
}
|
||||
#endif
|
||||
void dLogger::LogBasic(const std::string & message) {
|
||||
LogBasic(message.c_str());
|
||||
}
|
||||
|
||||
void dLogger::Log(const char * className, const char * format, ...) {
|
||||
va_list args;
|
||||
std::string log = "[" + std::string(className) + "] " + std::string(format);
|
||||
va_start(args, format);
|
||||
vLog(log.c_str(), args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void dLogger::Log(const std::string & className, const std::string & message) {
|
||||
Log(className.c_str(), message.c_str());
|
||||
}
|
||||
|
||||
void dLogger::LogDebug(const char * className, const char * format, ...) {
|
||||
if (!m_logDebugStatements) return;
|
||||
va_list args;
|
||||
std::string log = "[" + std::string(className) + "] " + std::string(format);
|
||||
va_start(args, format);
|
||||
vLog(log.c_str(), args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void dLogger::LogDebug(const std::string & className, const std::string & message) {
|
||||
LogDebug(className.c_str(), message.c_str());
|
||||
}
|
||||
|
||||
void dLogger::Flush() {
|
||||
#ifdef _WIN32
|
||||
mFile.flush();
|
||||
|
@@ -7,21 +7,26 @@
|
||||
|
||||
class dLogger {
|
||||
public:
|
||||
dLogger(const std::string& outpath, bool logToConsole);
|
||||
dLogger(const std::string& outpath, bool logToConsole, bool logDebugStatements);
|
||||
~dLogger();
|
||||
|
||||
void SetLogToConsole(bool logToConsole) { m_logToConsole = logToConsole; }
|
||||
void SetLogDebugStatements(bool logDebugStatements) { m_logDebugStatements = logDebugStatements; }
|
||||
void vLog(const char* format, va_list args);
|
||||
|
||||
void LogBasic(const std::string& message);
|
||||
void LogBasic(const char* format, ...);
|
||||
void Log(const char* className, const char* format, ...);
|
||||
void Log(const std::string& className, const std::string& message);
|
||||
void LogDebug(const std::string& className, const std::string& message);
|
||||
void LogDebug(const char* className, const char* format, ...);
|
||||
|
||||
void Flush();
|
||||
|
||||
const bool GetIsLoggingToConsole() const { return m_logToConsole; }
|
||||
|
||||
private:
|
||||
bool m_logDebugStatements;
|
||||
bool m_logToConsole;
|
||||
std::string m_outpath;
|
||||
std::ofstream mFile;
|
||||
|
Reference in New Issue
Block a user