From 57c65a4ba2e20a92e5e42e7f1c73166c6fb8c522 Mon Sep 17 00:00:00 2001 From: Intel Date: Fri, 26 Jul 2013 02:38:55 +0300 Subject: [PATCH] Tab2Space & Newlines --- .../poolserver/Database/ServerDatabaseEnv.cpp | 2 +- .../poolserver/Database/ServerDatabaseEnv.h | 2 +- src/server/poolserver/Main.cpp | 76 +++++------ src/server/poolserver/Server/Server.cpp | 18 +-- src/server/shared/Configuration/Config.h | 24 ++-- src/server/shared/Database/Database.h | 16 +-- src/server/shared/Database/DatabaseCallback.h | 2 +- src/server/shared/Database/DatabaseEnv.h | 2 +- src/server/shared/Database/Field.h | 2 +- .../MySQL/DatabaseConnectionMySQL.cpp | 2 +- .../Database/MySQL/DatabaseConnectionMySQL.h | 14 +-- .../shared/Database/MySQL/DatabaseEnvMySQL.h | 2 +- .../Database/MySQL/DatabaseOperationMySQL.cpp | 2 +- .../Database/MySQL/DatabaseOperationMySQL.h | 2 +- .../Database/MySQL/DatabaseWorkerMySQL.h | 2 +- .../Database/MySQL/DatabaseWorkerPoolMySQL.h | 16 +-- src/server/shared/Database/MySQL/FieldMySQL.h | 2 +- .../Database/MySQL/PreparedStatementMySQL.cpp | 2 +- .../Database/MySQL/PreparedStatementMySQL.h | 2 +- .../shared/Database/MySQL/QueryResultMySQL.h | 2 +- .../shared/Database/PreparedStatement.h | 2 +- src/server/shared/Database/QueryResult.h | 2 +- src/server/shared/Logging/Log.cpp | 118 +++++++++--------- src/server/shared/Logging/Log.h | 46 +++---- src/server/shared/Util.cpp | 2 +- src/server/shared/Util.h | 2 +- 26 files changed, 182 insertions(+), 182 deletions(-) diff --git a/src/server/poolserver/Database/ServerDatabaseEnv.cpp b/src/server/poolserver/Database/ServerDatabaseEnv.cpp index c043bdd..9cfa4b9 100644 --- a/src/server/poolserver/Database/ServerDatabaseEnv.cpp +++ b/src/server/poolserver/Database/ServerDatabaseEnv.cpp @@ -1,3 +1,3 @@ #include "ServerDatabaseEnv.h" -ServerDatabaseWorkerPoolMySQL sDatabase; \ No newline at end of file +ServerDatabaseWorkerPoolMySQL sDatabase; diff --git a/src/server/poolserver/Database/ServerDatabaseEnv.h b/src/server/poolserver/Database/ServerDatabaseEnv.h index c63d2e1..c495b88 100644 --- a/src/server/poolserver/Database/ServerDatabaseEnv.h +++ b/src/server/poolserver/Database/ServerDatabaseEnv.h @@ -9,4 +9,4 @@ class ServerDatabaseWorkerPoolMySQL : public DatabaseWorkerPoolMySQL extern ServerDatabaseWorkerPoolMySQL sDatabase; -#endif \ No newline at end of file +#endif diff --git a/src/server/poolserver/Main.cpp b/src/server/poolserver/Main.cpp index e3cd8c3..cf428ac 100644 --- a/src/server/poolserver/Main.cpp +++ b/src/server/poolserver/Main.cpp @@ -9,41 +9,41 @@ bool InitConfig(int argc, char *argv[]) { // Containers boost::program_options::options_description descGeneric("Generic Options"); - boost::program_options::options_description descServer("Server Configuration"); - boost::program_options::options_description descStratum("Stratum Configuration"); - boost::program_options::options_description descLogging("Logging Configuration"); + boost::program_options::options_description descServer("Server Configuration"); + boost::program_options::options_description descStratum("Stratum Configuration"); + boost::program_options::options_description descLogging("Logging Configuration"); boost::program_options::options_description descDatabase("Database Configuration"); #ifdef WITH_MYSQL boost::program_options::options_description descMySQL("MySQL Configuration"); #endif - boost::program_options::options_description cmdlineOptions; - boost::program_options::options_description fileOptions; + boost::program_options::options_description cmdlineOptions; + boost::program_options::options_description fileOptions; // Generic descGeneric.add_options() - ("version,v", "print version string") - ("help,h", "produce help message") - ("config,c", boost::program_options::value()->default_value("poolserver.cfg"),"name of a file of a configuration.") + ("version,v", "print version string") + ("help,h", "produce help message") + ("config,c", boost::program_options::value()->default_value("poolserver.cfg"),"name of a file of a configuration.") ; - - // Server + + // Server descServer.add_options() ("MinDiffTime", boost::program_options::value()->default_value(100), "Minimum server diff time") ; - - // Stratum + + // Stratum descStratum.add_options() ("StratumHost,sh", boost::program_options::value()->default_value("0.0.0.0"), "Stratum server host") - ("StratumPort,sp", boost::program_options::value()->default_value(3333), "Stratum server port") + ("StratumPort,sp", boost::program_options::value()->default_value(3333), "Stratum server port") ; - - // Logging - descLogging.add_options() + + // Logging + descLogging.add_options() ("LogConsoleLevel", boost::program_options::value()->default_value(LOG_LEVEL_INFO), "Console log level (0-None, 1-Error, 2-Warn, 3-Info, 4-Debug)") - ("LogConsoleDebugMask", boost::program_options::value()->default_value(0), "Console log debug mask") - ("LogFilePath", boost::program_options::value()->default_value("."), "File log path") - ("LogFileLevel", boost::program_options::value()->default_value(LOG_LEVEL_WARN), "File log level (0-None, 1-Error, 2-Warn, 3-Info, 4-Debug)") - ("LogFileDebugMask", boost::program_options::value()->default_value(0), "File log debug mask") + ("LogConsoleDebugMask", boost::program_options::value()->default_value(0), "Console log debug mask") + ("LogFilePath", boost::program_options::value()->default_value("."), "File log path") + ("LogFileLevel", boost::program_options::value()->default_value(LOG_LEVEL_WARN), "File log level (0-None, 1-Error, 2-Warn, 3-Info, 4-Debug)") + ("LogFileDebugMask", boost::program_options::value()->default_value(0), "File log debug mask") ; // Database @@ -62,39 +62,39 @@ bool InitConfig(int argc, char *argv[]) ; descDatabase.add(descMySQL); #endif - + cmdlineOptions.add(descGeneric).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); notify(sConfig.vm); - - if (sConfig.vm.count("help")) { - std::cout << cmdlineOptions << std::endl; - return false; - } + + if (sConfig.vm.count("help")) { + std::cout << cmdlineOptions << std::endl; + return false; + } std::ifstream ifs(sConfig.Get("config").c_str()); - - if (!ifs.is_open()) { + + if (!ifs.is_open()) { sLog.Error(LOG_GENERAL, "Failed opening config file: %s", sConfig.Get("config").c_str()); - return false; - } + return false; + } - store(parse_config_file(ifs, fileOptions), sConfig.vm); - notify(sConfig.vm); + store(parse_config_file(ifs, fileOptions), sConfig.vm); + notify(sConfig.vm); return true; } int main(int argc, char *argv[]) { - if (!InitConfig(argc, argv)) - return 0; - - sLog.OpenLogFile(sConfig.Get("LogFilePath")); - sLog.Info(LOG_GENERAL, "LogFile Started: %s", sLog.logFileLoc.c_str()); - + if (!InitConfig(argc, argv)) + return 0; + + sLog.OpenLogFile(sConfig.Get("LogFilePath")); + sLog.Info(LOG_GENERAL, "LogFile Started: %s", sLog.logFileLoc.c_str()); + Server* server = new Server(); int exitcode = server->Run(); delete server; diff --git a/src/server/poolserver/Server/Server.cpp b/src/server/poolserver/Server/Server.cpp index a41afef..d920f0a 100644 --- a/src/server/poolserver/Server/Server.cpp +++ b/src/server/poolserver/Server/Server.cpp @@ -19,27 +19,27 @@ Server::~Server() int Server::Run() { - sLog.Info(LOG_SERVER, "Server is starting..."); + sLog.Info(LOG_SERVER, "Server is starting..."); InitDatabase(); sDatabase.Execute("INSERT INTO `test_table` VALUES ('999', 'sync', '1.1')"); sDatabase.ExecuteAsync("INSERT INTO `test_table` VALUES ('999', 'sync', '1.1')"); - + // 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")); - + // Init loop vars uint32_t sleepDuration = 0; int exitcode = 0; running = true; // Init diff - uint32_t minDiffTime = sConfig.Get("MinDiffTime"); + uint32_t minDiffTime = sConfig.Get("MinDiffTime"); diffStart = boost::chrono::steady_clock::now(); - - sLog.Info(LOG_SERVER, "Server is running!"); + + sLog.Info(LOG_SERVER, "Server is running!"); while (running) { @@ -60,8 +60,8 @@ int Server::Run() ++serverLoops; - if (serverLoops > 50) - running = false; + if (serverLoops > 50) + running = false; //std::cout << "Diff: " << diff << ", Loop: " << serverLoops << std::endl; } diff --git a/src/server/shared/Configuration/Config.h b/src/server/shared/Configuration/Config.h index a2cbc3f..12b05b0 100644 --- a/src/server/shared/Configuration/Config.h +++ b/src/server/shared/Configuration/Config.h @@ -9,18 +9,18 @@ class Config { public: - Config(); - ~Config(); - - // Reading - template - T Get(std::string key) - { - return vm[key].as(); - } - - // Containers - boost::program_options::variables_map vm; + Config(); + ~Config(); + + // Reading + template + T Get(std::string key) + { + return vm[key].as(); + } + + // Containers + boost::program_options::variables_map vm; }; extern Config sConfig; diff --git a/src/server/shared/Database/Database.h b/src/server/shared/Database/Database.h index 8ce5ae0..1171feb 100644 --- a/src/server/shared/Database/Database.h +++ b/src/server/shared/Database/Database.h @@ -9,22 +9,22 @@ class Database { public: - // Queries - virtual bool Execute(const char* query) = 0; - virtual ResultSet* Query(const char* query) = 0; + // Queries + virtual bool Execute(const char* query) = 0; + virtual ResultSet* Query(const char* query) = 0; // Stmt virtual bool Execute(PreparedStatement* stmt) = 0; - virtual ResultSet* Query(PreparedStatement* stmt) = 0; + virtual ResultSet* Query(PreparedStatement* stmt) = 0; // Async virtual bool ExecuteAsync(const char* query) = 0; virtual bool ExecuteAsync(PreparedStatement* stmt) = 0; - virtual bool QueryAsync(DatabaseCallback callback, const char* query) = 0; - virtual bool QueryAsync(DatabaseCallback callback, PreparedStatement* stmt) = 0; + virtual bool QueryAsync(DatabaseCallback callback, const char* query) = 0; + virtual bool QueryAsync(DatabaseCallback callback, PreparedStatement* stmt) = 0; - // Prepared Statements - virtual PreparedStatement* GetPreparedStatement(uint32_t index) = 0; + // Prepared Statements + virtual PreparedStatement* GetPreparedStatement(uint32_t index) = 0; }; #endif diff --git a/src/server/shared/Database/DatabaseCallback.h b/src/server/shared/Database/DatabaseCallback.h index d687390..f5de674 100644 --- a/src/server/shared/Database/DatabaseCallback.h +++ b/src/server/shared/Database/DatabaseCallback.h @@ -7,4 +7,4 @@ typedef boost::function DatabaseCallback; -#endif \ No newline at end of file +#endif diff --git a/src/server/shared/Database/DatabaseEnv.h b/src/server/shared/Database/DatabaseEnv.h index 51230bd..6de8125 100644 --- a/src/server/shared/Database/DatabaseEnv.h +++ b/src/server/shared/Database/DatabaseEnv.h @@ -7,4 +7,4 @@ #include "MySQL/DatabaseEnvMySQL.h" #endif -#endif \ No newline at end of file +#endif diff --git a/src/server/shared/Database/Field.h b/src/server/shared/Database/Field.h index 334189b..ceeda84 100644 --- a/src/server/shared/Database/Field.h +++ b/src/server/shared/Database/Field.h @@ -8,4 +8,4 @@ public: //virtual Get(); }; -#endif \ No newline at end of file +#endif diff --git a/src/server/shared/Database/MySQL/DatabaseConnectionMySQL.cpp b/src/server/shared/Database/MySQL/DatabaseConnectionMySQL.cpp index 22d3eaf..8420239 100644 --- a/src/server/shared/Database/MySQL/DatabaseConnectionMySQL.cpp +++ b/src/server/shared/Database/MySQL/DatabaseConnectionMySQL.cpp @@ -146,4 +146,4 @@ ResultSetMySQL* DatabaseConnectionMySQL::Query(PreparedStatement* stmt) bool DatabaseConnectionMySQL::_HandleMySQLErrno(uint32_t lErrno) { return false; -} \ No newline at end of file +} diff --git a/src/server/shared/Database/MySQL/DatabaseConnectionMySQL.h b/src/server/shared/Database/MySQL/DatabaseConnectionMySQL.h index 08a744a..d5423d9 100644 --- a/src/server/shared/Database/MySQL/DatabaseConnectionMySQL.h +++ b/src/server/shared/Database/MySQL/DatabaseConnectionMySQL.h @@ -35,18 +35,18 @@ public: void Close(); // Ping! - void Ping() + void Ping() { mysql_ping(_mysql); } - - // Queries - bool Execute(const char* query); - ResultSetMySQL* Query(const char* query); + + // Queries + bool Execute(const char* query); + ResultSetMySQL* Query(const char* query); // Stmt bool Execute(PreparedStatement* stmt); - ResultSetMySQL* Query(PreparedStatement* stmt); + ResultSetMySQL* Query(PreparedStatement* stmt); // Locking bool LockIfReady() @@ -76,4 +76,4 @@ private: MySQLConnectionInfo _connectionInfo; }; -#endif \ No newline at end of file +#endif diff --git a/src/server/shared/Database/MySQL/DatabaseEnvMySQL.h b/src/server/shared/Database/MySQL/DatabaseEnvMySQL.h index 09a1fd7..8cc225e 100644 --- a/src/server/shared/Database/MySQL/DatabaseEnvMySQL.h +++ b/src/server/shared/Database/MySQL/DatabaseEnvMySQL.h @@ -3,4 +3,4 @@ #include "DatabaseWorkerPoolMySQL.h" -#endif \ No newline at end of file +#endif diff --git a/src/server/shared/Database/MySQL/DatabaseOperationMySQL.cpp b/src/server/shared/Database/MySQL/DatabaseOperationMySQL.cpp index 20069a0..f9f78d8 100644 --- a/src/server/shared/Database/MySQL/DatabaseOperationMySQL.cpp +++ b/src/server/shared/Database/MySQL/DatabaseOperationMySQL.cpp @@ -23,4 +23,4 @@ void DatabaseQueryOperationMySQL::Execute() _callback(result); } else _conn->Execute(_query); -} \ No newline at end of file +} diff --git a/src/server/shared/Database/MySQL/DatabaseOperationMySQL.h b/src/server/shared/Database/MySQL/DatabaseOperationMySQL.h index 86679a4..e0860b5 100644 --- a/src/server/shared/Database/MySQL/DatabaseOperationMySQL.h +++ b/src/server/shared/Database/MySQL/DatabaseOperationMySQL.h @@ -49,4 +49,4 @@ private: typedef Util::SynchronisedQueue DatabaseWorkQueueMySQL; -#endif \ No newline at end of file +#endif diff --git a/src/server/shared/Database/MySQL/DatabaseWorkerMySQL.h b/src/server/shared/Database/MySQL/DatabaseWorkerMySQL.h index ab90f70..45a1ff4 100644 --- a/src/server/shared/Database/MySQL/DatabaseWorkerMySQL.h +++ b/src/server/shared/Database/MySQL/DatabaseWorkerMySQL.h @@ -16,4 +16,4 @@ private: DatabaseConnectionMySQL* _conn; }; -#endif \ No newline at end of file +#endif diff --git a/src/server/shared/Database/MySQL/DatabaseWorkerPoolMySQL.h b/src/server/shared/Database/MySQL/DatabaseWorkerPoolMySQL.h index 6069c2c..5d51379 100644 --- a/src/server/shared/Database/MySQL/DatabaseWorkerPoolMySQL.h +++ b/src/server/shared/Database/MySQL/DatabaseWorkerPoolMySQL.h @@ -69,14 +69,14 @@ public: } // Queries - bool Execute(const char* query) + bool Execute(const char* query) { DatabaseConnectionMySQL* conn = GetSyncConnection(); bool result = conn->Execute(query); conn->Unlock(); return result; } - ResultSetMySQL* Query(const char* query) + ResultSetMySQL* Query(const char* query) { DatabaseConnectionMySQL* conn = GetSyncConnection(); ResultSetMySQL* result = conn->Query(query); @@ -92,7 +92,7 @@ public: conn->Unlock(); return result; } - ResultSetMySQL* Query(PreparedStatement* stmt) + ResultSetMySQL* Query(PreparedStatement* stmt) { DatabaseConnectionMySQL* conn = GetSyncConnection(); ResultSetMySQL* result = conn->Query(stmt); @@ -113,21 +113,21 @@ public: _asyncQueue->Enqueue(op); return true; } - bool QueryAsync(DatabaseCallback callback, const char* query) + bool QueryAsync(DatabaseCallback callback, const char* query) { DatabaseQueryOperationMySQL* op = new DatabaseQueryOperationMySQL(query, callback); _asyncQueue->Enqueue(op); return true; } - bool QueryAsync(DatabaseCallback callback, PreparedStatement* stmt) + bool QueryAsync(DatabaseCallback callback, PreparedStatement* stmt) { DatabasePreparedStatementOperationMySQL* op = new DatabasePreparedStatementOperationMySQL(stmt, callback); _asyncQueue->Enqueue(op); return true; } - // Prepared Statements - PreparedStatement* GetPreparedStatement(uint32_t stmtid) + // Prepared Statements + PreparedStatement* GetPreparedStatement(uint32_t stmtid) { return NULL;//new PreparedStatement(stmtid); } @@ -155,4 +155,4 @@ private: DatabaseWorkQueueMySQL* _asyncQueue; }; -#endif \ No newline at end of file +#endif diff --git a/src/server/shared/Database/MySQL/FieldMySQL.h b/src/server/shared/Database/MySQL/FieldMySQL.h index 87395f3..c53fe4a 100644 --- a/src/server/shared/Database/MySQL/FieldMySQL.h +++ b/src/server/shared/Database/MySQL/FieldMySQL.h @@ -7,4 +7,4 @@ class FieldMySQL : public Field { }; -#endif \ No newline at end of file +#endif diff --git a/src/server/shared/Database/MySQL/PreparedStatementMySQL.cpp b/src/server/shared/Database/MySQL/PreparedStatementMySQL.cpp index c98458a..efab4bb 100644 --- a/src/server/shared/Database/MySQL/PreparedStatementMySQL.cpp +++ b/src/server/shared/Database/MySQL/PreparedStatementMySQL.cpp @@ -31,4 +31,4 @@ void PreparedStatementMySQL::ClearParameters() delete[] (char*) _bind[i].buffer; _bind[i].buffer = NULL; } -} \ No newline at end of file +} diff --git a/src/server/shared/Database/MySQL/PreparedStatementMySQL.h b/src/server/shared/Database/MySQL/PreparedStatementMySQL.h index 297cdb7..c20592a 100644 --- a/src/server/shared/Database/MySQL/PreparedStatementMySQL.h +++ b/src/server/shared/Database/MySQL/PreparedStatementMySQL.h @@ -21,4 +21,4 @@ private: uint8_t _paramCount; }; -#endif \ No newline at end of file +#endif diff --git a/src/server/shared/Database/MySQL/QueryResultMySQL.h b/src/server/shared/Database/MySQL/QueryResultMySQL.h index a29f77a..d1a5d9a 100644 --- a/src/server/shared/Database/MySQL/QueryResultMySQL.h +++ b/src/server/shared/Database/MySQL/QueryResultMySQL.h @@ -36,4 +36,4 @@ private: MYSQL_FIELD* _fields; }; -#endif \ No newline at end of file +#endif diff --git a/src/server/shared/Database/PreparedStatement.h b/src/server/shared/Database/PreparedStatement.h index bc1fda6..87f8bfb 100644 --- a/src/server/shared/Database/PreparedStatement.h +++ b/src/server/shared/Database/PreparedStatement.h @@ -9,4 +9,4 @@ public: PreparedStatement(uint32_t index) {}; }; -#endif \ No newline at end of file +#endif diff --git a/src/server/shared/Database/QueryResult.h b/src/server/shared/Database/QueryResult.h index d85a23f..285cb76 100644 --- a/src/server/shared/Database/QueryResult.h +++ b/src/server/shared/Database/QueryResult.h @@ -18,4 +18,4 @@ public: typedef boost::shared_ptr QueryResult; -#endif \ No newline at end of file +#endif diff --git a/src/server/shared/Logging/Log.cpp b/src/server/shared/Logging/Log.cpp index 681fb70..6396432 100644 --- a/src/server/shared/Logging/Log.cpp +++ b/src/server/shared/Logging/Log.cpp @@ -10,109 +10,109 @@ Log::Log(): logfile(NULL) Log::~Log() { - if (logfile) - logfile.close(); + if (logfile) + logfile.close(); } void Log::Error(LogType type, const char * str, ...) { - va_list ap; - va_start(ap, str); + va_list ap; + va_start(ap, str); - char text[MAX_MSG_LEN]; + char text[MAX_MSG_LEN]; vsnprintf(text, MAX_MSG_LEN, str, ap); Write(LOG_LEVEL_ERROR, type, std::string(text)); - va_end(ap); + va_end(ap); } void Log::Warn(LogType type, const char * str, ...) { - va_list ap; - va_start(ap, str); + va_list ap; + va_start(ap, str); - char text[MAX_MSG_LEN]; + char text[MAX_MSG_LEN]; vsnprintf(text, MAX_MSG_LEN, str, ap); Write(LOG_LEVEL_WARN, type, std::string(text)); - va_end(ap); + va_end(ap); } void Log::Info(LogType type, const char * str, ...) { - va_list ap; - va_start(ap, str); + va_list ap; + va_start(ap, str); - char text[MAX_MSG_LEN]; + char text[MAX_MSG_LEN]; vsnprintf(text, MAX_MSG_LEN, str, ap); Write(LOG_LEVEL_INFO, type, std::string(text)); - va_end(ap); + va_end(ap); } void Log::Debug(LogType type, const char * str, ...) { - va_list ap; - va_start(ap, str); + va_list ap; + va_start(ap, str); - char text[MAX_MSG_LEN]; + char text[MAX_MSG_LEN]; vsnprintf(text, MAX_MSG_LEN, str, ap); Write(LOG_LEVEL_DEBUG, type, std::string(text)); - va_end(ap); + va_end(ap); } void Log::OpenLogFile(std::string path) { - if (!logfile) { - logFileLoc = path + "/server-" + Util::Date("%Y%m%d-%H%M%S") + ".log"; - logfile.open(logFileLoc.c_str()); - } + if (!logfile) { + logFileLoc = path + "/server-" + Util::Date("%Y%m%d-%H%M%S") + ".log"; + logfile.open(logFileLoc.c_str()); + } } void Log::Write(LogLevel level, LogType type, std::string msg) { boost::lock_guard lock(_mutex); - switch(level) - { - case LOG_LEVEL_ERROR: - if (sConfig.Get("LogConsoleLevel") >= level) - std::cout << "[ERROR] " << msg << std::endl; - if (sConfig.Get("LogFileLevel") >= level) - AppendFile("[ERROR] " + msg); - break; - case LOG_LEVEL_WARN: - if (sConfig.Get("LogConsoleLevel") >= level) - std::cout << "[WARN] " << msg << std::endl; - if (sConfig.Get("LogFileLevel") >= level) - AppendFile("[WARN] " + msg); - break; - case LOG_LEVEL_INFO: - if (sConfig.Get("LogConsoleLevel") >= level) - std::cout << "[INFO] " << msg << std::endl; - if (sConfig.Get("LogFileLevel") >= level) - AppendFile("[INFO] " + msg); - break; - case LOG_LEVEL_DEBUG: - if (sConfig.Get("LogConsoleLevel") >= level) { - uint32_t debugmask = sConfig.Get("LogConsoleDebugMask"); - if (debugmask & uint32_t(pow(2, type))) - std::cout << "[DEBUG] " << msg << std::endl; - } - if (sConfig.Get("LogFileLevel") >= level) { - uint32_t debugmask = sConfig.Get("LogFileDebugMask"); - if (debugmask & uint32_t(pow(2, type))) - AppendFile("[DEBUG] " + msg); - } - break; - } + switch(level) + { + case LOG_LEVEL_ERROR: + if (sConfig.Get("LogConsoleLevel") >= level) + std::cout << "[ERROR] " << msg << std::endl; + if (sConfig.Get("LogFileLevel") >= level) + AppendFile("[ERROR] " + msg); + break; + case LOG_LEVEL_WARN: + if (sConfig.Get("LogConsoleLevel") >= level) + std::cout << "[WARN] " << msg << std::endl; + if (sConfig.Get("LogFileLevel") >= level) + AppendFile("[WARN] " + msg); + break; + case LOG_LEVEL_INFO: + if (sConfig.Get("LogConsoleLevel") >= level) + std::cout << "[INFO] " << msg << std::endl; + if (sConfig.Get("LogFileLevel") >= level) + AppendFile("[INFO] " + msg); + break; + case LOG_LEVEL_DEBUG: + if (sConfig.Get("LogConsoleLevel") >= level) { + uint32_t debugmask = sConfig.Get("LogConsoleDebugMask"); + if (debugmask & uint32_t(pow(2, type))) + std::cout << "[DEBUG] " << msg << std::endl; + } + if (sConfig.Get("LogFileLevel") >= level) { + uint32_t debugmask = sConfig.Get("LogFileDebugMask"); + if (debugmask & uint32_t(pow(2, type))) + AppendFile("[DEBUG] " + msg); + } + break; + } } void Log::AppendFile(std::string msg) { - if (!logfile) - return; - - logfile << msg << std::endl; + if (!logfile) + return; + + logfile << msg << std::endl; } diff --git a/src/server/shared/Logging/Log.h b/src/server/shared/Logging/Log.h index 4fa6e87..48e30c7 100644 --- a/src/server/shared/Logging/Log.h +++ b/src/server/shared/Logging/Log.h @@ -14,40 +14,40 @@ enum LogType { - LOG_GENERAL = 0, - LOG_SERVER = 1, + LOG_GENERAL = 0, + LOG_SERVER = 1, LOG_DATABASE = 2 }; enum LogLevel { - LOG_LEVEL_NONE = 0, - LOG_LEVEL_ERROR = 1, - LOG_LEVEL_WARN = 2, - LOG_LEVEL_INFO = 3, - LOG_LEVEL_DEBUG = 4 + LOG_LEVEL_NONE = 0, + LOG_LEVEL_ERROR = 1, + LOG_LEVEL_WARN = 2, + LOG_LEVEL_INFO = 3, + LOG_LEVEL_DEBUG = 4 }; class Log { public: - Log(); - ~Log(); - - void Error(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 Debug(LogType type, const char * str, ...) ATTR_PRINTF(3, 4); - - void OpenLogFile(std::string filename); - std::string logFileLoc; - + Log(); + ~Log(); + + void Error(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 Debug(LogType type, const char * str, ...) ATTR_PRINTF(3, 4); + + void OpenLogFile(std::string filename); + std::string logFileLoc; + private: - void Write(LogLevel level, LogType type, std::string msg); - void AppendFile(std::string); - - std::string logfileloc; - std::ofstream logfile; + void Write(LogLevel level, LogType type, std::string msg); + void AppendFile(std::string); + + std::string logfileloc; + std::ofstream logfile; boost::mutex _mutex; }; diff --git a/src/server/shared/Util.cpp b/src/server/shared/Util.cpp index 31c3e9d..bf70584 100644 --- a/src/server/shared/Util.cpp +++ b/src/server/shared/Util.cpp @@ -14,4 +14,4 @@ std::string Util::Date(const char* format, bool utc) ss << now; return ss.str(); -} \ No newline at end of file +} diff --git a/src/server/shared/Util.h b/src/server/shared/Util.h index 38b9db6..71b92b6 100644 --- a/src/server/shared/Util.h +++ b/src/server/shared/Util.h @@ -10,7 +10,7 @@ namespace Util { - std::string Date(const char* format, bool utc = false); + std::string Date(const char* format, bool utc = false); template class SynchronisedQueue