From 7890312d0a850ffc5be20d078d7e8f2d148dca3e Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Mon, 31 Aug 2009 21:21:09 +0200 Subject: =?UTF-8?q?LogManager=20=C3=BCberarbeitet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ChallengeResponseAuthenticator.cpp | 2 +- .../Authenticators/PasswordAuthenticator.cpp | 2 +- src/Client/InformationManager.cpp | 4 +- src/Common/ModuleManager.cpp | 8 +- .../RequestHandlers/DisconnectRequestHandler.cpp | 2 +- .../RequestHandlers/SimpleRequestHandler.cpp | 2 +- .../RequestHandlers/SimpleRequestHandlerGroup.cpp | 2 +- src/Common/RequestManager.cpp | 8 +- src/Common/UserCache.cpp | 12 +- src/Common/UserManager.cpp | 28 ++--- src/Core/Application.cpp | 16 +-- src/Core/Application.h | 22 ++-- src/Core/ConfigManager.cpp | 2 +- src/Core/LogManager.cpp | 122 +++++++++++---------- src/Core/LogManager.h | 55 +++------- src/Core/Logger.h | 55 ++++++++-- src/Core/LoggerBase.h | 81 -------------- src/Core/RemoteLogger.h | 45 -------- src/Daemon/Backends/NetworkLogger.h | 4 +- src/Daemon/Requests/LogRequest.cpp | 1 + src/Daemon/Requests/LogRequest.h | 11 +- src/Net/Connection.cpp | 6 +- src/Server/ConnectionManager.cpp | 4 +- .../ConnectionRequestHandlerGroup.cpp | 6 +- .../RequestHandlers/DaemonRequestHandlerGroup.cpp | 2 +- src/mad-server.conf | 7 +- src/mad.conf | 5 +- src/mad.cpp | 2 +- src/madc.cpp | 2 +- src/modules/AuthProviderFile/AuthProviderFile.cpp | 8 +- src/modules/FileLogger/FileLogger.h | 13 +-- src/modules/FileLogger/Module.cpp | 23 +++- src/modules/FileLogger/Module.h | 2 + .../UserConfigBackendHome.cpp | 2 +- .../UserConfigBackendKrb5.cpp | 22 ++-- .../UserDBBackendMysql/UserDBBackendMysql.cpp | 4 +- 36 files changed, 253 insertions(+), 339 deletions(-) delete mode 100644 src/Core/LoggerBase.h delete mode 100644 src/Core/RemoteLogger.h diff --git a/src/Client/Authenticators/ChallengeResponseAuthenticator.cpp b/src/Client/Authenticators/ChallengeResponseAuthenticator.cpp index 375a708..33e5ccd 100644 --- a/src/Client/Authenticators/ChallengeResponseAuthenticator.cpp +++ b/src/Client/Authenticators/ChallengeResponseAuthenticator.cpp @@ -115,7 +115,7 @@ void ChallengeResponseAuthenticator::authenticate(Common::Application *applicati throw Core::Exception(Core::Exception::NOT_AVAILABLE); } - application->logf(Core::LoggerBase::LOG_VERBOSE, "Authenticating with method 'Challenge-Response' using hash '%s'...", hash.c_str()); + application->logf(Core::Logger::LOG_VERBOSE, "Authenticating with method 'Challenge-Response' using hash '%s'...", hash.c_str()); boost::shared_ptr request(new ChallengeResponseAuthRequest(application, username, password, hash)); diff --git a/src/Client/Authenticators/PasswordAuthenticator.cpp b/src/Client/Authenticators/PasswordAuthenticator.cpp index 77abb24..8887d96 100644 --- a/src/Client/Authenticators/PasswordAuthenticator.cpp +++ b/src/Client/Authenticators/PasswordAuthenticator.cpp @@ -93,7 +93,7 @@ void PasswordAuthenticator::authenticate(Common::Application *application, Commo throw Core::Exception(Core::Exception::NOT_AVAILABLE); } - application->logf(Core::LoggerBase::LOG_VERBOSE, "Authenticating with method 'Password' using hash '%s'...", hash.c_str()); + application->logf(Core::Logger::LOG_VERBOSE, "Authenticating with method 'Password' using hash '%s'...", hash.c_str()); boost::shared_ptr request(new PasswordAuthRequest(application, username, password, hash)); diff --git a/src/Client/InformationManager.cpp b/src/Client/InformationManager.cpp index 6ac2647..bcdb4a9 100644 --- a/src/Client/InformationManager.cpp +++ b/src/Client/InformationManager.cpp @@ -40,7 +40,7 @@ void InformationManager::DaemonStateUpdateRequestHandler::handleRequest(boost::s if(host != informationManager->daemons.end()) host->second.setState(static_cast(packet->get("state"))); else - getApplication()->log(Core::LoggerBase::LOG_WARNING, "Received a state update for an unknown host."); + getApplication()->log(Core::Logger::LOG_WARNING, "Received a state update for an unknown host."); } ret->setType("OK"); @@ -73,7 +73,7 @@ void InformationManager::daemonListRequestFinished(boost::shared_ptr lock(mutex); if(!packet || error) { - application->logf(Core::LoggerBase::LOG_CRITICAL, "Host list request failed: %s", error.what()); + application->logf(Core::Logger::LOG_CRITICAL, "Host list request failed: %s", error.what()); } else { const Common::XmlPacket::List *list = packet->getList("hosts"); diff --git a/src/Common/ModuleManager.cpp b/src/Common/ModuleManager.cpp index 057af1f..78a6459 100644 --- a/src/Common/ModuleManager.cpp +++ b/src/Common/ModuleManager.cpp @@ -64,7 +64,7 @@ bool ModuleManager::handleConfigEntry(const Core::ConfigEntry &entry, bool handl if(entry[0].getKey().matches("LoadModule") && entry[1].empty()) { if(!loadModule(entry[0][0].c_str())) - application->logf(Core::LoggerBase::LOG_ERROR, "Can't load module '%s'.", entry[0][0].c_str()); + application->logf(Core::Logger::LOG_ERROR, "Can't load module '%s'.", entry[0][0].c_str()); return true; } @@ -96,7 +96,7 @@ bool ModuleManager::loadModule(const std::string &name) { #ifdef WIN32 application->logf(Core::LoggerBase::LOG_VERBOSE, "loadModule: Can't open module: Error %u", GetLastError()); #else - application->log(Core::LoggerBase::LOG_VERBOSE, std::string("loadModule: Can't open module: ") + std::string(dlerror())); + application->log(Core::Logger::LOG_VERBOSE, std::string("loadModule: Can't open module: ") + std::string(dlerror())); #endif return false; } @@ -111,14 +111,14 @@ bool ModuleManager::loadModule(const std::string &name) { #endif if(!loader) { - application->log(Core::LoggerBase::LOG_VERBOSE, "loadModule: Can't open module: Invalid module"); + application->log(Core::Logger::LOG_VERBOSE, "loadModule: Can't open module: Invalid module"); return false; } Module *mod = loader(application); if(!mod) { - application->log(Core::LoggerBase::LOG_VERBOSE, "loadModule: Can't open module: Internal module error"); + application->log(Core::Logger::LOG_VERBOSE, "loadModule: Can't open module: Internal module error"); return false; } } diff --git a/src/Common/RequestHandlers/DisconnectRequestHandler.cpp b/src/Common/RequestHandlers/DisconnectRequestHandler.cpp index a1ecd5a..d6b3449 100644 --- a/src/Common/RequestHandlers/DisconnectRequestHandler.cpp +++ b/src/Common/RequestHandlers/DisconnectRequestHandler.cpp @@ -26,7 +26,7 @@ namespace RequestHandlers { void DisconnectRequestHandler::handlePacket(boost::shared_ptr packet) { if(packet->getType() != "Disconnect") { - getApplication()->log(Core::LoggerBase::LOG_ERROR, "Received an unexpected packet."); + getApplication()->log(Core::Logger::LOG_ERROR, "Received an unexpected packet."); XmlPacket ret; ret.setType("Error"); diff --git a/src/Common/RequestHandlers/SimpleRequestHandler.cpp b/src/Common/RequestHandlers/SimpleRequestHandler.cpp index 789db9e..33dfd5a 100644 --- a/src/Common/RequestHandlers/SimpleRequestHandler.cpp +++ b/src/Common/RequestHandlers/SimpleRequestHandler.cpp @@ -27,7 +27,7 @@ namespace RequestHandlers { void SimpleRequestHandler::handlePacket(boost::shared_ptr packet) { if(packet->getType() != type) { - getApplication()->log(Core::LoggerBase::LOG_ERROR, "Received an unexpected packet."); + getApplication()->log(Core::Logger::LOG_ERROR, "Received an unexpected packet."); XmlPacket ret; ret.setType("Error"); diff --git a/src/Common/RequestHandlers/SimpleRequestHandlerGroup.cpp b/src/Common/RequestHandlers/SimpleRequestHandlerGroup.cpp index 261950d..4d6a0e4 100644 --- a/src/Common/RequestHandlers/SimpleRequestHandlerGroup.cpp +++ b/src/Common/RequestHandlers/SimpleRequestHandlerGroup.cpp @@ -28,7 +28,7 @@ namespace RequestHandlers { void SimpleRequestHandlerGroup::GroupRequestHandler::handlePacket(boost::shared_ptr packet) { if(packet->getType() != type) { - getApplication()->log(Core::LoggerBase::LOG_ERROR, "Received an unexpected packet."); + getApplication()->log(Core::Logger::LOG_ERROR, "Received an unexpected packet."); XmlPacket ret; ret.setType("Error"); diff --git a/src/Common/RequestManager.cpp b/src/Common/RequestManager.cpp index c30ddc2..66c06b4 100644 --- a/src/Common/RequestManager.cpp +++ b/src/Common/RequestManager.cpp @@ -99,7 +99,7 @@ void RequestManager::receiveHandler(Connection *connection, boost::shared_ptrlog(Core::LoggerBase::LOG_ERROR, "Received a packet from an unregistered connection."); + application->log(Core::Logger::LOG_ERROR, "Received a packet from an unregistered connection."); return; } @@ -126,7 +126,7 @@ void RequestManager::receiveHandler(Connection *connection, boost::shared_ptrlogf(Core::LoggerBase::LOG_ERROR, "Received an unexpected packet with type '%s'.", packet->getType().c_str()); + application->logf(Core::Logger::LOG_ERROR, "Received an unexpected packet with type '%s'.", packet->getType().c_str()); XmlPacket ret; ret.setType("Error"); @@ -139,14 +139,14 @@ bool RequestManager::sendRequest(Connection *connection, boost::shared_ptr lock(mutex); if(!requestMap.isConnectionRegistered(connection)) { - application->log(Core::LoggerBase::LOG_CRITICAL, "Trying to send a request over an unregistered connecion."); + application->log(Core::Logger::LOG_CRITICAL, "Trying to send a request over an unregistered connecion."); return false; } boost::uint16_t requestId = _getUnusedRequestId(connection); if(request->isFinished || !requestMap.addRequest(connection, requestId, request)) { - application->log(Core::LoggerBase::LOG_CRITICAL, "Trying resend a request."); + application->log(Core::Logger::LOG_CRITICAL, "Trying resend a request."); return false; } request->connectSignalFinished(boost::bind(&RequestManager::handleRequestFinished, this, connection, requestId)); diff --git a/src/Common/UserCache.cpp b/src/Common/UserCache.cpp index 1367041..e2bb575 100644 --- a/src/Common/UserCache.cpp +++ b/src/Common/UserCache.cpp @@ -42,9 +42,9 @@ boost::shared_ptr > UserCache::getUserLi } else { if(users) - application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_DEBUG, "Using cached user list"); + application->log(Core::Logger::LOG_USER, Core::Logger::LOG_DEBUG, "Using cached user list"); else - application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_DEBUG, "Error cached"); + application->log(Core::Logger::LOG_USER, Core::Logger::LOG_DEBUG, "Error cached"); } } catch(Core::Exception e) { @@ -133,9 +133,9 @@ boost::shared_ptr > UserCache::getGroup } else { if(groups) - application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_DEBUG, "Using cached group list"); + application->log(Core::Logger::LOG_USER, Core::Logger::LOG_DEBUG, "Using cached group list"); else - application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_DEBUG, "Error cached"); + application->log(Core::Logger::LOG_USER, Core::Logger::LOG_DEBUG, "Error cached"); } } catch(Core::Exception e) { @@ -223,9 +223,9 @@ boost::shared_ptr > UserCache: } else { if(userGroups) - application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_DEBUG, "Using cached user-group table"); + application->log(Core::Logger::LOG_USER, Core::Logger::LOG_DEBUG, "Using cached user-group table"); else - application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_DEBUG, "Error cached"); + application->log(Core::Logger::LOG_USER, Core::Logger::LOG_DEBUG, "Error cached"); } } catch(Core::Exception e) { diff --git a/src/Common/UserManager.cpp b/src/Common/UserManager.cpp index d184044..f112894 100644 --- a/src/Common/UserManager.cpp +++ b/src/Common/UserManager.cpp @@ -43,7 +43,7 @@ bool UserManager::handleConfigEntry(const Core::ConfigEntry &entry, bool /*handl char *endptr; unsigned long val = std::strtoul(entry[1][0].c_str(), &endptr, 10); if(entry[1][0].empty() || *endptr) { - application->logf(Core::LoggerBase::LOG_WARNING, "UserBackendHome: Invalid configuration: MinUid '%s'", entry[1][0].c_str()); + application->logf(Core::Logger::LOG_WARNING, "UserBackendHome: Invalid configuration: MinUid '%s'", entry[1][0].c_str()); } else { minUid = val; @@ -55,7 +55,7 @@ bool UserManager::handleConfigEntry(const Core::ConfigEntry &entry, bool /*handl char *endptr; unsigned long val = std::strtoul(entry[1][0].c_str(), &endptr, 10); if(entry[1][0].empty() || *endptr) { - application->logf(Core::LoggerBase::LOG_WARNING, "UserBackendHome: Invalid configuration: MaxUid '%s'", entry[1][0].c_str()); + application->logf(Core::Logger::LOG_WARNING, "UserBackendHome: Invalid configuration: MaxUid '%s'", entry[1][0].c_str()); } else { maxUid = val; @@ -67,7 +67,7 @@ bool UserManager::handleConfigEntry(const Core::ConfigEntry &entry, bool /*handl char *endptr; unsigned long val = std::strtoul(entry[1][0].c_str(), &endptr, 10); if(entry[1][0].empty() || *endptr) { - application->logf(Core::LoggerBase::LOG_WARNING, "UserBackendHome: Invalid configuration: MinGid '%s'", entry[1][0].c_str()); + application->logf(Core::Logger::LOG_WARNING, "UserBackendHome: Invalid configuration: MinGid '%s'", entry[1][0].c_str()); } else { minGid = val; @@ -79,7 +79,7 @@ bool UserManager::handleConfigEntry(const Core::ConfigEntry &entry, bool /*handl char *endptr; unsigned long val = std::strtoul(entry[1][0].c_str(), &endptr, 10); if(entry[1][0].empty() || *endptr) { - application->logf(Core::LoggerBase::LOG_WARNING, "UserBackendHome: Invalid configuration: MaxGid '%s'", entry[1][0].c_str()); + application->logf(Core::Logger::LOG_WARNING, "UserBackendHome: Invalid configuration: MaxGid '%s'", entry[1][0].c_str()); } else { maxGid = val; @@ -234,7 +234,7 @@ void UserManager::addUser(const UserInfo &userInfo) throw(Core::Exception) { (*configBackend)->addUser(userInfo); } catch(Core::Exception e) { - application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_WARNING, e.what()); + application->log(Core::Logger::LOG_USER, Core::Logger::LOG_WARNING, e.what()); } } } @@ -258,7 +258,7 @@ void UserManager::updateUser(unsigned long uid, const UserInfo &userInfo) throw( (*configBackend)->updateUser(*oldUserInfo, userInfo); } catch(Core::Exception e) { - application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_WARNING, e.what()); + application->log(Core::Logger::LOG_USER, Core::Logger::LOG_WARNING, e.what()); } } } @@ -280,7 +280,7 @@ void UserManager::deleteUser(unsigned long uid) throw(Core::Exception) { (*configBackend)->deleteUser(*userInfo); } catch(Core::Exception e) { - application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_WARNING, e.what()); + application->log(Core::Logger::LOG_USER, Core::Logger::LOG_WARNING, e.what()); } } } @@ -317,7 +317,7 @@ void UserManager::addGroup(const GroupInfo &groupInfo) throw(Core::Exception) { (*configBackend)->addGroup(groupInfo); } catch(Core::Exception e) { - application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_WARNING, e.what()); + application->log(Core::Logger::LOG_USER, Core::Logger::LOG_WARNING, e.what()); } } } @@ -341,7 +341,7 @@ void UserManager::updateGroup(unsigned long gid, const GroupInfo &groupInfo) thr (*configBackend)->updateGroup(*oldGroupInfo, groupInfo); } catch(Core::Exception e) { - application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_WARNING, e.what()); + application->log(Core::Logger::LOG_USER, Core::Logger::LOG_WARNING, e.what()); } } } @@ -363,7 +363,7 @@ void UserManager::deleteGroup(unsigned long gid) throw(Core::Exception) { (*configBackend)->deleteGroup(*groupInfo); } catch(Core::Exception e) { - application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_WARNING, e.what()); + application->log(Core::Logger::LOG_USER, Core::Logger::LOG_WARNING, e.what()); } } } @@ -388,7 +388,7 @@ void UserManager::addUserToGroup(unsigned long uid, unsigned long gid) throw(Cor (*configBackend)->addUserToGroup(*userInfo, *groupInfo); } catch(Core::Exception e) { - application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_WARNING, e.what()); + application->log(Core::Logger::LOG_USER, Core::Logger::LOG_WARNING, e.what()); } } } @@ -413,7 +413,7 @@ void UserManager::deleteUserFromGroup(unsigned long uid, unsigned long gid) thro (*configBackend)->deleteUserFromGroup(*userInfo, *groupInfo); } catch(Core::Exception e) { - application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_WARNING, e.what()); + application->log(Core::Logger::LOG_USER, Core::Logger::LOG_WARNING, e.what()); } } } @@ -439,7 +439,7 @@ void UserManager::setPassword(unsigned long uid, const std::string &password) th exception = e; if(e.getErrorCode() != Core::Exception::NOT_IMPLEMENTED) - application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_WARNING, e.what()); + application->log(Core::Logger::LOG_USER, Core::Logger::LOG_WARNING, e.what()); } for(std::set >::iterator configBackend = configBackends.begin(); configBackend != configBackends.end(); ++configBackend) { @@ -449,7 +449,7 @@ void UserManager::setPassword(unsigned long uid, const std::string &password) th } catch(Core::Exception e) { if(e.getErrorCode() != Core::Exception::NOT_IMPLEMENTED) - application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_WARNING, e.what()); + application->log(Core::Logger::LOG_USER, Core::Logger::LOG_WARNING, e.what()); } } diff --git a/src/Core/Application.cpp b/src/Core/Application.cpp index 7083be5..d75cbaf 100644 --- a/src/Core/Application.cpp +++ b/src/Core/Application.cpp @@ -40,7 +40,7 @@ Application::~Application() { } -void Application::logfv(LoggerBase::MessageCategory category, LoggerBase::MessageLevel level, const char *format, va_list ap) { +void Application::logfv(Logger::MessageCategory category, Logger::MessageLevel level, const char *format, va_list ap) { int size = 100; char *buf = (char*)std::malloc(size); @@ -68,35 +68,35 @@ void Application::logfv(LoggerBase::MessageCategory category, LoggerBase::Messag } -void Application::log(LoggerBase::MessageCategory category, LoggerBase::MessageLevel level, const std::string &message) { +void Application::log(Logger::MessageCategory category, Logger::MessageLevel level, const std::string &message) { logManager->log(category, level, boost::posix_time::microsec_clock::universal_time(), message); } -void Application::logf(LoggerBase::MessageCategory category, LoggerBase::MessageLevel level, const char *format, ...) { +void Application::logf(Logger::MessageCategory category, Logger::MessageLevel level, const char *format, ...) { va_list ap; va_start(ap, format); logfv(category, level, format, ap); va_end(ap); } -void Application::logf(LoggerBase::MessageCategory category, const char *format, ...) { +void Application::logf(Logger::MessageCategory category, const char *format, ...) { va_list ap; va_start(ap, format); - logfv(category, LoggerBase::LOG_DEFAULT, format, ap); + logfv(category, Logger::LOG_DEFAULT, format, ap); va_end(ap); } -void Application::logf(LoggerBase::MessageLevel level, const char *format, ...) { +void Application::logf(Logger::MessageLevel level, const char *format, ...) { va_list ap; va_start(ap, format); - logfv(LoggerBase::LOG_GENERAL, level, format, ap); + logfv(Logger::LOG_GENERAL, level, format, ap); va_end(ap); } void Application::logf(const char *format, ...) { va_list ap; va_start(ap, format); - logfv(LoggerBase::LOG_GENERAL, LoggerBase::LOG_DEFAULT, format, ap); + logfv(Logger::LOG_GENERAL, Logger::LOG_DEFAULT, format, ap); va_end(ap); } diff --git a/src/Core/Application.h b/src/Core/Application.h index 3951b5c..18521d5 100644 --- a/src/Core/Application.h +++ b/src/Core/Application.h @@ -22,7 +22,7 @@ #include "export.h" -#include "LoggerBase.h" +#include "Logger.h" #include #include @@ -45,7 +45,7 @@ class MAD_CORE_EXPORT Application : private boost::noncopyable { LogManager *logManager; ThreadManager *threadManager; - void logfv(LoggerBase::MessageCategory category, LoggerBase::MessageLevel level, const char *format, va_list ap); + void logfv(Logger::MessageCategory category, Logger::MessageLevel level, const char *format, va_list ap); protected: Application(); @@ -69,24 +69,24 @@ class MAD_CORE_EXPORT Application : private boost::noncopyable { } - void log(LoggerBase::MessageCategory category, LoggerBase::MessageLevel level, const std::string &message); + void log(Logger::MessageCategory category, Logger::MessageLevel level, const std::string &message); - void log(LoggerBase::MessageCategory category, const std::string &message) { - log(category, LoggerBase::LOG_DEFAULT, message); + void log(Logger::MessageCategory category, const std::string &message) { + log(category, Logger::LOG_DEFAULT, message); } - void log(LoggerBase::MessageLevel level, const std::string &message) { - log(LoggerBase::LOG_GENERAL, level, message); + void log(Logger::MessageLevel level, const std::string &message) { + log(Logger::LOG_GENERAL, level, message); } void log(const std::string &message) { - log(LoggerBase::LOG_GENERAL, LoggerBase::LOG_DEFAULT, message); + log(Logger::LOG_GENERAL, Logger::LOG_DEFAULT, message); } - void logf(LoggerBase::MessageCategory category, LoggerBase::MessageLevel level, const char *format, ...); - void logf(LoggerBase::MessageCategory category, const char *format, ...); - void logf(LoggerBase::MessageLevel level, const char *format, ...); + void logf(Logger::MessageCategory category, Logger::MessageLevel level, const char *format, ...); + void logf(Logger::MessageCategory category, const char *format, ...); + void logf(Logger::MessageLevel level, const char *format, ...); void logf(const char *format, ...); }; diff --git a/src/Core/ConfigManager.cpp b/src/Core/ConfigManager.cpp index 83e92db..bd20cc5 100644 --- a/src/Core/ConfigManager.cpp +++ b/src/Core/ConfigManager.cpp @@ -46,7 +46,7 @@ void ConfigManager::handleConfigEntry(const ConfigEntry &entry) { } if(!handled) - application->logf(LoggerBase::LOG_WARNING, "Invalid config option '%s'.", entry[entry.getSize()-1].getKey().c_str()); + application->logf(Logger::LOG_WARNING, "Invalid config option '%s'.", entry[entry.getSize()-1].getKey().c_str()); } bool ConfigManager::loadFile(const std::string &filename) { diff --git a/src/Core/LogManager.cpp b/src/Core/LogManager.cpp index b255c04..8fe7428 100644 --- a/src/Core/LogManager.cpp +++ b/src/Core/LogManager.cpp @@ -27,24 +27,41 @@ namespace Mad { namespace Core { -void LogManager::ConsoleLogger::logMessage(MessageCategory /*category*/, MessageLevel level, boost::posix_time::ptime /*timestamp*/, const std::string &message) { - if(level != LOG_CRITICAL) {// Critical messages are printed to cerr directly, so don't print them a second time - cerrLock.lock(); - std::cerr << message << std::endl; - cerrLock.unlock(); +void LogManager::ConsoleLogger::logMessage(MessageCategory category, MessageLevel level, boost::posix_time::ptime timestamp, const std::string &message, const std::string &source) { + if(!(level == LOG_CRITICAL && source.empty())) {// Critical messages are printed to cerr directly, so don't print them a second time + boost::lock_guard lock(cerrMutex); + logMessageDirect(category, level, timestamp, message, source); } } -void LogManager::ConsoleLogger::logMessage(MessageCategory /*category*/, MessageLevel /*level*/, boost::posix_time::ptime /*timestamp*/, const std::string &message, const std::string &messageSource) { - cerrLock.lock(); - std::cerr << message << " from " << messageSource << std::endl; - cerrLock.unlock(); +void LogManager::ConsoleLogger::logMessageDirect(MessageCategory /*category*/, MessageLevel /*level*/, boost::posix_time::ptime /*timestamp*/, const std::string &message, const std::string &source) { + if(source.empty()) + std::cerr << message << std::endl; + else + std::cerr << message << " from " << source << std::endl; } -void LogManager::ConsoleLogger::logMessageDirect(MessageCategory /*category*/, MessageLevel /*level*/, boost::posix_time::ptime /*timestamp*/, const std::string &message) { - cerrLock.lock(); - std::cerr << message << std::endl; - cerrLock.unlock(); + +LogManager::MessageLevel LogManager::parseLevel(const std::string &str) throw (Exception) { + if(str.empty()) + return Logger::LOG_DEFAULT; + + std::string lowerStr = boost::algorithm::to_lower_copy(str); + + if(lowerStr == "debug") + return Logger::LOG_DEBUG; + else if(lowerStr == "verbose") + return Logger::LOG_VERBOSE; + else if(lowerStr == "default") + return Logger::LOG_DEFAULT; + else if(lowerStr == "warning") + return Logger::LOG_WARNING; + else if(lowerStr == "error") + return Logger::LOG_ERROR; + else if(lowerStr == "critical") + return Logger::LOG_CRITICAL; + else + throw Exception(Exception::INVALID_INPUT); } @@ -58,19 +75,30 @@ LogManager::~LogManager() { bool LogManager::handleConfigEntry(const ConfigEntry &entry, bool handled) { - if(handled) - return false; - - if(entry[0].getKey().matches("Logger")) { + if(entry[0].getKey().matches("Log")) { if(entry[0][0].matches("Console")) { if(entry[1].empty()) { - registerLogger(boost::static_pointer_cast(consoleLogger)); + registerLogger(consoleLogger); return true; } + else if(entry[1].getKey().matches("Level")) { + if(entry[2].empty()) { + try { + consoleLogger->setLevel(parseLevel(entry[1][0])); + } + catch(Core::Exception e) { + application->logf(Logger::LOG_WARNING, "Unknown log level '%s'.", entry[1][0].c_str()); + } + + return true; + } + } } else if(entry[1].empty()) { - application->logf(Logger::LOG_WARNING, "Unknown logger '%s'.", entry[0][0].c_str()); - return true; + if(!handled) { + application->logf(Logger::LOG_WARNING, "Unknown logger '%s'.", entry[0][0].c_str()); + return true; + } } } @@ -79,38 +107,26 @@ bool LogManager::handleConfigEntry(const ConfigEntry &entry, bool handled) { void LogManager::configFinished() { if(loggers.empty()) - registerLogger(boost::static_pointer_cast(consoleLogger)); + registerLogger(consoleLogger); - // TODO Debug - consoleLogger->Logger::setLevel(LoggerBase::LOG_VERBOSE); - queueLock.lock(); + boost::lock_guard lock(queueMutex); configured = true; - queueLock.unlock(); queueCond.notify_one(); } -void LogManager::log(MessageCategory category, MessageLevel level, boost::posix_time::ptime timestamp, const std::string &message) { - if(level == LoggerBase::LOG_CRITICAL) - consoleLogger->logMessageDirect(category, level, timestamp, message); +void LogManager::log(MessageCategory category, MessageLevel level, boost::posix_time::ptime timestamp, const std::string &message, const std::string &source) { + if(level == Logger::LOG_CRITICAL && source.empty()) + consoleLogger->logMessageDirect(category, level, timestamp, message, source); - queueLock.lock(); - Message m = {category, level, timestamp, message}; + boost::lock_guard lock(queueMutex); + Message m = {category, level, timestamp, message, source}; messageQueue.push(m); - queueLock.unlock(); queueCond.notify_one(); } -void LogManager::log(MessageCategory category, MessageLevel level, boost::posix_time::ptime timestamp, const std::string &message, const std::string &source) { - queueLock.lock(); - RemoteMessage m = {category, level, timestamp, message, source}; - remoteMessageQueue.push(m); - queueLock.unlock(); - queueCond.notify_one(); -} - void LogManager::loggerThread() { - boost::unique_lock lock(queueLock); + boost::unique_lock lock(queueMutex); running = true; @@ -123,27 +139,13 @@ void LogManager::loggerThread() { messageQueue.pop(); lock.unlock(); - loggerLock.lock(); - for(std::set >::iterator logger = loggers.begin(); logger != loggers.end(); ++logger) { - if((*logger)->getLevel() >= message.level && (*logger)->isCategorySet(message.category)) - (*logger)->logMessage(message.category, message.level, message.timestamp, message.message); - } - loggerLock.unlock(); - - lock.lock(); - } - - while(!remoteMessageQueue.empty()) { - RemoteMessage message = remoteMessageQueue.front(); - remoteMessageQueue.pop(); - lock.unlock(); - - remoteLoggerLock.lock(); - for(std::set >::iterator logger = remoteLoggers.begin(); logger != remoteLoggers.end(); ++logger) { - if((*logger)->getLevel() >= message.level && (*logger)->isCategorySet(message.category)) - (*logger)->logMessage(message.category, message.level, message.timestamp, message.message, message.source); + { + boost::lock_guard loggerLock(loggerMutex); + for(std::set >::iterator logger = loggers.begin(); logger != loggers.end(); ++logger) { + if((*logger)->getLevel() >= message.level && (*logger)->isCategorySet(message.category)) + (*logger)->logMessage(message.category, message.level, message.timestamp, message.message, message.source); + } } - remoteLoggerLock.unlock(); lock.lock(); } diff --git a/src/Core/LogManager.h b/src/Core/LogManager.h index 3aab49e..c569238 100644 --- a/src/Core/LogManager.h +++ b/src/Core/LogManager.h @@ -23,8 +23,8 @@ #include "export.h" #include "Configurable.h" +#include "Exception.h" #include "Logger.h" -#include "RemoteLogger.h" #include #include @@ -43,38 +43,30 @@ class MAD_CORE_EXPORT LogManager : public Configurable { friend class Application; friend class ThreadManager; - typedef LoggerBase::MessageCategory MessageCategory; - typedef LoggerBase::MessageLevel MessageLevel; + typedef Logger::MessageCategory MessageCategory; + typedef Logger::MessageLevel MessageLevel; struct Message { MessageCategory category; MessageLevel level; boost::posix_time::ptime timestamp; std::string message; - }; - - struct RemoteMessage { - MessageCategory category; - MessageLevel level; - boost::posix_time::ptime timestamp; - std::string message; std::string source; }; - class ConsoleLogger : public Logger, public RemoteLogger { + class ConsoleLogger : public Logger { private: // For long messages, writing to cerr is not atomic // -> lock cerr to prevent messages mixing up - boost::mutex cerrLock; + boost::mutex cerrMutex; protected: - virtual void logMessage(MessageCategory category, MessageLevel level, boost::posix_time::ptime timestamp, const std::string &message); - virtual void logMessage(MessageCategory category, MessageLevel, boost::posix_time::ptime timestamp, const std::string &message, const std::string &messageSource); + virtual void logMessage(MessageCategory category, MessageLevel, boost::posix_time::ptime timestamp, const std::string &message, const std::string &source); public: ConsoleLogger() {} - void logMessageDirect(MessageCategory category, MessageLevel level, boost::posix_time::ptime timestamp, const std::string &message); + void logMessageDirect(MessageCategory category, MessageLevel level, boost::posix_time::ptime timestamp, const std::string &message, const std::string &source); }; @@ -83,23 +75,19 @@ class MAD_CORE_EXPORT LogManager : public Configurable { boost::shared_ptr consoleLogger; std::set > loggers; - std::set > remoteLoggers; bool configured, running; - boost::mutex queueLock; + boost::mutex queueMutex; boost::condition_variable queueCond; - boost::mutex loggerLock; - boost::mutex remoteLoggerLock; + boost::mutex loggerMutex; std::queue messageQueue; - std::queue remoteMessageQueue; void loggerThread(); void stopLoggerThread() { - queueLock.lock(); + boost::lock_guard lock(queueMutex); running = false; - queueLock.unlock(); queueCond.notify_one(); } @@ -111,31 +99,18 @@ class MAD_CORE_EXPORT LogManager : public Configurable { virtual void configFinished(); public: - void log(MessageCategory category, MessageLevel level, boost::posix_time::ptime timestamp, const std::string &message); - void log(MessageCategory category, MessageLevel level, boost::posix_time::ptime timestamp, const std::string &message, const std::string &source); + static MessageLevel parseLevel(const std::string &str) throw (Exception); + + void log(MessageCategory category, MessageLevel level, boost::posix_time::ptime timestamp, const std::string &message, const std::string &source = std::string()); void registerLogger(boost::shared_ptr logger) { - loggerLock.lock(); + boost::lock_guard lock(loggerMutex); loggers.insert(logger); - loggerLock.unlock(); } void unregisterLogger(boost::shared_ptr logger) { - loggerLock.lock(); + boost::lock_guard lock(loggerMutex); loggers.erase(logger); - loggerLock.unlock(); - } - - void registerLogger(boost::shared_ptr logger) { - remoteLoggerLock.lock(); - remoteLoggers.insert(logger); - remoteLoggerLock.unlock(); - } - - void unregisterLogger(boost::shared_ptr logger) { - remoteLoggerLock.lock(); - remoteLoggers.erase(logger); - remoteLoggerLock.unlock(); } }; diff --git a/src/Core/Logger.h b/src/Core/Logger.h index 53ec665..24582bc 100644 --- a/src/Core/Logger.h +++ b/src/Core/Logger.h @@ -20,10 +20,7 @@ #ifndef MAD_CORE_LOGGER_H_ #define MAD_CORE_LOGGER_H_ -#include "export.h" - -#include "LoggerBase.h" - +#include #include #include @@ -32,12 +29,56 @@ namespace Core { class LogManager; -class Logger : public LoggerBase { - protected: +class Logger { + public: friend class LogManager; - virtual void logMessage(MessageCategory category, MessageLevel level, boost::posix_time::ptime timestamp, const std::string &message) = 0; + enum MessageLevel { + LOG_CRITICAL, LOG_ERROR, LOG_WARNING, LOG_DEFAULT, LOG_VERBOSE, LOG_DEBUG + }; + + enum MessageCategory { + LOG_SYSTEM, LOG_NETWORK, LOG_DAEMON, LOG_USER, LOG_DISK, LOG_PROGRAM, LOG_GENERAL + }; + + private: + std::bitset<16> categories; + MessageLevel level; + + protected: + Logger() : level(LOG_DEFAULT) {setAllCategories();} + virtual ~Logger() {} + + virtual void logMessage(MessageCategory category, MessageLevel level, boost::posix_time::ptime timestamp, const std::string &message, const std::string &source) = 0; + + public: + void setCategory(MessageCategory newCategory) { + categories.set(newCategory); + } + + void unsetCategory(MessageCategory oldCategory) { + categories.reset(oldCategory); + } + + void setAllCategories() { + categories.set(); + } + + void unsetAllCategories() { + categories.reset(); + } + + bool isCategorySet(MessageCategory category) const { + return categories.test(category); + } + + MessageLevel getLevel() const { + return level; + } + void setLevel(MessageLevel newLevel) { + level = newLevel; + } }; } diff --git a/src/Core/LoggerBase.h b/src/Core/LoggerBase.h deleted file mode 100644 index a2df969..0000000 --- a/src/Core/LoggerBase.h +++ /dev/null @@ -1,81 +0,0 @@ -/* - * LoggerBase.h - * - * Copyright (C) 2008 Johannes Thorn - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License along - * with this program. If not, see . - */ - -#ifndef MAD_CORE_LOGGERBASE_H_ -#define MAD_CORE_LOGGERBASE_H_ - -#include "export.h" - -#include -#include - -namespace Mad { -namespace Core { - -class LoggerBase { - public: - enum MessageLevel { - LOG_CRITICAL, LOG_ERROR, LOG_WARNING, LOG_DEFAULT, LOG_VERBOSE, LOG_DEBUG - }; - - enum MessageCategory { - LOG_SYSTEM, LOG_NETWORK, LOG_DAEMON, LOG_USER, LOG_DISK, LOG_PROGRAM, LOG_GENERAL - }; - - protected: - std::bitset<16> categories; - MessageLevel level; - - LoggerBase() : level(LOG_DEFAULT) {setAllCategories();} - virtual ~LoggerBase() {} - - public: - void setCategory(MessageCategory newCategory) { - categories.set(newCategory); - } - - void unsetCategory(MessageCategory oldCategory) { - categories.reset(oldCategory); - } - - void setAllCategories() { - categories.set(); - } - - void unsetAllCategories() { - categories.reset(); - } - - bool isCategorySet(MessageCategory category) const { - return categories.test(category); - } - - MessageLevel getLevel() const { - return level; - } - - void setLevel(MessageLevel newLevel) { - level = newLevel; - } -}; - -} -} - -#endif /* MAD_CORE_LOGGERBASE_H_ */ diff --git a/src/Core/RemoteLogger.h b/src/Core/RemoteLogger.h deleted file mode 100644 index 8dedb7a..0000000 --- a/src/Core/RemoteLogger.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * LogRequestLogger.h - * - * Copyright (C) 2008 Johannes Thorn - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License along - * with this program. If not, see . - */ - -#ifndef MAD_CORE_REMOTELOGGER_H_ -#define MAD_CORE_REMOTELOGGER_H_ - -#include "export.h" - -#include "LoggerBase.h" - -#include -#include - -namespace Mad { -namespace Core { - -class LogManager; - -class RemoteLogger : public LoggerBase { - protected: - friend class LogManager; - - virtual void logMessage(MessageCategory category, MessageLevel level, boost::posix_time::ptime messageTimestamp, const std::string &message, const std::string &messageSource) = 0; -}; - -} -} - -#endif /* MAD_CORE_REMOTELOGGER_H_ */ diff --git a/src/Daemon/Backends/NetworkLogger.h b/src/Daemon/Backends/NetworkLogger.h index 9965468..8c93036 100644 --- a/src/Daemon/Backends/NetworkLogger.h +++ b/src/Daemon/Backends/NetworkLogger.h @@ -35,8 +35,8 @@ class NetworkLogger : public Core::Logger { Common::Connection *connection; protected: - virtual void logMessage(Core::Logger::MessageCategory category, Core::Logger::MessageLevel level, boost::posix_time::ptime messageTimestamp, const std::string &message) { - boost::shared_ptr request(new Requests::LogRequest(application, category, level, messageTimestamp, message)); + virtual void logMessage(Core::Logger::MessageCategory category, Core::Logger::MessageLevel level, boost::posix_time::ptime messageTimestamp, const std::string &message, const std::string &source) { + boost::shared_ptr request(new Requests::LogRequest(application, category, level, messageTimestamp, message, source)); application->getRequestManager()->sendRequest(connection, request); } diff --git a/src/Daemon/Requests/LogRequest.cpp b/src/Daemon/Requests/LogRequest.cpp index 2d12fc8..9266420 100644 --- a/src/Daemon/Requests/LogRequest.cpp +++ b/src/Daemon/Requests/LogRequest.cpp @@ -34,6 +34,7 @@ void LogRequest::sendRequest() { packet.set("level", level); packet.set("timestamp", boost::posix_time::to_iso_string(messageTimestamp)); packet.set("message", message); + packet.set("source", source); sendPacket(packet); } diff --git a/src/Daemon/Requests/LogRequest.h b/src/Daemon/Requests/LogRequest.h index 49d5c6f..2d8c91f 100644 --- a/src/Daemon/Requests/LogRequest.h +++ b/src/Daemon/Requests/LogRequest.h @@ -31,17 +31,18 @@ namespace Requests { class MAD_DAEMON_EXPORT LogRequest : public Common::Request { private: - Core::LoggerBase::MessageCategory category; - Core::LoggerBase::MessageLevel level; + Core::Logger::MessageCategory category; + Core::Logger::MessageLevel level; boost::posix_time::ptime messageTimestamp; - std::string message; + std::string message, source; protected: virtual void sendRequest(); public: - LogRequest(Common::Application *application, Core::LoggerBase::MessageCategory category0, Core::LoggerBase::MessageLevel level0, boost::posix_time::ptime messageTimestamp0, const std::string &message0) - : Common::Request(application), category(category0), level(level0), messageTimestamp(messageTimestamp0), message(message0) {} + LogRequest(Common::Application *application, Core::Logger::MessageCategory category0, Core::Logger::MessageLevel level0, boost::posix_time::ptime messageTimestamp0, const std::string &message0, + const std::string &source0) + : Common::Request(application), category(category0), level(level0), messageTimestamp(messageTimestamp0), message(message0), source(source0) {} }; } diff --git a/src/Net/Connection.cpp b/src/Net/Connection.cpp index 94b5493..80a7163 100644 --- a/src/Net/Connection.cpp +++ b/src/Net/Connection.cpp @@ -64,7 +64,7 @@ void Connection::handleShutdown(const boost::system::error_code& error) { boost::lock_guard lock(connectionLock); if(error) { - application->logf(Core::LoggerBase::LOG_VERBOSE, "Shutdown error: %s", error.message().c_str()); + application->logf(Core::Logger::LOG_VERBOSE, "Shutdown error: %s", error.message().c_str()); } _setState(DISCONNECTED); @@ -115,7 +115,7 @@ void Connection::handleRead(const boost::system::error_code& error, std::size_t if(error == boost::system::errc::operation_canceled) return; - application->logf(Core::LoggerBase::LOG_DEFAULT, "Read error: %s", error.message().c_str()); + application->logf(Core::Logger::LOG_DEFAULT, "Read error: %s", error.message().c_str()); // TODO Error doDisconnect(); @@ -176,7 +176,7 @@ void Connection::rawReceive(std::size_t length, const boost::function1logf(Core::LoggerBase::LOG_VERBOSE, "Write error: %s", error.message().c_str()); + application->logf(Core::Logger::LOG_VERBOSE, "Write error: %s", error.message().c_str()); { boost::unique_lock lock(connectionLock); diff --git a/src/Server/ConnectionManager.cpp b/src/Server/ConnectionManager.cpp index 4867464..ad5a7d3 100644 --- a/src/Server/ConnectionManager.cpp +++ b/src/Server/ConnectionManager.cpp @@ -134,7 +134,7 @@ bool ConnectionManager::handleConfigEntry(const Core::ConfigEntry &entry, bool h listenerAddresses.push_back(parseAddress(entry[0][0])); } catch(Core::Exception &e) { - application->logf(Core::LoggerBase::LOG_WARNING, "ConnectionManager: Invalid listen address '%s'", entry[0][0].c_str()); + application->logf(Core::Logger::LOG_WARNING, "ConnectionManager: Invalid listen address '%s'", entry[0][0].c_str()); } return true; @@ -290,7 +290,7 @@ void ConnectionManager::identifyDaemonConnection(Common::Connection *con, const if(hostInfo->getState() != Common::HostInfo::INACTIVE) { try { getDaemonConnection(name)->disconnect(); - application->log(Core::LoggerBase::LOG_WARNING, "Disconnecting old connection."); + application->log(Core::Logger::LOG_WARNING, "Disconnecting old connection."); } catch(Core::Exception&) {} } diff --git a/src/Server/RequestHandlers/ConnectionRequestHandlerGroup.cpp b/src/Server/RequestHandlers/ConnectionRequestHandlerGroup.cpp index 2171deb..af48d65 100644 --- a/src/Server/RequestHandlers/ConnectionRequestHandlerGroup.cpp +++ b/src/Server/RequestHandlers/ConnectionRequestHandlerGroup.cpp @@ -112,14 +112,14 @@ void ConnectionRequestHandlerGroup::handleLogRequest(boost::shared_ptrgetLogManager()->log( - static_cast(packet->get("category")), - static_cast(packet->get("level")), + static_cast(packet->get("category")), + static_cast(packet->get("level")), timestamp, packet->get("message"), application->getConnectionManager()->getDaemonName(connection)); } catch(Core::Exception &e) { - application->logf(Core::LoggerBase::LOG_ERROR, "Can't determine daemon name: %s", e.what()); + application->logf(Core::Logger::LOG_ERROR, "Can't determine daemon name: %s", e.what()); } ret->setType("OK"); diff --git a/src/Server/RequestHandlers/DaemonRequestHandlerGroup.cpp b/src/Server/RequestHandlers/DaemonRequestHandlerGroup.cpp index 35e167e..499e7b6 100644 --- a/src/Server/RequestHandlers/DaemonRequestHandlerGroup.cpp +++ b/src/Server/RequestHandlers/DaemonRequestHandlerGroup.cpp @@ -32,7 +32,7 @@ namespace RequestHandlers { void DaemonRequestHandlerGroup::DaemonRequestHandler::handlePacket(boost::shared_ptr packet) { if(packet->getType() != type) { - getApplication()->log(Core::LoggerBase::LOG_ERROR, "Received an unexpected packet."); + getApplication()->log(Core::Logger::LOG_ERROR, "Received an unexpected packet."); Common::XmlPacket ret; ret.setType("Error"); diff --git a/src/mad-server.conf b/src/mad-server.conf index 7b176d4..9fa8f29 100644 --- a/src/mad-server.conf +++ b/src/mad-server.conf @@ -11,8 +11,11 @@ LoadModule "UserDBBackendMysql" LoadModule "UserConfigBackendHome" LoadModule "UserConfigBackendKrb5" -Logger Console -Logger File "mad-server.log" +Log Console { + Level "verbose" +} + +Log File "mad-server.log" Listen 127.0.0.1 diff --git a/src/mad.conf b/src/mad.conf index 1d5ca61..5066efe 100644 --- a/src/mad.conf +++ b/src/mad.conf @@ -1,3 +1,6 @@ -LoadModule "FileLogger" LoadModule "SystemBackendPosix" LoadModule "SystemBackendProc" + +Log Console { + Level "debug" +} diff --git a/src/mad.cpp b/src/mad.cpp index 81061ca..fbf9a87 100644 --- a/src/mad.cpp +++ b/src/mad.cpp @@ -71,7 +71,7 @@ int main() { application.getRequestManager()->unregisterConnection(connection); } catch(Core::Exception &e) { - application.logf(Core::LoggerBase::LOG_CRITICAL, "Connection error: %s", e.what()); + application.logf(Core::Logger::LOG_CRITICAL, "Connection error: %s", e.what()); } delete connection; diff --git a/src/madc.cpp b/src/madc.cpp index 0f4639d..762aa03 100644 --- a/src/madc.cpp +++ b/src/madc.cpp @@ -125,7 +125,7 @@ int main(int argc, char *argv[]) { application.getRequestManager()->unregisterConnection(connection); } catch(Core::Exception &e) { - application.logf(Core::LoggerBase::LOG_CRITICAL, "Error: %s", e.what()); + application.logf(Core::Logger::LOG_CRITICAL, "Error: %s", e.what()); } delete connection; diff --git a/src/modules/AuthProviderFile/AuthProviderFile.cpp b/src/modules/AuthProviderFile/AuthProviderFile.cpp index f670fec..99af6b6 100644 --- a/src/modules/AuthProviderFile/AuthProviderFile.cpp +++ b/src/modules/AuthProviderFile/AuthProviderFile.cpp @@ -34,7 +34,7 @@ namespace AuthProviderFile { void AuthProviderFile::readFile(const std::string &name) { std::ifstream stream(name.c_str()); if(!stream.good()) { - application->logf(Core::LoggerBase::LOG_WARNING, "AuthProviderFile: Can't read file '%s'.", name.c_str()); + application->logf(Core::Logger::LOG_WARNING, "AuthProviderFile: Can't read file '%s'.", name.c_str()); return; } @@ -49,7 +49,7 @@ void AuthProviderFile::readFile(const std::string &name) { boost::smatch match; if(!boost::regex_match(line, match, regex)) { - application->logf(Core::LoggerBase::LOG_WARNING, "AuthProviderFile: Malformed line in file '%s'.", name.c_str()); + application->logf(Core::Logger::LOG_WARNING, "AuthProviderFile: Malformed line in file '%s'.", name.c_str()); continue; } @@ -67,7 +67,7 @@ void AuthProviderFile::readFile(const std::string &name) { unsigned char byte; if(std::sscanf(buffer, "%hhx", &byte) != 1) { - application->logf(Core::LoggerBase::LOG_WARNING, "AuthProviderFile: Malformed hash in file '%s'.", name.c_str()); + application->logf(Core::Logger::LOG_WARNING, "AuthProviderFile: Malformed hash in file '%s'.", name.c_str()); data.clear(); break; } @@ -93,7 +93,7 @@ bool AuthProviderFile::handleConfigEntry(const Core::ConfigEntry &entry, bool /* filehash = entry[1][0]; if(!Common::Hash::isHashSupported(filehash)) - application->logf(Core::LoggerBase::LOG_WARNING, "AuthProviderFile: Unsupported hash '%s'", filehash.c_str()); + application->logf(Core::Logger::LOG_WARNING, "AuthProviderFile: Unsupported hash '%s'", filehash.c_str()); } } else if(entry[1].getKey().matches("File")) { diff --git a/src/modules/FileLogger/FileLogger.h b/src/modules/FileLogger/FileLogger.h index 0ee9ad7..c202e4b 100644 --- a/src/modules/FileLogger/FileLogger.h +++ b/src/modules/FileLogger/FileLogger.h @@ -23,22 +23,21 @@ #include #include -#include namespace Mad { namespace Modules { namespace FileLogger { -class FileLogger : public Core::Logger, public Core::RemoteLogger { +class FileLogger : public Core::Logger { private: std::ofstream file; protected: - virtual void logMessage(MessageCategory /*category*/, MessageLevel /*level*/, boost::posix_time::ptime /*timestamp*/, const std::string &message) { - file << message << std::endl; - } - virtual void logMessage(MessageCategory /*category*/, MessageLevel /*level*/, boost::posix_time::ptime /*timestamp*/, const std::string &message, const std::string &messageSource) { - file << message << " from "<< messageSource << std::endl; + virtual void logMessage(MessageCategory /*category*/, MessageLevel /*level*/, boost::posix_time::ptime /*timestamp*/, const std::string &message, const std::string &source) { + if(source.empty()) + file << message << std::endl; + else + file << message << " from "<< source << std::endl; } public: diff --git a/src/modules/FileLogger/Module.cpp b/src/modules/FileLogger/Module.cpp index e715386..88d475c 100644 --- a/src/modules/FileLogger/Module.cpp +++ b/src/modules/FileLogger/Module.cpp @@ -30,21 +30,34 @@ bool Module::handleConfigEntry(const Core::ConfigEntry &entry, bool handled) { if(handled) return false; - if(entry[0].getKey().matches("Logger")) { + if(entry[0].getKey().matches("Log")) { if(entry[0][0].matches("File")) { if(entry[1].empty()) { if(!entry[0][1].empty()) { - boost::shared_ptr logger(new FileLogger(entry[0][1])); + lastLogger.reset(new FileLogger(entry[0][1])); - loggers.insert(logger); - application->getLogManager()->registerLogger(boost::static_pointer_cast(logger)); + loggers.insert(lastLogger); + application->getLogManager()->registerLogger(lastLogger); } else { - application->logf(Core::LoggerBase::LOG_WARNING, "FileLogger: no filename given."); + lastLogger.reset(); + application->logf(Core::Logger::LOG_WARNING, "FileLogger: no filename given."); } return true; } + else if(entry[1].getKey().matches("Level")) { + if(entry[2].empty()) { + try { + lastLogger->setLevel(Core::LogManager::parseLevel(entry[1][0])); + } + catch(Core::Exception e) { + application->logf(Core::Logger::LOG_WARNING, "Unknown log level '%s'.", entry[1][0].c_str()); + } + + return true; + } + } } } diff --git a/src/modules/FileLogger/Module.h b/src/modules/FileLogger/Module.h index b45dd8c..8cf54a1 100644 --- a/src/modules/FileLogger/Module.h +++ b/src/modules/FileLogger/Module.h @@ -39,6 +39,8 @@ class Module : public Common::Module, private Core::Configurable { std::set > loggers; + boost::shared_ptr lastLogger; + protected: virtual bool handleConfigEntry(const Core::ConfigEntry &entry, bool handled); diff --git a/src/modules/UserConfigBackendHome/UserConfigBackendHome.cpp b/src/modules/UserConfigBackendHome/UserConfigBackendHome.cpp index 1a2a5c4..9f724e5 100644 --- a/src/modules/UserConfigBackendHome/UserConfigBackendHome.cpp +++ b/src/modules/UserConfigBackendHome/UserConfigBackendHome.cpp @@ -50,7 +50,7 @@ bool UserConfigBackendHome::handleConfigEntry(const Core::ConfigEntry &entry, bo char *endptr; unsigned long val = std::strtoul(entry[1][0].c_str(), &endptr, 8); if(*endptr || val > 07777) { - application->logf(Core::LoggerBase::LOG_WARNING, "UserBackendHome: Invalid configuration: DirMode '%s'", entry[1][0].c_str()); + application->logf(Core::Logger::LOG_WARNING, "UserBackendHome: Invalid configuration: DirMode '%s'", entry[1][0].c_str()); } else { dirMode = val; diff --git a/src/modules/UserConfigBackendKrb5/UserConfigBackendKrb5.cpp b/src/modules/UserConfigBackendKrb5/UserConfigBackendKrb5.cpp index 35d65ae..94e3506 100644 --- a/src/modules/UserConfigBackendKrb5/UserConfigBackendKrb5.cpp +++ b/src/modules/UserConfigBackendKrb5/UserConfigBackendKrb5.cpp @@ -29,12 +29,12 @@ namespace UserConfigBackendKrb5 { void UserConfigBackendKrb5::connect() { if(principal.empty()) { - application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_ERROR, "UserConfigBackendKrb5: no principal given"); + application->log(Core::Logger::LOG_USER, Core::Logger::LOG_ERROR, "UserConfigBackendKrb5: no principal given"); return; } if(realm.empty()) { - application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_ERROR, "UserConfigBackendKrb5: no realm given and no default realm available"); + application->log(Core::Logger::LOG_USER, Core::Logger::LOG_ERROR, "UserConfigBackendKrb5: no realm given and no default realm available"); return; } @@ -64,7 +64,7 @@ void UserConfigBackendKrb5::connect() { const_cast(KADM5_ADMIN_SERVICE), ¶ms, KADM5_STRUCT_VERSION, KADM5_API_VERSION_2, 0, &handle); if(err) { - application->logf(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_ERROR, "kadm5_init_with_password: %s", krb5_get_error_message(context, err)); + application->logf(Core::Logger::LOG_USER, Core::Logger::LOG_ERROR, "kadm5_init_with_password: %s", krb5_get_error_message(context, err)); return; } } @@ -77,12 +77,12 @@ void UserConfigBackendKrb5::connect() { const_cast(KADM5_ADMIN_SERVICE), ¶ms, KADM5_STRUCT_VERSION, KADM5_API_VERSION_2, 0, &handle); if(err) { - application->logf(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_ERROR, "kadm5_init_with_skey: %s", krb5_get_error_message(context, err)); + application->logf(Core::Logger::LOG_USER, Core::Logger::LOG_ERROR, "kadm5_init_with_skey: %s", krb5_get_error_message(context, err)); return; } } - application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_VERBOSE, "Connected to kerberos admin server."); + application->log(Core::Logger::LOG_USER, Core::Logger::LOG_VERBOSE, "Connected to kerberos admin server."); return; } @@ -153,7 +153,7 @@ void UserConfigBackendKrb5::addUser(const Common::UserInfo &userInfo) throw(Core do { err = kadm5_create_principal(handle, &princ, KADM5_PRINCIPAL|KADM5_ATTRIBUTES, dummybuf); if(err == KADM5_RPC_ERROR && retryCount > 0) { - application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_VERBOSE, "Connection to kerberos admin server lost. Reconnecting..."); + application->log(Core::Logger::LOG_USER, Core::Logger::LOG_VERBOSE, "Connection to kerberos admin server lost. Reconnecting..."); connect(); --retryCount; } @@ -166,7 +166,7 @@ void UserConfigBackendKrb5::addUser(const Common::UserInfo &userInfo) throw(Core do { err = kadm5_randkey_principal(handle, princ.principal, 0, 0); if(err == KADM5_RPC_ERROR && retryCount > 0) { - application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_VERBOSE, "Connection to kerberos admin server lost. Reconnecting..."); + application->log(Core::Logger::LOG_USER, Core::Logger::LOG_VERBOSE, "Connection to kerberos admin server lost. Reconnecting..."); connect(); --retryCount; } @@ -180,7 +180,7 @@ void UserConfigBackendKrb5::addUser(const Common::UserInfo &userInfo) throw(Core do { err = kadm5_modify_principal(handle, &princ, KADM5_ATTRIBUTES); if(err == KADM5_RPC_ERROR && retryCount > 0) { - application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_VERBOSE, "Connection to kerberos admin server lost. Reconnecting..."); + application->log(Core::Logger::LOG_USER, Core::Logger::LOG_VERBOSE, "Connection to kerberos admin server lost. Reconnecting..."); connect(); --retryCount; } @@ -222,7 +222,7 @@ void UserConfigBackendKrb5::deleteUser(const Common::UserInfo &userInfo) throw(C do { err = kadm5_delete_principal(handle, princ); if(err == KADM5_RPC_ERROR && retryCount > 0) { - application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_VERBOSE, "Connection to kerberos admin server lost. Reconnecting..."); + application->log(Core::Logger::LOG_USER, Core::Logger::LOG_VERBOSE, "Connection to kerberos admin server lost. Reconnecting..."); connect(); --retryCount; } @@ -231,7 +231,7 @@ void UserConfigBackendKrb5::deleteUser(const Common::UserInfo &userInfo) throw(C krb5_free_principal(context, princ); if(err) - application->logf(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_WARNING, "kadm5_delete_principal: %s", krb5_get_error_message(context, err)); + application->logf(Core::Logger::LOG_USER, Core::Logger::LOG_WARNING, "kadm5_delete_principal: %s", krb5_get_error_message(context, err)); } void UserConfigBackendKrb5::setPassword(const Common::UserInfo &userInfo, const std::string &password) throw(Core::Exception) { @@ -252,7 +252,7 @@ void UserConfigBackendKrb5::setPassword(const Common::UserInfo &userInfo, const do { err = kadm5_chpass_principal(handle, princ, const_cast(password.c_str())); if(err == KADM5_RPC_ERROR && retryCount > 0) { - application->log(Core::LoggerBase::LOG_USER, Core::LoggerBase::LOG_VERBOSE, "Connection to kerberos admin server lost. Reconnecting..."); + application->log(Core::Logger::LOG_USER, Core::Logger::LOG_VERBOSE, "Connection to kerberos admin server lost. Reconnecting..."); connect(); --retryCount; } diff --git a/src/modules/UserDBBackendMysql/UserDBBackendMysql.cpp b/src/modules/UserDBBackendMysql/UserDBBackendMysql.cpp index bf087f2..e905541 100644 --- a/src/modules/UserDBBackendMysql/UserDBBackendMysql.cpp +++ b/src/modules/UserDBBackendMysql/UserDBBackendMysql.cpp @@ -70,7 +70,7 @@ bool UserDBBackendMysql::handleConfigEntry(const Core::ConfigEntry &entry, bool val = strtol(entry[2][0].c_str(), &endptr, 10); if(endptr != 0 || val < 0 || val > 65535) - application->log(Core::LoggerBase::LOG_WARNING, "UserDBBackendMysql: Invalid port"); + application->log(Core::Logger::LOG_WARNING, "UserDBBackendMysql: Invalid port"); else port = val; } @@ -159,7 +159,7 @@ bool UserDBBackendMysql::handleConfigEntry(const Core::ConfigEntry &entry, bool void UserDBBackendMysql::configFinished() { if(db.empty()) { - application->log(Core::LoggerBase::LOG_ERROR, "UserDBBackendMysql: No database name given"); + application->log(Core::Logger::LOG_ERROR, "UserDBBackendMysql: No database name given"); return; } -- cgit v1.2.3