summaryrefslogtreecommitdiffstats
path: root/src/modules
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2009-08-31 21:21:09 +0200
committerMatthias Schiffer <matthias@gamezock.de>2009-08-31 21:21:09 +0200
commit7890312d0a850ffc5be20d078d7e8f2d148dca3e (patch)
treea466ac9d3d0a8ecde06fa5c03b154480361cfdf5 /src/modules
parent053843f893dd5c96a88e285cf2a5b35419f7dfca (diff)
downloadmad-7890312d0a850ffc5be20d078d7e8f2d148dca3e.tar
mad-7890312d0a850ffc5be20d078d7e8f2d148dca3e.zip
LogManager überarbeitet
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/AuthProviderFile/AuthProviderFile.cpp8
-rw-r--r--src/modules/FileLogger/FileLogger.h13
-rw-r--r--src/modules/FileLogger/Module.cpp23
-rw-r--r--src/modules/FileLogger/Module.h2
-rw-r--r--src/modules/UserConfigBackendHome/UserConfigBackendHome.cpp2
-rw-r--r--src/modules/UserConfigBackendKrb5/UserConfigBackendKrb5.cpp22
-rw-r--r--src/modules/UserDBBackendMysql/UserDBBackendMysql.cpp4
7 files changed, 44 insertions, 30 deletions
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 <fstream>
#include <Core/Logger.h>
-#include <Core/RemoteLogger.h>
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<FileLogger> logger(new FileLogger(entry[0][1]));
+ lastLogger.reset(new FileLogger(entry[0][1]));
- loggers.insert(logger);
- application->getLogManager()->registerLogger(boost::static_pointer_cast<Core::Logger>(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<boost::shared_ptr<FileLogger> > loggers;
+ boost::shared_ptr<FileLogger> 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<char*>(KADM5_ADMIN_SERVICE), &params, 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<char*>(KADM5_ADMIN_SERVICE), &params, 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<char*>(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;
}