Browse Source

Tab2Space & Newlines

peercoin
Intel 12 years ago
parent
commit
57c65a4ba2
  1. 2
      src/server/poolserver/Database/ServerDatabaseEnv.cpp
  2. 2
      src/server/poolserver/Database/ServerDatabaseEnv.h
  3. 76
      src/server/poolserver/Main.cpp
  4. 18
      src/server/poolserver/Server/Server.cpp
  5. 24
      src/server/shared/Configuration/Config.h
  6. 16
      src/server/shared/Database/Database.h
  7. 2
      src/server/shared/Database/DatabaseCallback.h
  8. 2
      src/server/shared/Database/DatabaseEnv.h
  9. 2
      src/server/shared/Database/Field.h
  10. 2
      src/server/shared/Database/MySQL/DatabaseConnectionMySQL.cpp
  11. 14
      src/server/shared/Database/MySQL/DatabaseConnectionMySQL.h
  12. 2
      src/server/shared/Database/MySQL/DatabaseEnvMySQL.h
  13. 2
      src/server/shared/Database/MySQL/DatabaseOperationMySQL.cpp
  14. 2
      src/server/shared/Database/MySQL/DatabaseOperationMySQL.h
  15. 2
      src/server/shared/Database/MySQL/DatabaseWorkerMySQL.h
  16. 16
      src/server/shared/Database/MySQL/DatabaseWorkerPoolMySQL.h
  17. 2
      src/server/shared/Database/MySQL/FieldMySQL.h
  18. 2
      src/server/shared/Database/MySQL/PreparedStatementMySQL.cpp
  19. 2
      src/server/shared/Database/MySQL/PreparedStatementMySQL.h
  20. 2
      src/server/shared/Database/MySQL/QueryResultMySQL.h
  21. 2
      src/server/shared/Database/PreparedStatement.h
  22. 2
      src/server/shared/Database/QueryResult.h
  23. 118
      src/server/shared/Logging/Log.cpp
  24. 46
      src/server/shared/Logging/Log.h
  25. 2
      src/server/shared/Util.cpp
  26. 2
      src/server/shared/Util.h

2
src/server/poolserver/Database/ServerDatabaseEnv.cpp

@ -1,3 +1,3 @@
#include "ServerDatabaseEnv.h" #include "ServerDatabaseEnv.h"
ServerDatabaseWorkerPoolMySQL sDatabase; ServerDatabaseWorkerPoolMySQL sDatabase;

2
src/server/poolserver/Database/ServerDatabaseEnv.h

@ -9,4 +9,4 @@ class ServerDatabaseWorkerPoolMySQL : public DatabaseWorkerPoolMySQL
extern ServerDatabaseWorkerPoolMySQL sDatabase; extern ServerDatabaseWorkerPoolMySQL sDatabase;
#endif #endif

76
src/server/poolserver/Main.cpp

@ -9,41 +9,41 @@ bool InitConfig(int argc, char *argv[])
{ {
// Containers // Containers
boost::program_options::options_description descGeneric("Generic Options"); boost::program_options::options_description descGeneric("Generic Options");
boost::program_options::options_description descServer("Server Configuration"); boost::program_options::options_description descServer("Server Configuration");
boost::program_options::options_description descStratum("Stratum Configuration"); boost::program_options::options_description descStratum("Stratum Configuration");
boost::program_options::options_description descLogging("Logging Configuration"); boost::program_options::options_description descLogging("Logging Configuration");
boost::program_options::options_description descDatabase("Database Configuration"); boost::program_options::options_description descDatabase("Database Configuration");
#ifdef WITH_MYSQL #ifdef WITH_MYSQL
boost::program_options::options_description descMySQL("MySQL Configuration"); boost::program_options::options_description descMySQL("MySQL Configuration");
#endif #endif
boost::program_options::options_description cmdlineOptions; boost::program_options::options_description cmdlineOptions;
boost::program_options::options_description fileOptions; boost::program_options::options_description fileOptions;
// Generic // Generic
descGeneric.add_options() descGeneric.add_options()
("version,v", "print version string") ("version,v", "print version string")
("help,h", "produce help message") ("help,h", "produce help message")
("config,c", boost::program_options::value<std::string>()->default_value("poolserver.cfg"),"name of a file of a configuration.") ("config,c", boost::program_options::value<std::string>()->default_value("poolserver.cfg"),"name of a file of a configuration.")
; ;
// Server // Server
descServer.add_options() descServer.add_options()
("MinDiffTime", boost::program_options::value<uint32_t>()->default_value(100), "Minimum server diff time") ("MinDiffTime", boost::program_options::value<uint32_t>()->default_value(100), "Minimum server diff time")
; ;
// Stratum // Stratum
descStratum.add_options() descStratum.add_options()
("StratumHost,sh", boost::program_options::value<std::string>()->default_value("0.0.0.0"), "Stratum server host") ("StratumHost,sh", boost::program_options::value<std::string>()->default_value("0.0.0.0"), "Stratum server host")
("StratumPort,sp", boost::program_options::value<uint16_t>()->default_value(3333), "Stratum server port") ("StratumPort,sp", boost::program_options::value<uint16_t>()->default_value(3333), "Stratum server port")
; ;
// Logging // Logging
descLogging.add_options() descLogging.add_options()
("LogConsoleLevel", boost::program_options::value<uint32_t>()->default_value(LOG_LEVEL_INFO), "Console log level (0-None, 1-Error, 2-Warn, 3-Info, 4-Debug)") ("LogConsoleLevel", boost::program_options::value<uint32_t>()->default_value(LOG_LEVEL_INFO), "Console log level (0-None, 1-Error, 2-Warn, 3-Info, 4-Debug)")
("LogConsoleDebugMask", boost::program_options::value<uint32_t>()->default_value(0), "Console log debug mask") ("LogConsoleDebugMask", boost::program_options::value<uint32_t>()->default_value(0), "Console log debug mask")
("LogFilePath", boost::program_options::value<std::string>()->default_value("."), "File log path") ("LogFilePath", boost::program_options::value<std::string>()->default_value("."), "File log path")
("LogFileLevel", boost::program_options::value<uint32_t>()->default_value(LOG_LEVEL_WARN), "File log level (0-None, 1-Error, 2-Warn, 3-Info, 4-Debug)") ("LogFileLevel", boost::program_options::value<uint32_t>()->default_value(LOG_LEVEL_WARN), "File log level (0-None, 1-Error, 2-Warn, 3-Info, 4-Debug)")
("LogFileDebugMask", boost::program_options::value<uint32_t>()->default_value(0), "File log debug mask") ("LogFileDebugMask", boost::program_options::value<uint32_t>()->default_value(0), "File log debug mask")
; ;
// Database // Database
@ -62,39 +62,39 @@ bool InitConfig(int argc, char *argv[])
; ;
descDatabase.add(descMySQL); descDatabase.add(descMySQL);
#endif #endif
cmdlineOptions.add(descGeneric).add(descServer).add(descStratum).add(descLogging).add(descDatabase); cmdlineOptions.add(descGeneric).add(descServer).add(descStratum).add(descLogging).add(descDatabase);
fileOptions.add(descServer).add(descStratum).add(descLogging).add(descDatabase); fileOptions.add(descServer).add(descStratum).add(descLogging).add(descDatabase);
store(boost::program_options::command_line_parser(argc, argv).options(cmdlineOptions).run(), sConfig.vm); store(boost::program_options::command_line_parser(argc, argv).options(cmdlineOptions).run(), sConfig.vm);
notify(sConfig.vm); notify(sConfig.vm);
if (sConfig.vm.count("help")) { if (sConfig.vm.count("help")) {
std::cout << cmdlineOptions << std::endl; std::cout << cmdlineOptions << std::endl;
return false; return false;
} }
std::ifstream ifs(sConfig.Get<std::string>("config").c_str()); std::ifstream ifs(sConfig.Get<std::string>("config").c_str());
if (!ifs.is_open()) { if (!ifs.is_open()) {
sLog.Error(LOG_GENERAL, "Failed opening config file: %s", sConfig.Get<std::string>("config").c_str()); sLog.Error(LOG_GENERAL, "Failed opening config file: %s", sConfig.Get<std::string>("config").c_str());
return false; return false;
} }
store(parse_config_file(ifs, fileOptions), sConfig.vm); store(parse_config_file(ifs, fileOptions), sConfig.vm);
notify(sConfig.vm); notify(sConfig.vm);
return true; return true;
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
if (!InitConfig(argc, argv)) if (!InitConfig(argc, argv))
return 0; return 0;
sLog.OpenLogFile(sConfig.Get<std::string>("LogFilePath")); sLog.OpenLogFile(sConfig.Get<std::string>("LogFilePath"));
sLog.Info(LOG_GENERAL, "LogFile Started: %s", sLog.logFileLoc.c_str()); sLog.Info(LOG_GENERAL, "LogFile Started: %s", sLog.logFileLoc.c_str());
Server* server = new Server(); Server* server = new Server();
int exitcode = server->Run(); int exitcode = server->Run();
delete server; delete server;

18
src/server/poolserver/Server/Server.cpp

@ -19,27 +19,27 @@ Server::~Server()
int Server::Run() int Server::Run()
{ {
sLog.Info(LOG_SERVER, "Server is starting..."); sLog.Info(LOG_SERVER, "Server is starting...");
InitDatabase(); InitDatabase();
sDatabase.Execute("INSERT INTO `test_table` VALUES ('999', 'sync', '1.1')"); sDatabase.Execute("INSERT INTO `test_table` VALUES ('999', 'sync', '1.1')");
sDatabase.ExecuteAsync("INSERT INTO `test_table` VALUES ('999', 'sync', '1.1')"); sDatabase.ExecuteAsync("INSERT INTO `test_table` VALUES ('999', 'sync', '1.1')");
// Start stratum server // Start stratum server
sLog.Info(LOG_SERVER, "Starting stratum"); sLog.Info(LOG_SERVER, "Starting stratum");
//stratumServer = new Stratum::Server(Config::GetString("STRATUM_IP"), Config::GetInt("STRATUM_PORT")); //stratumServer = new Stratum::Server(Config::GetString("STRATUM_IP"), Config::GetInt("STRATUM_PORT"));
// Init loop vars // Init loop vars
uint32_t sleepDuration = 0; uint32_t sleepDuration = 0;
int exitcode = 0; int exitcode = 0;
running = true; running = true;
// Init diff // Init diff
uint32_t minDiffTime = sConfig.Get<uint32_t>("MinDiffTime"); uint32_t minDiffTime = sConfig.Get<uint32_t>("MinDiffTime");
diffStart = boost::chrono::steady_clock::now(); diffStart = boost::chrono::steady_clock::now();
sLog.Info(LOG_SERVER, "Server is running!"); sLog.Info(LOG_SERVER, "Server is running!");
while (running) while (running)
{ {
@ -60,8 +60,8 @@ int Server::Run()
++serverLoops; ++serverLoops;
if (serverLoops > 50) if (serverLoops > 50)
running = false; running = false;
//std::cout << "Diff: " << diff << ", Loop: " << serverLoops << std::endl; //std::cout << "Diff: " << diff << ", Loop: " << serverLoops << std::endl;
} }

24
src/server/shared/Configuration/Config.h

@ -9,18 +9,18 @@
class Config class Config
{ {
public: public:
Config(); Config();
~Config(); ~Config();
// Reading // Reading
template<class T> template<class T>
T Get(std::string key) T Get(std::string key)
{ {
return vm[key].as<T>(); return vm[key].as<T>();
} }
// Containers // Containers
boost::program_options::variables_map vm; boost::program_options::variables_map vm;
}; };
extern Config sConfig; extern Config sConfig;

16
src/server/shared/Database/Database.h

@ -9,22 +9,22 @@
class Database class Database
{ {
public: public:
// Queries // Queries
virtual bool Execute(const char* query) = 0; virtual bool Execute(const char* query) = 0;
virtual ResultSet* Query(const char* query) = 0; virtual ResultSet* Query(const char* query) = 0;
// Stmt // Stmt
virtual bool Execute(PreparedStatement* stmt) = 0; virtual bool Execute(PreparedStatement* stmt) = 0;
virtual ResultSet* Query(PreparedStatement* stmt) = 0; virtual ResultSet* Query(PreparedStatement* stmt) = 0;
// Async // Async
virtual bool ExecuteAsync(const char* query) = 0; virtual bool ExecuteAsync(const char* query) = 0;
virtual bool ExecuteAsync(PreparedStatement* stmt) = 0; virtual bool ExecuteAsync(PreparedStatement* stmt) = 0;
virtual bool QueryAsync(DatabaseCallback callback, const char* query) = 0; virtual bool QueryAsync(DatabaseCallback callback, const char* query) = 0;
virtual bool QueryAsync(DatabaseCallback callback, PreparedStatement* stmt) = 0; virtual bool QueryAsync(DatabaseCallback callback, PreparedStatement* stmt) = 0;
// Prepared Statements // Prepared Statements
virtual PreparedStatement* GetPreparedStatement(uint32_t index) = 0; virtual PreparedStatement* GetPreparedStatement(uint32_t index) = 0;
}; };
#endif #endif

2
src/server/shared/Database/DatabaseCallback.h

@ -7,4 +7,4 @@
typedef boost::function<void(ResultSet*)> DatabaseCallback; typedef boost::function<void(ResultSet*)> DatabaseCallback;
#endif #endif

2
src/server/shared/Database/DatabaseEnv.h

@ -7,4 +7,4 @@
#include "MySQL/DatabaseEnvMySQL.h" #include "MySQL/DatabaseEnvMySQL.h"
#endif #endif
#endif #endif

2
src/server/shared/Database/Field.h

@ -8,4 +8,4 @@ public:
//virtual Get(); //virtual Get();
}; };
#endif #endif

2
src/server/shared/Database/MySQL/DatabaseConnectionMySQL.cpp

@ -146,4 +146,4 @@ ResultSetMySQL* DatabaseConnectionMySQL::Query(PreparedStatement* stmt)
bool DatabaseConnectionMySQL::_HandleMySQLErrno(uint32_t lErrno) bool DatabaseConnectionMySQL::_HandleMySQLErrno(uint32_t lErrno)
{ {
return false; return false;
} }

14
src/server/shared/Database/MySQL/DatabaseConnectionMySQL.h

@ -35,18 +35,18 @@ public:
void Close(); void Close();
// Ping! // Ping!
void Ping() void Ping()
{ {
mysql_ping(_mysql); mysql_ping(_mysql);
} }
// Queries // Queries
bool Execute(const char* query); bool Execute(const char* query);
ResultSetMySQL* Query(const char* query); ResultSetMySQL* Query(const char* query);
// Stmt // Stmt
bool Execute(PreparedStatement* stmt); bool Execute(PreparedStatement* stmt);
ResultSetMySQL* Query(PreparedStatement* stmt); ResultSetMySQL* Query(PreparedStatement* stmt);
// Locking // Locking
bool LockIfReady() bool LockIfReady()
@ -76,4 +76,4 @@ private:
MySQLConnectionInfo _connectionInfo; MySQLConnectionInfo _connectionInfo;
}; };
#endif #endif

2
src/server/shared/Database/MySQL/DatabaseEnvMySQL.h

@ -3,4 +3,4 @@
#include "DatabaseWorkerPoolMySQL.h" #include "DatabaseWorkerPoolMySQL.h"
#endif #endif

2
src/server/shared/Database/MySQL/DatabaseOperationMySQL.cpp

@ -23,4 +23,4 @@ void DatabaseQueryOperationMySQL::Execute()
_callback(result); _callback(result);
} else } else
_conn->Execute(_query); _conn->Execute(_query);
} }

2
src/server/shared/Database/MySQL/DatabaseOperationMySQL.h

@ -49,4 +49,4 @@ private:
typedef Util::SynchronisedQueue<DatabaseOperationMySQL*> DatabaseWorkQueueMySQL; typedef Util::SynchronisedQueue<DatabaseOperationMySQL*> DatabaseWorkQueueMySQL;
#endif #endif

2
src/server/shared/Database/MySQL/DatabaseWorkerMySQL.h

@ -16,4 +16,4 @@ private:
DatabaseConnectionMySQL* _conn; DatabaseConnectionMySQL* _conn;
}; };
#endif #endif

16
src/server/shared/Database/MySQL/DatabaseWorkerPoolMySQL.h

@ -69,14 +69,14 @@ public:
} }
// Queries // Queries
bool Execute(const char* query) bool Execute(const char* query)
{ {
DatabaseConnectionMySQL* conn = GetSyncConnection(); DatabaseConnectionMySQL* conn = GetSyncConnection();
bool result = conn->Execute(query); bool result = conn->Execute(query);
conn->Unlock(); conn->Unlock();
return result; return result;
} }
ResultSetMySQL* Query(const char* query) ResultSetMySQL* Query(const char* query)
{ {
DatabaseConnectionMySQL* conn = GetSyncConnection(); DatabaseConnectionMySQL* conn = GetSyncConnection();
ResultSetMySQL* result = conn->Query(query); ResultSetMySQL* result = conn->Query(query);
@ -92,7 +92,7 @@ public:
conn->Unlock(); conn->Unlock();
return result; return result;
} }
ResultSetMySQL* Query(PreparedStatement* stmt) ResultSetMySQL* Query(PreparedStatement* stmt)
{ {
DatabaseConnectionMySQL* conn = GetSyncConnection(); DatabaseConnectionMySQL* conn = GetSyncConnection();
ResultSetMySQL* result = conn->Query(stmt); ResultSetMySQL* result = conn->Query(stmt);
@ -113,21 +113,21 @@ public:
_asyncQueue->Enqueue(op); _asyncQueue->Enqueue(op);
return true; return true;
} }
bool QueryAsync(DatabaseCallback callback, const char* query) bool QueryAsync(DatabaseCallback callback, const char* query)
{ {
DatabaseQueryOperationMySQL* op = new DatabaseQueryOperationMySQL(query, callback); DatabaseQueryOperationMySQL* op = new DatabaseQueryOperationMySQL(query, callback);
_asyncQueue->Enqueue(op); _asyncQueue->Enqueue(op);
return true; return true;
} }
bool QueryAsync(DatabaseCallback callback, PreparedStatement* stmt) bool QueryAsync(DatabaseCallback callback, PreparedStatement* stmt)
{ {
DatabasePreparedStatementOperationMySQL* op = new DatabasePreparedStatementOperationMySQL(stmt, callback); DatabasePreparedStatementOperationMySQL* op = new DatabasePreparedStatementOperationMySQL(stmt, callback);
_asyncQueue->Enqueue(op); _asyncQueue->Enqueue(op);
return true; return true;
} }
// Prepared Statements // Prepared Statements
PreparedStatement* GetPreparedStatement(uint32_t stmtid) PreparedStatement* GetPreparedStatement(uint32_t stmtid)
{ {
return NULL;//new PreparedStatement(stmtid); return NULL;//new PreparedStatement(stmtid);
} }
@ -155,4 +155,4 @@ private:
DatabaseWorkQueueMySQL* _asyncQueue; DatabaseWorkQueueMySQL* _asyncQueue;
}; };
#endif #endif

2
src/server/shared/Database/MySQL/FieldMySQL.h

@ -7,4 +7,4 @@ class FieldMySQL : public Field
{ {
}; };
#endif #endif

2
src/server/shared/Database/MySQL/PreparedStatementMySQL.cpp

@ -31,4 +31,4 @@ void PreparedStatementMySQL::ClearParameters()
delete[] (char*) _bind[i].buffer; delete[] (char*) _bind[i].buffer;
_bind[i].buffer = NULL; _bind[i].buffer = NULL;
} }
} }

2
src/server/shared/Database/MySQL/PreparedStatementMySQL.h

@ -21,4 +21,4 @@ private:
uint8_t _paramCount; uint8_t _paramCount;
}; };
#endif #endif

2
src/server/shared/Database/MySQL/QueryResultMySQL.h

@ -36,4 +36,4 @@ private:
MYSQL_FIELD* _fields; MYSQL_FIELD* _fields;
}; };
#endif #endif

2
src/server/shared/Database/PreparedStatement.h

@ -9,4 +9,4 @@ public:
PreparedStatement(uint32_t index) {}; PreparedStatement(uint32_t index) {};
}; };
#endif #endif

2
src/server/shared/Database/QueryResult.h

@ -18,4 +18,4 @@ public:
typedef boost::shared_ptr<ResultSet> QueryResult; typedef boost::shared_ptr<ResultSet> QueryResult;
#endif #endif

118
src/server/shared/Logging/Log.cpp

@ -10,109 +10,109 @@ Log::Log(): logfile(NULL)
Log::~Log() Log::~Log()
{ {
if (logfile) if (logfile)
logfile.close(); logfile.close();
} }
void Log::Error(LogType type, const char * str, ...) void Log::Error(LogType type, const char * str, ...)
{ {
va_list ap; va_list ap;
va_start(ap, str); va_start(ap, str);
char text[MAX_MSG_LEN]; char text[MAX_MSG_LEN];
vsnprintf(text, MAX_MSG_LEN, str, ap); vsnprintf(text, MAX_MSG_LEN, str, ap);
Write(LOG_LEVEL_ERROR, type, std::string(text)); Write(LOG_LEVEL_ERROR, type, std::string(text));
va_end(ap); va_end(ap);
} }
void Log::Warn(LogType type, const char * str, ...) void Log::Warn(LogType type, const char * str, ...)
{ {
va_list ap; va_list ap;
va_start(ap, str); va_start(ap, str);
char text[MAX_MSG_LEN]; char text[MAX_MSG_LEN];
vsnprintf(text, MAX_MSG_LEN, str, ap); vsnprintf(text, MAX_MSG_LEN, str, ap);
Write(LOG_LEVEL_WARN, type, std::string(text)); Write(LOG_LEVEL_WARN, type, std::string(text));
va_end(ap); va_end(ap);
} }
void Log::Info(LogType type, const char * str, ...) void Log::Info(LogType type, const char * str, ...)
{ {
va_list ap; va_list ap;
va_start(ap, str); va_start(ap, str);
char text[MAX_MSG_LEN]; char text[MAX_MSG_LEN];
vsnprintf(text, MAX_MSG_LEN, str, ap); vsnprintf(text, MAX_MSG_LEN, str, ap);
Write(LOG_LEVEL_INFO, type, std::string(text)); Write(LOG_LEVEL_INFO, type, std::string(text));
va_end(ap); va_end(ap);
} }
void Log::Debug(LogType type, const char * str, ...) void Log::Debug(LogType type, const char * str, ...)
{ {
va_list ap; va_list ap;
va_start(ap, str); va_start(ap, str);
char text[MAX_MSG_LEN]; char text[MAX_MSG_LEN];
vsnprintf(text, MAX_MSG_LEN, str, ap); vsnprintf(text, MAX_MSG_LEN, str, ap);
Write(LOG_LEVEL_DEBUG, type, std::string(text)); Write(LOG_LEVEL_DEBUG, type, std::string(text));
va_end(ap); va_end(ap);
} }
void Log::OpenLogFile(std::string path) void Log::OpenLogFile(std::string path)
{ {
if (!logfile) { if (!logfile) {
logFileLoc = path + "/server-" + Util::Date("%Y%m%d-%H%M%S") + ".log"; logFileLoc = path + "/server-" + Util::Date("%Y%m%d-%H%M%S") + ".log";
logfile.open(logFileLoc.c_str()); logfile.open(logFileLoc.c_str());
} }
} }
void Log::Write(LogLevel level, LogType type, std::string msg) void Log::Write(LogLevel level, LogType type, std::string msg)
{ {
boost::lock_guard<boost::mutex> lock(_mutex); boost::lock_guard<boost::mutex> lock(_mutex);
switch(level) switch(level)
{ {
case LOG_LEVEL_ERROR: case LOG_LEVEL_ERROR:
if (sConfig.Get<uint32_t>("LogConsoleLevel") >= level) if (sConfig.Get<uint32_t>("LogConsoleLevel") >= level)
std::cout << "[ERROR] " << msg << std::endl; std::cout << "[ERROR] " << msg << std::endl;
if (sConfig.Get<uint32_t>("LogFileLevel") >= level) if (sConfig.Get<uint32_t>("LogFileLevel") >= level)
AppendFile("[ERROR] " + msg); AppendFile("[ERROR] " + msg);
break; break;
case LOG_LEVEL_WARN: case LOG_LEVEL_WARN:
if (sConfig.Get<uint32_t>("LogConsoleLevel") >= level) if (sConfig.Get<uint32_t>("LogConsoleLevel") >= level)
std::cout << "[WARN] " << msg << std::endl; std::cout << "[WARN] " << msg << std::endl;
if (sConfig.Get<uint32_t>("LogFileLevel") >= level) if (sConfig.Get<uint32_t>("LogFileLevel") >= level)
AppendFile("[WARN] " + msg); AppendFile("[WARN] " + msg);
break; break;
case LOG_LEVEL_INFO: case LOG_LEVEL_INFO:
if (sConfig.Get<uint32_t>("LogConsoleLevel") >= level) if (sConfig.Get<uint32_t>("LogConsoleLevel") >= level)
std::cout << "[INFO] " << msg << std::endl; std::cout << "[INFO] " << msg << std::endl;
if (sConfig.Get<uint32_t>("LogFileLevel") >= level) if (sConfig.Get<uint32_t>("LogFileLevel") >= level)
AppendFile("[INFO] " + msg); AppendFile("[INFO] " + msg);
break; break;
case LOG_LEVEL_DEBUG: case LOG_LEVEL_DEBUG:
if (sConfig.Get<uint32_t>("LogConsoleLevel") >= level) { if (sConfig.Get<uint32_t>("LogConsoleLevel") >= level) {
uint32_t debugmask = sConfig.Get<uint32_t>("LogConsoleDebugMask"); uint32_t debugmask = sConfig.Get<uint32_t>("LogConsoleDebugMask");
if (debugmask & uint32_t(pow(2, type))) if (debugmask & uint32_t(pow(2, type)))
std::cout << "[DEBUG] " << msg << std::endl; std::cout << "[DEBUG] " << msg << std::endl;
} }
if (sConfig.Get<uint32_t>("LogFileLevel") >= level) { if (sConfig.Get<uint32_t>("LogFileLevel") >= level) {
uint32_t debugmask = sConfig.Get<uint32_t>("LogFileDebugMask"); uint32_t debugmask = sConfig.Get<uint32_t>("LogFileDebugMask");
if (debugmask & uint32_t(pow(2, type))) if (debugmask & uint32_t(pow(2, type)))
AppendFile("[DEBUG] " + msg); AppendFile("[DEBUG] " + msg);
} }
break; break;
} }
} }
void Log::AppendFile(std::string msg) void Log::AppendFile(std::string msg)
{ {
if (!logfile) if (!logfile)
return; return;
logfile << msg << std::endl; logfile << msg << std::endl;
} }

46
src/server/shared/Logging/Log.h

@ -14,40 +14,40 @@
enum LogType enum LogType
{ {
LOG_GENERAL = 0, LOG_GENERAL = 0,
LOG_SERVER = 1, LOG_SERVER = 1,
LOG_DATABASE = 2 LOG_DATABASE = 2
}; };
enum LogLevel enum LogLevel
{ {
LOG_LEVEL_NONE = 0, LOG_LEVEL_NONE = 0,
LOG_LEVEL_ERROR = 1, LOG_LEVEL_ERROR = 1,
LOG_LEVEL_WARN = 2, LOG_LEVEL_WARN = 2,
LOG_LEVEL_INFO = 3, LOG_LEVEL_INFO = 3,
LOG_LEVEL_DEBUG = 4 LOG_LEVEL_DEBUG = 4
}; };
class Log class Log
{ {
public: public:
Log(); Log();
~Log(); ~Log();
void Error(LogType type, const char * str, ...) ATTR_PRINTF(3, 4); void Error(LogType type, const char * str, ...) ATTR_PRINTF(3, 4);
void Warn(LogType type, const char * str, ...) ATTR_PRINTF(3, 4); void Warn(LogType type, const char * str, ...) ATTR_PRINTF(3, 4);
void Info(LogType type, const char * str, ...) ATTR_PRINTF(3, 4); void Info(LogType type, const char * str, ...) ATTR_PRINTF(3, 4);
void Debug(LogType type, const char * str, ...) ATTR_PRINTF(3, 4); void Debug(LogType type, const char * str, ...) ATTR_PRINTF(3, 4);
void OpenLogFile(std::string filename); void OpenLogFile(std::string filename);
std::string logFileLoc; std::string logFileLoc;
private: private:
void Write(LogLevel level, LogType type, std::string msg); void Write(LogLevel level, LogType type, std::string msg);
void AppendFile(std::string); void AppendFile(std::string);
std::string logfileloc; std::string logfileloc;
std::ofstream logfile; std::ofstream logfile;
boost::mutex _mutex; boost::mutex _mutex;
}; };

2
src/server/shared/Util.cpp

@ -14,4 +14,4 @@ std::string Util::Date(const char* format, bool utc)
ss << now; ss << now;
return ss.str(); return ss.str();
} }

2
src/server/shared/Util.h

@ -10,7 +10,7 @@
namespace Util namespace Util
{ {
std::string Date(const char* format, bool utc = false); std::string Date(const char* format, bool utc = false);
template <typename T> template <typename T>
class SynchronisedQueue class SynchronisedQueue

Loading…
Cancel
Save