From 2e487cdbbc4da36295227c219a37724a60257218 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Fri, 25 Jan 2013 17:32:12 +0100 Subject: [PATCH 1/9] Feature #1658: Enable syslog for oned.log - LOG_SYSTEM in oned.conf - SysLog class --- SConstruct | 3 ++ include/Log.h | 26 +++++++++++- include/NebulaLog.h | 8 +++- include/VirtualMachine.h | 3 +- share/etc/oned.conf | 2 + src/log/Log.cc | 79 ++++++++++++++++++++++++++++++++++++ src/nebula/Nebula.cc | 27 ++++++++---- src/nebula/NebulaTemplate.cc | 13 ++++++ 8 files changed, 151 insertions(+), 10 deletions(-) diff --git a/SConstruct b/SConstruct index 4b1b9813af..4a25c82e82 100644 --- a/SConstruct +++ b/SConstruct @@ -118,6 +118,9 @@ if mysql=='yes': else: main_env.Append(mysql='no') +# log4cpp +main_env.Append(LIBS=['pthread','log4cpp']) + # xmlrpc xmlrpc_dir=ARGUMENTS.get('xmlrpc', 'none') if xmlrpc_dir!='none': diff --git a/include/Log.h b/include/Log.h index 49d96d7ae2..4353c65b6b 100644 --- a/include/Log.h +++ b/include/Log.h @@ -20,6 +20,8 @@ #include #include +#include "log4cpp/Priority.hh" + using namespace std; /** @@ -79,7 +81,7 @@ public: const char * module, const MessageType type, const char * message); - + private: char * log_file; }; @@ -137,4 +139,26 @@ public: const char * message); }; + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +/** + * Send log messages to syslog + */ +class SysLog : public Log +{ +public: + SysLog(const MessageType level = WARNING); + + ~SysLog(); + + void log( + const char * module, + const MessageType type, + const char * message); +protected: + log4cpp::Priority::PriorityLevel get_priority_level(const MessageType level); +}; + #endif /* _LOG_H_ */ diff --git a/include/NebulaLog.h b/include/NebulaLog.h index 9eaf902606..0f9c630f63 100644 --- a/include/NebulaLog.h +++ b/include/NebulaLog.h @@ -31,7 +31,8 @@ public: enum LogType { FILE = 0, FILE_TS = 1, - CERR = 2 + CERR = 2, + SYSLOG = 3 }; // --------------------------------------------------------------- @@ -58,6 +59,11 @@ public: } }; + static void init_syslog_system(Log::MessageType clevel) + { + NebulaLog::logger = new SysLog(clevel); + }; + static void finalize_log_system() { delete logger; diff --git a/include/VirtualMachine.h b/include/VirtualMachine.h index 633e186516..64a3e7fdca 100644 --- a/include/VirtualMachine.h +++ b/include/VirtualMachine.h @@ -1049,8 +1049,9 @@ private: * $ONE_LOCATION/var/$VID/vm.log * or, in case that OpenNebula is installed in root * /var/log/one/$VM_ID.log + * For the syslog... TODO */ - FileLog * _log; + Log * _log; /** * User template to store custom metadata. This template can be updated diff --git a/share/etc/oned.conf b/share/etc/oned.conf index f32a3254f0..79e4162c9e 100644 --- a/share/etc/oned.conf +++ b/share/etc/oned.conf @@ -43,6 +43,8 @@ # Values: YES or NO. #******************************************************************************* +LOG_SYSTEM = "syslog" + #MANAGER_TIMER = 30 HOST_MONITORING_INTERVAL = 600 diff --git a/src/log/Log.cc b/src/log/Log.cc index a8a77b2126..b15c68e195 100644 --- a/src/log/Log.cc +++ b/src/log/Log.cc @@ -21,6 +21,15 @@ #include #include #include +#include + +#include "log4cpp/Category.hh" +#include "log4cpp/CategoryStream.hh" +#include "log4cpp/Appender.hh" +#include "log4cpp/SyslogAppender.hh" +#include "log4cpp/Layout.hh" +#include "log4cpp/SimpleLayout.hh" +#include "log4cpp/Priority.hh" /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ @@ -141,3 +150,73 @@ void CerrLog::log( cerr.flush(); } } + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +SysLog::SysLog(const MessageType level):Log(level) { + + log4cpp::Appender *syslog_appender = new log4cpp::SyslogAppender( + "syslog", "OpenNebula", LOG_DAEMON); + + syslog_appender->setLayout(new log4cpp::SimpleLayout()); + + log4cpp::Category& root = log4cpp::Category::getRoot(); + + root.setPriority(get_priority_level(level)); + + root.addAppender(syslog_appender); +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +SysLog::~SysLog() {} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +void SysLog::log( + const char * module, + const MessageType type, + const char * message) +{ + log4cpp::Category& root = log4cpp::Category::getRoot(); + + root << get_priority_level(type) << "[" << module << "]" + << "[" << error_names[type] << "]: " + << message; +} + +log4cpp::Priority::PriorityLevel SysLog::get_priority_level( + const MessageType level) +{ + log4cpp::Priority::PriorityLevel priority_level; + + switch (level) + { + case Log::ERROR: + priority_level = log4cpp::Priority::ERROR; + break; + + case Log::WARNING: + priority_level = log4cpp::Priority::WARN; + break; + + case Log::INFO: + priority_level = log4cpp::Priority::INFO; + break; + + case Log::DEBUG: + case Log::DDEBUG: + case Log::DDDEBUG: + priority_level = log4cpp::Priority::DEBUG; + break; + + default: + priority_level = log4cpp::Priority::NOTSET; + break; + } + + return priority_level; +} diff --git a/src/nebula/Nebula.cc b/src/nebula/Nebula.cc index d69d34427a..a9471697e1 100644 --- a/src/nebula/Nebula.cc +++ b/src/nebula/Nebula.cc @@ -317,18 +317,31 @@ void Nebula::start() try { - string log_fname; Log::MessageType clevel; + string log_system; - log_fname = log_location + "oned.log"; - clevel = get_debug_level(); + nebula_configuration->get("LOG_SYSTEM", log_system); + clevel = get_debug_level(); // Initializing ONE Daemon log system + if ( log_system == "syslog" ) + { + NebulaLog::init_syslog_system(clevel); + } + else if ( log_system == "file" ) + { + string log_fname; + log_fname = log_location + "oned.log"; - NebulaLog::init_log_system(NebulaLog::FILE_TS, - clevel, - log_fname.c_str(), - ios_base::trunc); + NebulaLog::init_log_system(NebulaLog::FILE_TS, + clevel, + log_fname.c_str(), + ios_base::trunc); + } + else + { + throw runtime_error("Unknown LOG_SYSTEM."); + } os << "Starting " << version() << endl; os << "----------------------------------------\n"; diff --git a/src/nebula/NebulaTemplate.cc b/src/nebula/NebulaTemplate.cc index b16af0641e..24b6a8e6e7 100644 --- a/src/nebula/NebulaTemplate.cc +++ b/src/nebula/NebulaTemplate.cc @@ -245,5 +245,18 @@ void OpenNebulaTemplate::set_conf_default() attribute = new SingleAttribute("DEFAULT_UMASK",value); conf_default.insert(make_pair(attribute->name(),attribute)); + +/* +#******************************************************************************* +# Log system configuration +#******************************************************************************* +# LOG_SYSTEM +#******************************************************************************* +*/ + // LOG_SYSTEM + value = "file"; + + attribute = new SingleAttribute("LOG_SYSTEM",value); + conf_default.insert(make_pair(attribute->name(),attribute)); } From 32f8098f8b35ad278c6f828ebf206fe9a9365c0a Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Thu, 31 Jan 2013 17:27:21 +0100 Subject: [PATCH 2/9] Feature #1658: Add SysLogResource class and refactor --- include/Log.h | 46 +++++++++++++++++++--- include/NebulaLog.h | 16 ++++++++ src/log/Log.cc | 95 ++++++++++++++++++++++++++++++++++++--------- 3 files changed, 133 insertions(+), 24 deletions(-) diff --git a/include/Log.h b/include/Log.h index 4353c65b6b..a10ebad4dc 100644 --- a/include/Log.h +++ b/include/Log.h @@ -20,6 +20,8 @@ #include #include +#include "PoolObjectSQL.h" + #include "log4cpp/Priority.hh" using namespace std; @@ -139,7 +141,6 @@ public: const char * message); }; - /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ @@ -149,16 +150,51 @@ public: class SysLog : public Log { public: - SysLog(const MessageType level = WARNING); + SysLog(const MessageType level = WARNING):Log(level){}; - ~SysLog(); + ~SysLog() {}; + + virtual void log( + const char * module, + const MessageType type, + const char * message); + + static void init( + Log::MessageType clevel, + string name, + string label); + + static log4cpp::Priority::PriorityLevel get_priority_level( + const MessageType level); +}; + +/** + * Send log messages to syslog per resource + */ +class SysLogResource : public SysLog +{ +public: + SysLogResource( + int oid, + const PoolObjectSQL::ObjectType obj_type, + const MessageType clevel); + + ~SysLogResource(){}; void log( const char * module, const MessageType type, const char * message); -protected: - log4cpp::Priority::PriorityLevel get_priority_level(const MessageType level); + + static void init( + Log::MessageType clevel, + string name, + string label); + + static string name; + +private: + string obj_label; }; #endif /* _LOG_H_ */ diff --git a/include/NebulaLog.h b/include/NebulaLog.h index 0f9c630f63..4e713a601d 100644 --- a/include/NebulaLog.h +++ b/include/NebulaLog.h @@ -18,8 +18,19 @@ #define _NEBULA_LOG_H_ #include "Log.h" + #include +#include + +//#include "log4cpp/Category.hh" +//#include "log4cpp/CategoryStream.hh" +//#include "log4cpp/Appender.hh" +//#include "log4cpp/SyslogAppender.hh" +//#include "log4cpp/Layout.hh" +//#include "log4cpp/SimpleLayout.hh" +//#include "log4cpp/Priority.hh" + using namespace std; /** @@ -61,7 +72,12 @@ public: static void init_syslog_system(Log::MessageType clevel) { + // Initialize the 'root' syslog logger + SysLog::init(clevel, "root", "OpenNebula"); NebulaLog::logger = new SysLog(clevel); + + // Initialize the 'resource' syslog logger + SysLogResource::init(clevel, "resource", "OpenNebula"); }; static void finalize_log_system() diff --git a/src/log/Log.cc b/src/log/Log.cc index b15c68e195..0bfaaee133 100644 --- a/src/log/Log.cc +++ b/src/log/Log.cc @@ -21,6 +21,7 @@ #include #include #include + #include #include "log4cpp/Category.hh" @@ -154,24 +155,18 @@ void CerrLog::log( /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -SysLog::SysLog(const MessageType level):Log(level) { - - log4cpp::Appender *syslog_appender = new log4cpp::SyslogAppender( - "syslog", "OpenNebula", LOG_DAEMON); - +void SysLog::init( + Log::MessageType clevel, + string name, + string label) +{ + log4cpp::Appender *syslog_appender; + syslog_appender = new log4cpp::SyslogAppender(name,label,LOG_DAEMON); syslog_appender->setLayout(new log4cpp::SimpleLayout()); - log4cpp::Category& root = log4cpp::Category::getRoot(); - - root.setPriority(get_priority_level(level)); - + root.setPriority(SysLog::get_priority_level(clevel)); root.addAppender(syslog_appender); -} - -/* -------------------------------------------------------------------------- */ -/* -------------------------------------------------------------------------- */ - -SysLog::~SysLog() {} +}; /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ @@ -183,13 +178,17 @@ void SysLog::log( { log4cpp::Category& root = log4cpp::Category::getRoot(); - root << get_priority_level(type) << "[" << module << "]" - << "[" << error_names[type] << "]: " - << message; + log4cpp::Priority::PriorityLevel level = get_priority_level(type); + + root << level << "[" << module << "] " + << message; } +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + log4cpp::Priority::PriorityLevel SysLog::get_priority_level( - const MessageType level) + const MessageType level) { log4cpp::Priority::PriorityLevel priority_level; @@ -220,3 +219,61 @@ log4cpp::Priority::PriorityLevel SysLog::get_priority_level( return priority_level; } + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +string SysLogResource::name; + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + + +void SysLogResource::init( + Log::MessageType clevel, + string name, + string label) +{ + SysLogResource::name = name; + + log4cpp::Appender *resource_appender; + resource_appender = new log4cpp::SyslogAppender(name,label,LOG_DAEMON); + + resource_appender->setLayout(new log4cpp::SimpleLayout()); + log4cpp::Category& res = log4cpp::Category::getInstance(name); + res.addAppender(resource_appender); + res.setPriority(SysLog::get_priority_level(clevel)); +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +SysLogResource::SysLogResource( + int oid, + const PoolObjectSQL::ObjectType obj_type, + const MessageType clevel = WARNING) + :SysLog(clevel) +{ + ostringstream oss_label; + string obj_type_str = PoolObjectSQL::type_to_str(obj_type); + + oss_label << "[" << obj_type_str << " " << oid << "]: "; + obj_label = oss_label.str(); +}; + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +void SysLogResource::log( + const char * module, + const MessageType type, + const char * message) +{ + log4cpp::Category& res = log4cpp::Category::getInstance( + SysLogResource::name); + + log4cpp::Priority::PriorityLevel level = get_priority_level(type); + + res << level << "[THISISAVM] " + << message; +} From 50160c50c70b7af9c5f1620a6f2476c94721f440 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Thu, 31 Jan 2013 20:43:17 +0100 Subject: [PATCH 3/9] feature #1658: Move DEBUG_LEVEL and LOG_SYSTEM to the LOG section in oned.conf --- include/Nebula.h | 47 +++++++++++++++++++++++++++++++----- share/etc/oned.conf | 12 ++++++--- src/nebula/Nebula.cc | 2 +- src/nebula/NebulaTemplate.cc | 21 ++++++---------- src/vm/VirtualMachine.cc | 19 +++++++++++++-- 5 files changed, 74 insertions(+), 27 deletions(-) diff --git a/include/Nebula.h b/include/Nebula.h index aeb2dea417..87e7a2c005 100644 --- a/include/Nebula.h +++ b/include/Nebula.h @@ -172,24 +172,59 @@ public: // -------------------------------------------------------------- /** - * Returns the value of DEBUG_LEVEL in oned.conf file + * Returns the value of LOG->DEBUG_LEVEL in oned.conf file * @return the debug level, to instantiate Log'ers */ Log::MessageType get_debug_level() const { - Log::MessageType clevel = Log::ERROR; - int log_level_int; + Log::MessageType clevel = Log::ERROR; + vector logs; + int rc; + int log_level_int; - nebula_configuration->get("DEBUG_LEVEL", log_level_int); + rc = nebula_configuration->get("LOG", logs); - if (0 <= log_level_int && log_level_int <= 3 ) + if ( rc != 0 ) { - clevel = static_cast(log_level_int); + string value; + const VectorAttribute * log = static_cast + (logs[0]); + value = log->vector_value("DEBUG_LEVEL"); + + log_level_int = atoi(value.c_str()); + + if (0 <= log_level_int && log_level_int <= 3 ) + { + clevel = static_cast(log_level_int); + } } return clevel; } + /** + * Returns the value of LOG->SYSTEM in oned.conf file + * @return the system, either "file" or "syslog" + */ + string get_log_system() const + { + vector logs; + int rc; + string log_system = "file"; + + rc = nebula_configuration->get("LOG", logs); + + if ( rc != 0 ) + { + string value; + const VectorAttribute * log = static_cast + (logs[0]); + log_system = log->vector_value("SYSTEM"); + } + + return log_system; + } + /** * Returns the value of ONE_LOCATION env variable. When this variable is * not defined the nebula location is "/". diff --git a/share/etc/oned.conf b/share/etc/oned.conf index 79e4162c9e..826f235f8e 100644 --- a/share/etc/oned.conf +++ b/share/etc/oned.conf @@ -37,13 +37,19 @@ # VNC_BASE_PORT: VNC ports for VMs can be automatically set to VNC_BASE_PORT + # VMID # -# DEBUG_LEVEL: 0 = ERROR, 1 = WARNING, 2 = INFO, 3 = DEBUG +# LOG: Configuration for the logging system +# SYSTEM: either "file" or "syslog". +# DEBUG_LEVEL: 0 = ERROR, 1 = WARNING, 2 = INFO, 3 = DEBUG # # VM_SUBMIT_ON_HOLD: Forces VMs to be created on hold state instead of pending. # Values: YES or NO. #******************************************************************************* +# -LOG_SYSTEM = "syslog" +LOG = [ + # SYSTEM = "file", + DEBUG_LEVEL = 3 +] #MANAGER_TIMER = 30 @@ -71,8 +77,6 @@ DB = [ backend = "sqlite" ] VNC_BASE_PORT = 5900 -DEBUG_LEVEL = 3 - #VM_SUBMIT_ON_HOLD = "NO" #******************************************************************************* diff --git a/src/nebula/Nebula.cc b/src/nebula/Nebula.cc index a9471697e1..f0bb5d84b5 100644 --- a/src/nebula/Nebula.cc +++ b/src/nebula/Nebula.cc @@ -320,7 +320,7 @@ void Nebula::start() Log::MessageType clevel; string log_system; - nebula_configuration->get("LOG_SYSTEM", log_system); + log_system = get_log_system(); clevel = get_debug_level(); // Initializing ONE Daemon log system diff --git a/src/nebula/NebulaTemplate.cc b/src/nebula/NebulaTemplate.cc index 24b6a8e6e7..5e8f20adcb 100644 --- a/src/nebula/NebulaTemplate.cc +++ b/src/nebula/NebulaTemplate.cc @@ -78,6 +78,7 @@ void OpenNebulaTemplate::set_conf_default() SingleAttribute * attribute; VectorAttribute * vattribute; string value; + map vvalue; // MANAGER_TIMER value = "15"; @@ -144,7 +145,6 @@ void OpenNebulaTemplate::set_conf_default() conf_default.insert(make_pair(attribute->name(),attribute)); //DB CONFIGURATION - map vvalue; vvalue.insert(make_pair("BACKEND","sqlite")); vattribute = new VectorAttribute("DB",vvalue); @@ -174,6 +174,12 @@ void OpenNebulaTemplate::set_conf_default() attribute = new SingleAttribute("VM_SUBMIT_ON_HOLD",value); conf_default.insert(make_pair(attribute->name(),attribute)); + // LOG CONFIGURATION + vvalue.clear(); + vvalue.insert(make_pair("SYSTEM","file")); + vvalue.insert(make_pair("DEBUG_LEVEL","3")); + vattribute = new VectorAttribute("LOG",vvalue); + /* #******************************************************************************* # Physical Networks configuration @@ -245,18 +251,5 @@ void OpenNebulaTemplate::set_conf_default() attribute = new SingleAttribute("DEFAULT_UMASK",value); conf_default.insert(make_pair(attribute->name(),attribute)); - -/* -#******************************************************************************* -# Log system configuration -#******************************************************************************* -# LOG_SYSTEM -#******************************************************************************* -*/ - // LOG_SYSTEM - value = "file"; - - attribute = new SingleAttribute("LOG_SYSTEM",value); - conf_default.insert(make_pair(attribute->name(),attribute)); } diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index 835e1d2bb4..4160d1f10a 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -192,9 +192,24 @@ int VirtualMachine::select(SqlDB * db) try { Log::MessageType clevel; + string log_system; + + log_system = nd.get_log_system(); + clevel = nd.get_debug_level(); + + if ( log_system == "file" ) + { + _log = new FileLog(nd.get_vm_log_filename(oid), clevel); + } + else if ( log_system == "syslog" ) + { + _log = new SysLogResource(oid, obj_type, clevel); + } + else + { + throw('Unknown log system.'); + } - clevel = nd.get_debug_level(); - _log = new FileLog(nd.get_vm_log_filename(oid), clevel); } catch(exception &e) { From d506f71f6866da96a30d96f95fb204b87845d0c6 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Thu, 31 Jan 2013 21:27:30 +0100 Subject: [PATCH 4/9] feature #1658: register the default confuguration of oned.conf --- src/nebula/NebulaTemplate.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nebula/NebulaTemplate.cc b/src/nebula/NebulaTemplate.cc index 5e8f20adcb..df80e50b40 100644 --- a/src/nebula/NebulaTemplate.cc +++ b/src/nebula/NebulaTemplate.cc @@ -179,7 +179,7 @@ void OpenNebulaTemplate::set_conf_default() vvalue.insert(make_pair("SYSTEM","file")); vvalue.insert(make_pair("DEBUG_LEVEL","3")); vattribute = new VectorAttribute("LOG",vvalue); - + conf_default.insert(make_pair(vattribute->name(),vattribute)); /* #******************************************************************************* # Physical Networks configuration From b4c48b062fc57972c06c8eb4b4ad0757ee2c1150 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Thu, 31 Jan 2013 22:15:28 +0100 Subject: [PATCH 5/9] feature #1658: Apply proper format to the logger --- src/log/Log.cc | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/src/log/Log.cc b/src/log/Log.cc index 0bfaaee133..313554551f 100644 --- a/src/log/Log.cc +++ b/src/log/Log.cc @@ -22,6 +22,9 @@ #include #include +#include +#include + #include #include "log4cpp/Category.hh" @@ -29,7 +32,7 @@ #include "log4cpp/Appender.hh" #include "log4cpp/SyslogAppender.hh" #include "log4cpp/Layout.hh" -#include "log4cpp/SimpleLayout.hh" +#include "log4cpp/PatternLayout.hh" #include "log4cpp/Priority.hh" /* -------------------------------------------------------------------------- */ @@ -158,11 +161,17 @@ void CerrLog::log( void SysLog::init( Log::MessageType clevel, string name, - string label) + string _label) { + ostringstream oss_label; + string label; + + oss_label << _label << "[" << getpid() << "]"; + label = oss_label.str(); + log4cpp::Appender *syslog_appender; syslog_appender = new log4cpp::SyslogAppender(name,label,LOG_DAEMON); - syslog_appender->setLayout(new log4cpp::SimpleLayout()); + syslog_appender->setLayout(new log4cpp::PatternLayout()); log4cpp::Category& root = log4cpp::Category::getRoot(); root.setPriority(SysLog::get_priority_level(clevel)); root.addAppender(syslog_appender); @@ -180,7 +189,8 @@ void SysLog::log( log4cpp::Priority::PriorityLevel level = get_priority_level(type); - root << level << "[" << module << "] " + root << level << "[" << module << "]" + << "[" << error_names[type] << "]: " << message; } @@ -232,14 +242,20 @@ string SysLogResource::name; void SysLogResource::init( Log::MessageType clevel, string name, - string label) + string _label) { SysLogResource::name = name; + ostringstream oss_label; + string label; + + oss_label << _label << "[" << getpid() << "]"; + label = oss_label.str(); + log4cpp::Appender *resource_appender; resource_appender = new log4cpp::SyslogAppender(name,label,LOG_DAEMON); - resource_appender->setLayout(new log4cpp::SimpleLayout()); + resource_appender->setLayout(new log4cpp::PatternLayout()); log4cpp::Category& res = log4cpp::Category::getInstance(name); res.addAppender(resource_appender); res.setPriority(SysLog::get_priority_level(clevel)); @@ -257,7 +273,7 @@ SysLogResource::SysLogResource( ostringstream oss_label; string obj_type_str = PoolObjectSQL::type_to_str(obj_type); - oss_label << "[" << obj_type_str << " " << oid << "]: "; + oss_label << "[" << obj_type_str << " " << oid << "]"; obj_label = oss_label.str(); }; @@ -274,6 +290,8 @@ void SysLogResource::log( log4cpp::Priority::PriorityLevel level = get_priority_level(type); - res << level << "[THISISAVM] " + res << level << obj_label + << "[" << module << "]" + << "[" << error_names[type] << "]: " << message; } From 7217b53cc2c8ed17478c0246421e58cc9705b04d Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Thu, 31 Jan 2013 23:08:50 +0100 Subject: [PATCH 6/9] feature #1658: the syslog label is now a parameter for the syslog init method and it's not hardcoded inside of it --- include/NebulaLog.h | 6 +++--- src/nebula/Nebula.cc | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/NebulaLog.h b/include/NebulaLog.h index 4e713a601d..aa51acd562 100644 --- a/include/NebulaLog.h +++ b/include/NebulaLog.h @@ -70,14 +70,14 @@ public: } }; - static void init_syslog_system(Log::MessageType clevel) + static void init_syslog_system(Log::MessageType clevel, string label) { // Initialize the 'root' syslog logger - SysLog::init(clevel, "root", "OpenNebula"); + SysLog::init(clevel, "root", label); NebulaLog::logger = new SysLog(clevel); // Initialize the 'resource' syslog logger - SysLogResource::init(clevel, "resource", "OpenNebula"); + SysLogResource::init(clevel, "resource", label); }; static void finalize_log_system() diff --git a/src/nebula/Nebula.cc b/src/nebula/Nebula.cc index f0bb5d84b5..fbf6940f43 100644 --- a/src/nebula/Nebula.cc +++ b/src/nebula/Nebula.cc @@ -326,7 +326,7 @@ void Nebula::start() // Initializing ONE Daemon log system if ( log_system == "syslog" ) { - NebulaLog::init_syslog_system(clevel); + NebulaLog::init_syslog_system(clevel, "oned"); } else if ( log_system == "file" ) { From 4855ade6bcc05e089fb826e68f423d39ac1adc9a Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Thu, 31 Jan 2013 23:11:23 +0100 Subject: [PATCH 7/9] feature #1658: enable syslog for the scheduler --- src/scheduler/etc/sched.conf | 22 ++-- src/scheduler/include/Scheduler.h | 6 ++ src/scheduler/src/sched/Scheduler.cc | 104 +++++++++++-------- src/scheduler/src/sched/SchedulerTemplate.cc | 16 ++- 4 files changed, 89 insertions(+), 59 deletions(-) diff --git a/src/scheduler/etc/sched.conf b/src/scheduler/etc/sched.conf index 543a274078..d336f754a8 100644 --- a/src/scheduler/etc/sched.conf +++ b/src/scheduler/etc/sched.conf @@ -9,31 +9,33 @@ # # SCHED_INTERVAL: Seconds between two scheduling actions # -# MAX_VM: Maximum number of Virtual Machines scheduled in each scheduling +# MAX_VM: Maximum number of Virtual Machines scheduled in each scheduling # action # # MAX_DISPATCH: Maximum number of Virtual Machines actually dispatched to a # host in each scheduling action # -# MAX_HOST: Maximum number of Virtual Machines dispatched to a given host in +# MAX_HOST: Maximum number of Virtual Machines dispatched to a given host in # each scheduling action # # LIVE_RESCHEDS: Perform live (1) or cold migrations (0) when rescheduling a VM # -# HYPERVISOR_MEM: Fraction of total MEMORY reserved for the hypervisor. +# HYPERVISOR_MEM: Fraction of total MEMORY reserved for the hypervisor. # E.g. 0.1 means that only 90% of the total MEMORY will be used # # DEFAULT_SCHED: Definition of the default scheduling algorithm -# - policy: -# 0 = Packing. Heuristic that minimizes the number of hosts in use by +# - policy: +# 0 = Packing. Heuristic that minimizes the number of hosts in use by # packing the VMs in the hosts to reduce VM fragmentation -# 1 = Striping. Heuristic that tries to maximize resources available for +# 1 = Striping. Heuristic that tries to maximize resources available for # the VMs by spreading the VMs in the hosts # 2 = Load-aware. Heuristic that tries to maximize resources available for # the VMs by usingthose nodes with less load -# 3 = Custom. +# 3 = Custom. # - rank: Custom arithmetic exprission to rank suitable hosts based in their # attributes +# +# LOG_SYSTEM: choose the log system, either "file" or "syslog" #******************************************************************************* ONED_PORT = 2633 @@ -49,10 +51,12 @@ LIVE_RESCHEDS = 0 HYPERVISOR_MEM = 0.1 DEFAULT_SCHED = [ - policy = 1 + policy = 1 ] #DEFAULT_SCHED = [ -# policy = 3, +# policy = 3, # rank = "- (RUNNING_VMS * 50 + FREE_CPU)" #] + +#LOG_SYSTEM = "file" diff --git a/src/scheduler/include/Scheduler.h b/src/scheduler/include/Scheduler.h index 9fb7495460..68708692ae 100644 --- a/src/scheduler/include/Scheduler.h +++ b/src/scheduler/include/Scheduler.h @@ -51,6 +51,7 @@ protected: acls(0), timer(0), url(""), + log_system("file"), machines_limit(0), dispatch_limit(0), host_dispatch_limit(0), @@ -165,6 +166,11 @@ private: */ Client * client; + /** + * Log system + */ + string log_system; + // --------------------------------------------------------------- // Timer to periodically schedule and dispatch VMs // --------------------------------------------------------------- diff --git a/src/scheduler/src/sched/Scheduler.cc b/src/scheduler/src/sched/Scheduler.cc index 54a4f9ec4f..16ccab0dad 100644 --- a/src/scheduler/src/sched/Scheduler.cc +++ b/src/scheduler/src/sched/Scheduler.cc @@ -77,46 +77,28 @@ void Scheduler::start() pthread_attr_t pattr; - // ----------------------------------------------------------- - // Log system & Configuration File - // ----------------------------------------------------------- - - try - { - string log_file; - const char * nl = getenv("ONE_LOCATION"); - - if (nl == 0) //OpenNebula installed under root directory - { - log_file = "/var/log/one/sched.log"; - etc_path = "/etc/one/"; - } - else - { - oss << nl << "/var/sched.log"; - - log_file = oss.str(); - - oss.str(""); - oss << nl << "/etc/"; - - etc_path = oss.str(); - } - - NebulaLog::init_log_system(NebulaLog::FILE, - Log::DEBUG, - log_file.c_str()); - - NebulaLog::log("SCHED", Log::INFO, "Init Scheduler Log system"); - } - catch(runtime_error &) - { - throw; - } - // ----------------------------------------------------------- // Configuration File // ----------------------------------------------------------- + string log_file; + const char * nl = getenv("ONE_LOCATION"); + + if (nl == 0) //OpenNebula installed under root directory + { + log_file = "/var/log/one/sched.log"; + etc_path = "/etc/one/"; + } + else + { + oss << nl << "/var/sched.log"; + + log_file = oss.str(); + + oss.str(""); + oss << nl << "/etc/"; + + etc_path = oss.str(); + } SchedulerTemplate conf(etc_path); @@ -128,7 +110,7 @@ void Scheduler::start() conf.get("ONED_PORT", oned_port); oss.str(""); - oss << "http://localhost:" << oned_port << "/RPC2"; + oss << "http://localhost:" << oned_port << "/RPC2"; url = oss.str(); conf.get("SCHED_INTERVAL", timer); @@ -142,9 +124,41 @@ void Scheduler::start() conf.get("LIVE_RESCHEDS", live_rescheds); conf.get("HYPERVISOR_MEM", hypervisor_mem); - + + conf.get("LOG_SYSTEM", log_system); + + // ----------------------------------------------------------- + // Log system & Configuration File + // ----------------------------------------------------------- + + try + { + // Start the log system + if ( log_system == "syslog" ) + { + NebulaLog::init_syslog_system(Log::DEBUG, "mm_sched"); + } + else if ( log_system == "file" ) + { + NebulaLog::init_log_system(NebulaLog::FILE, + Log::DEBUG, + log_file.c_str()); + } + else + { + throw runtime_error("Unknown LOG_SYSTEM."); + } + + + NebulaLog::log("SCHED", Log::INFO, "Init Scheduler Log system"); + } + catch(runtime_error &) + { + throw; + } + oss.str(""); - + oss << "Starting Scheduler Daemon" << endl; oss << "----------------------------------------\n"; oss << " Scheduler Configuration File \n"; @@ -175,7 +189,7 @@ void Scheduler::start() // ----------------------------------------------------------- hpool = new HostPoolXML(client, hypervisor_mem); - vmpool = new VirtualMachinePoolXML(client, + vmpool = new VirtualMachinePoolXML(client, machines_limit, (live_rescheds == 1)); acls = new AclXML(client); @@ -372,18 +386,18 @@ void Scheduler::match() { matched = true; } - + if ( matched == false ) { ostringstream oss; - oss << "Host " << host->get_hid() << + oss << "Host " << host->get_hid() << " filtered out. It does not fullfil REQUIREMENTS."; NebulaLog::log("SCHED",Log::DEBUG,oss); continue; } - + // ----------------------------------------------------------------- // Check if user is authorized // ----------------------------------------------------------------- @@ -401,7 +415,7 @@ void Scheduler::match() host_perms.oid = host->get_hid(); host_perms.obj_type = PoolObjectSQL::HOST; - matched = acls->authorize(uid, + matched = acls->authorize(uid, gid, host_perms, AuthRequest::MANAGE); diff --git a/src/scheduler/src/sched/SchedulerTemplate.cc b/src/scheduler/src/sched/SchedulerTemplate.cc index 51747ee603..7931f5944a 100644 --- a/src/scheduler/src/sched/SchedulerTemplate.cc +++ b/src/scheduler/src/sched/SchedulerTemplate.cc @@ -73,14 +73,14 @@ void SchedulerTemplate::set_conf_default() attribute = new SingleAttribute("MAX_HOST",value); conf_default.insert(make_pair(attribute->name(),attribute)); - + //LIVE_RESCHEDS value = "0"; attribute = new SingleAttribute("LIVE_RESCHEDS",value); conf_default.insert(make_pair(attribute->name(),attribute)); - //DEFAULT_SCHED + //DEFAULT_SCHED map vvalue; vvalue.insert(make_pair("POLICY","1")); @@ -92,6 +92,12 @@ void SchedulerTemplate::set_conf_default() attribute = new SingleAttribute("HYPERVISOR_MEM",value); conf_default.insert(make_pair(attribute->name(),attribute)); + + //LOG_SYSTEM + value = "file"; + + attribute = new SingleAttribute("LOG_SYSTEM", value); + conf_default.insert(make_pair(attribute->name(),attribute)); } /* -------------------------------------------------------------------------- */ @@ -105,7 +111,7 @@ string SchedulerTemplate::get_policy() const istringstream iss; vector vsched; - const VectorAttribute * sched; + const VectorAttribute * sched; get("DEFAULT_SCHED", vsched); @@ -123,7 +129,7 @@ string SchedulerTemplate::get_policy() const case 1: //Striping rank = "- RUNNING_VMS"; break; - + case 2: //Load-aware rank = "FREE_CPU"; break; @@ -137,4 +143,4 @@ string SchedulerTemplate::get_policy() const } return rank; -} \ No newline at end of file +} From d3b790719d3e2bf12e8605a54a247d6c183311ba Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Thu, 31 Jan 2013 23:34:42 +0100 Subject: [PATCH 8/9] Feature #1658: split log messages with newlines into separate messages and log them --- src/log/Log.cc | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/src/log/Log.cc b/src/log/Log.cc index 313554551f..0b7c8c9a19 100644 --- a/src/log/Log.cc +++ b/src/log/Log.cc @@ -186,12 +186,20 @@ void SysLog::log( const char * message) { log4cpp::Category& root = log4cpp::Category::getRoot(); - log4cpp::Priority::PriorityLevel level = get_priority_level(type); - root << level << "[" << module << "]" - << "[" << error_names[type] << "]: " - << message; + istringstream smessage; + string line; + + smessage.str(message); + + + while ( getline(smessage, line) ) + { + root << level << "[" << module << "]" + << "[" << error_names[type] << "]: " + << line; + } } /* -------------------------------------------------------------------------- */ @@ -287,11 +295,18 @@ void SysLogResource::log( { log4cpp::Category& res = log4cpp::Category::getInstance( SysLogResource::name); - log4cpp::Priority::PriorityLevel level = get_priority_level(type); - res << level << obj_label - << "[" << module << "]" - << "[" << error_names[type] << "]: " - << message; + istringstream smessage; + string line; + + smessage.str(message); + + while ( getline(smessage, line) ) + { + res << level << obj_label + << "[" << module << "]" + << "[" << error_names[type] << "]: " + << line; + } } From b924b8c81f863d9aaa208f6f152961ee17c42385 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Fri, 1 Feb 2013 18:49:03 +0100 Subject: [PATCH 9/9] feature #1658: Moved init methods to constructors (static). Make use of log system enums for type cheking. Use the same LOG variables as oned for scheduler. --- include/Log.h | 49 +++++--- include/Nebula.h | 16 +-- include/NebulaLog.h | 56 +++++----- share/etc/oned.conf | 10 +- src/log/Log.cc | 111 ++++++++++--------- src/nebula/Nebula.cc | 17 ++- src/nebula/NebulaTemplate.cc | 1 + src/scheduler/etc/sched.conf | 11 +- src/scheduler/include/Scheduler.h | 7 -- src/scheduler/src/sched/Scheduler.cc | 43 +++++-- src/scheduler/src/sched/SchedulerTemplate.cc | 14 ++- src/vm/VirtualMachine.cc | 32 +++--- 12 files changed, 213 insertions(+), 154 deletions(-) diff --git a/include/Log.h b/include/Log.h index a10ebad4dc..8f307499bf 100644 --- a/include/Log.h +++ b/include/Log.h @@ -150,26 +150,41 @@ public: class SysLog : public Log { public: - SysLog(const MessageType level = WARNING):Log(level){}; + SysLog(const MessageType level, + const string& label); - ~SysLog() {}; + virtual ~SysLog() {}; virtual void log( const char * module, const MessageType type, const char * message); - static void init( - Log::MessageType clevel, - string name, - string label); - static log4cpp::Priority::PriorityLevel get_priority_level( const MessageType level); +protected: + /** + * Specialized constructor only for derived classes that uses an initialzed + * SysLog system. + */ + SysLog(const MessageType level):Log(level){}; + + /** + * This is the root category name used by any syslog resource + * in the process + */ + static const char * CATEGORY; + + /** + * This is the daemon name+pid, used to label every message in the process + */ + static string LABEL; + }; /** - * Send log messages to syslog per resource + * Send log messages to syslog per resource. It requires a Root Syslog + * to be initialized before using a SysLogResource */ class SysLogResource : public SysLog { @@ -179,21 +194,23 @@ public: const PoolObjectSQL::ObjectType obj_type, const MessageType clevel); - ~SysLogResource(){}; + virtual ~SysLogResource(){}; void log( const char * module, const MessageType type, const char * message); - static void init( - Log::MessageType clevel, - string name, - string label); +protected: + /** + * This is the resource category name used by any syslog resource + * in the process + */ + static const char * CATEGORY; - static string name; - -private: + /** + * The resource log label + */ string obj_label; }; diff --git a/include/Nebula.h b/include/Nebula.h index 87e7a2c005..9b68cb3188 100644 --- a/include/Nebula.h +++ b/include/Nebula.h @@ -204,13 +204,13 @@ public: /** * Returns the value of LOG->SYSTEM in oned.conf file - * @return the system, either "file" or "syslog" + * @return the logging system CERR, FILE_TS or SYSLOG */ - string get_log_system() const + NebulaLog::LogType get_log_system() const { - vector logs; - int rc; - string log_system = "file"; + vector logs; + int rc; + NebulaLog::LogType log_system = NebulaLog::UNDEFINED; rc = nebula_configuration->get("LOG", logs); @@ -219,11 +219,13 @@ public: string value; const VectorAttribute * log = static_cast (logs[0]); - log_system = log->vector_value("SYSTEM"); + + value = log->vector_value("SYSTEM"); + log_system = NebulaLog::str_to_type(value); } return log_system; - } + }; /** * Returns the value of ONE_LOCATION env variable. When this variable is diff --git a/include/NebulaLog.h b/include/NebulaLog.h index aa51acd562..ae39469dfd 100644 --- a/include/NebulaLog.h +++ b/include/NebulaLog.h @@ -20,17 +20,8 @@ #include "Log.h" #include - #include -//#include "log4cpp/Category.hh" -//#include "log4cpp/CategoryStream.hh" -//#include "log4cpp/Appender.hh" -//#include "log4cpp/SyslogAppender.hh" -//#include "log4cpp/Layout.hh" -//#include "log4cpp/SimpleLayout.hh" -//#include "log4cpp/Priority.hh" - using namespace std; /** @@ -43,7 +34,8 @@ public: FILE = 0, FILE_TS = 1, CERR = 2, - SYSLOG = 3 + SYSLOG = 3, + UNDEFINED = 4 }; // --------------------------------------------------------------- @@ -53,32 +45,46 @@ public: static void init_log_system( LogType ltype, Log::MessageType clevel, - const char * filename = 0, - ios_base::openmode mode = ios_base::trunc) + const char * filename, + ios_base::openmode mode, + const string& daemon) { switch(ltype) { case FILE: - NebulaLog::logger = new FileLog(filename,clevel,mode); - break; + NebulaLog::logger = new FileLog(filename,clevel,mode); + break; case FILE_TS: - NebulaLog::logger = new FileLogTS(filename,clevel,mode); - break; + NebulaLog::logger = new FileLogTS(filename,clevel,mode); + break; + case SYSLOG: + NebulaLog::logger = new SysLog(clevel, daemon); + break; default: - NebulaLog::logger = new CerrLog(clevel); - break; + NebulaLog::logger = new CerrLog(clevel); + break; } }; - static void init_syslog_system(Log::MessageType clevel, string label) + static LogType str_to_type(string& type) { - // Initialize the 'root' syslog logger - SysLog::init(clevel, "root", label); - NebulaLog::logger = new SysLog(clevel); + transform(type.begin(), type.end(), type.begin(), (int(*)(int))toupper); - // Initialize the 'resource' syslog logger - SysLogResource::init(clevel, "resource", label); - }; + if (type == "FILE") + { + return FILE_TS; + } + else if (type == "SYSLOG") + { + return SYSLOG; + } + else if (type == "STDERR") + { + return CERR; + } + + return UNDEFINED; + } static void finalize_log_system() { diff --git a/share/etc/oned.conf b/share/etc/oned.conf index 826f235f8e..14ee16d8d6 100644 --- a/share/etc/oned.conf +++ b/share/etc/oned.conf @@ -38,8 +38,10 @@ # VMID # # LOG: Configuration for the logging system -# SYSTEM: either "file" or "syslog". -# DEBUG_LEVEL: 0 = ERROR, 1 = WARNING, 2 = INFO, 3 = DEBUG +# system: defines the logging system: +# file to log in the oned.log file +# syslog to use the syslog facilities +# debug_level: 0 = ERROR, 1 = WARNING, 2 = INFO, 3 = DEBUG # # VM_SUBMIT_ON_HOLD: Forces VMs to be created on hold state instead of pending. # Values: YES or NO. @@ -47,8 +49,8 @@ # LOG = [ - # SYSTEM = "file", - DEBUG_LEVEL = 3 + system = "file", + debug_level = 3 ] #MANAGER_TIMER = 30 diff --git a/src/log/Log.cc b/src/log/Log.cc index 0b7c8c9a19..f515bfe575 100644 --- a/src/log/Log.cc +++ b/src/log/Log.cc @@ -158,23 +158,35 @@ void CerrLog::log( /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -void SysLog::init( - Log::MessageType clevel, - string name, - string _label) +const char * SysLog::CATEGORY = "ROOT"; +string SysLog::LABEL; + +/* -------------------------------------------------------------------------- */ + +SysLog::SysLog(const MessageType level, + const string& label):Log(level) { - ostringstream oss_label; - string label; + static bool initialized = false; - oss_label << _label << "[" << getpid() << "]"; - label = oss_label.str(); + if (!initialized) //Initialize just once for all SysLog instances + { + ostringstream oss; + log4cpp::Appender *appender; - log4cpp::Appender *syslog_appender; - syslog_appender = new log4cpp::SyslogAppender(name,label,LOG_DAEMON); - syslog_appender->setLayout(new log4cpp::PatternLayout()); - log4cpp::Category& root = log4cpp::Category::getRoot(); - root.setPriority(SysLog::get_priority_level(clevel)); - root.addAppender(syslog_appender); + oss << label << "[" << getpid() << "]"; + + LABEL = oss.str(); + + appender = new log4cpp::SyslogAppender(CATEGORY, LABEL, LOG_DAEMON); + appender->setLayout(new log4cpp::PatternLayout()); + + log4cpp::Category& root = log4cpp::Category::getRoot(); + + root.setPriority(SysLog::get_priority_level(level)); + root.addAppender(appender); + + initialized = true; + } }; /* -------------------------------------------------------------------------- */ @@ -185,15 +197,14 @@ void SysLog::log( const MessageType type, const char * message) { - log4cpp::Category& root = log4cpp::Category::getRoot(); + log4cpp::Category& root = log4cpp::Category::getRoot(); log4cpp::Priority::PriorityLevel level = get_priority_level(type); - istringstream smessage; - string line; + istringstream smessage; + string line; smessage.str(message); - while ( getline(smessage, line) ) { root << level << "[" << module << "]" @@ -241,49 +252,42 @@ log4cpp::Priority::PriorityLevel SysLog::get_priority_level( /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -string SysLogResource::name; +const char * SysLogResource::CATEGORY = "RESOURCE"; -/* -------------------------------------------------------------------------- */ -/* -------------------------------------------------------------------------- */ - - -void SysLogResource::init( - Log::MessageType clevel, - string name, - string _label) -{ - SysLogResource::name = name; - - ostringstream oss_label; - string label; - - oss_label << _label << "[" << getpid() << "]"; - label = oss_label.str(); - - log4cpp::Appender *resource_appender; - resource_appender = new log4cpp::SyslogAppender(name,label,LOG_DAEMON); - - resource_appender->setLayout(new log4cpp::PatternLayout()); - log4cpp::Category& res = log4cpp::Category::getInstance(name); - res.addAppender(resource_appender); - res.setPriority(SysLog::get_priority_level(clevel)); -} - -/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ SysLogResource::SysLogResource( - int oid, - const PoolObjectSQL::ObjectType obj_type, - const MessageType clevel = WARNING) - :SysLog(clevel) + int oid, + const PoolObjectSQL::ObjectType obj_type, + const MessageType clevel):SysLog(clevel) { + static bool initialized = false; ostringstream oss_label; - string obj_type_str = PoolObjectSQL::type_to_str(obj_type); + string obj_type_str; + + if (!initialized) + { + log4cpp::Appender *appender; + + appender = new log4cpp::SyslogAppender(CATEGORY, + SysLog::LABEL, + LOG_DAEMON); + + appender->setLayout(new log4cpp::PatternLayout()); + + log4cpp::Category& res = log4cpp::Category::getInstance(CATEGORY); + + res.addAppender(appender); + res.setPriority(SysLog::get_priority_level(clevel)); + + initialized = true; + } + + obj_type_str = PoolObjectSQL::type_to_str(obj_type); oss_label << "[" << obj_type_str << " " << oid << "]"; obj_label = oss_label.str(); -}; +} /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ @@ -293,8 +297,7 @@ void SysLogResource::log( const MessageType type, const char * message) { - log4cpp::Category& res = log4cpp::Category::getInstance( - SysLogResource::name); + log4cpp::Category& res = log4cpp::Category::getInstance(CATEGORY); log4cpp::Priority::PriorityLevel level = get_priority_level(type); istringstream smessage; diff --git a/src/nebula/Nebula.cc b/src/nebula/Nebula.cc index fbf6940f43..418ad6117b 100644 --- a/src/nebula/Nebula.cc +++ b/src/nebula/Nebula.cc @@ -317,26 +317,23 @@ void Nebula::start() try { - Log::MessageType clevel; - string log_system; + Log::MessageType clevel; + NebulaLog::LogType log_system; log_system = get_log_system(); - clevel = get_debug_level(); + clevel = get_debug_level(); // Initializing ONE Daemon log system - if ( log_system == "syslog" ) - { - NebulaLog::init_syslog_system(clevel, "oned"); - } - else if ( log_system == "file" ) + if ( log_system != NebulaLog::UNDEFINED ) { string log_fname; log_fname = log_location + "oned.log"; - NebulaLog::init_log_system(NebulaLog::FILE_TS, + NebulaLog::init_log_system(log_system, clevel, log_fname.c_str(), - ios_base::trunc); + ios_base::trunc, + "oned"); } else { diff --git a/src/nebula/NebulaTemplate.cc b/src/nebula/NebulaTemplate.cc index df80e50b40..65b0df29ee 100644 --- a/src/nebula/NebulaTemplate.cc +++ b/src/nebula/NebulaTemplate.cc @@ -178,6 +178,7 @@ void OpenNebulaTemplate::set_conf_default() vvalue.clear(); vvalue.insert(make_pair("SYSTEM","file")); vvalue.insert(make_pair("DEBUG_LEVEL","3")); + vattribute = new VectorAttribute("LOG",vvalue); conf_default.insert(make_pair(vattribute->name(),vattribute)); /* diff --git a/src/scheduler/etc/sched.conf b/src/scheduler/etc/sched.conf index d336f754a8..d5be6c0d4b 100644 --- a/src/scheduler/etc/sched.conf +++ b/src/scheduler/etc/sched.conf @@ -35,7 +35,11 @@ # - rank: Custom arithmetic exprission to rank suitable hosts based in their # attributes # -# LOG_SYSTEM: choose the log system, either "file" or "syslog" +# LOG: Configuration for the logging system +# - system: defines the logging system: +# file to log in the sched.log file +# syslog to use the syslog facilities +# - debug_level: 0 = ERROR, 1 = WARNING, 2 = INFO, 3 = DEBU #******************************************************************************* ONED_PORT = 2633 @@ -59,4 +63,7 @@ DEFAULT_SCHED = [ # rank = "- (RUNNING_VMS * 50 + FREE_CPU)" #] -#LOG_SYSTEM = "file" +LOG = [ + system = "file", + debug_level = 3 +] diff --git a/src/scheduler/include/Scheduler.h b/src/scheduler/include/Scheduler.h index 68708692ae..7c6507542d 100644 --- a/src/scheduler/include/Scheduler.h +++ b/src/scheduler/include/Scheduler.h @@ -51,7 +51,6 @@ protected: acls(0), timer(0), url(""), - log_system("file"), machines_limit(0), dispatch_limit(0), host_dispatch_limit(0), @@ -126,7 +125,6 @@ private: friend void * scheduler_action_loop(void *arg); - // --------------------------------------------------------------- // Scheduling Policies // --------------------------------------------------------------- @@ -166,11 +164,6 @@ private: */ Client * client; - /** - * Log system - */ - string log_system; - // --------------------------------------------------------------- // Timer to periodically schedule and dispatch VMs // --------------------------------------------------------------- diff --git a/src/scheduler/src/sched/Scheduler.cc b/src/scheduler/src/sched/Scheduler.cc index 16ccab0dad..222e376b4a 100644 --- a/src/scheduler/src/sched/Scheduler.cc +++ b/src/scheduler/src/sched/Scheduler.cc @@ -125,31 +125,53 @@ void Scheduler::start() conf.get("HYPERVISOR_MEM", hypervisor_mem); - conf.get("LOG_SYSTEM", log_system); - // ----------------------------------------------------------- // Log system & Configuration File // ----------------------------------------------------------- try { - // Start the log system - if ( log_system == "syslog" ) + vector logs; + int rc; + + NebulaLog::LogType log_system = NebulaLog::UNDEFINED; + Log::MessageType clevel = Log::ERROR;; + + rc = conf.get("LOG", logs); + + if ( rc != 0 ) { - NebulaLog::init_syslog_system(Log::DEBUG, "mm_sched"); + string value; + int ilevel; + + const VectorAttribute * log = static_cast + (logs[0]); + value = log->vector_value("SYSTEM"); + log_system = NebulaLog::str_to_type(value); + + value = log->vector_value("DEBUG_LEVEL"); + ilevel = atoi(value.c_str()); + + if (0 <= ilevel && ilevel <= 3 ) + { + clevel = static_cast(ilevel); + } } - else if ( log_system == "file" ) + + // Start the log system + if ( log_system != NebulaLog::UNDEFINED ) { - NebulaLog::init_log_system(NebulaLog::FILE, - Log::DEBUG, - log_file.c_str()); + NebulaLog::init_log_system(log_system, + clevel, + log_file.c_str(), + ios_base::trunc, + "mm_sched"); } else { throw runtime_error("Unknown LOG_SYSTEM."); } - NebulaLog::log("SCHED", Log::INFO, "Init Scheduler Log system"); } catch(runtime_error &) @@ -181,7 +203,6 @@ void Scheduler::start() throw; } - xmlInitParser(); // ----------------------------------------------------------- diff --git a/src/scheduler/src/sched/SchedulerTemplate.cc b/src/scheduler/src/sched/SchedulerTemplate.cc index 7931f5944a..e51530c18b 100644 --- a/src/scheduler/src/sched/SchedulerTemplate.cc +++ b/src/scheduler/src/sched/SchedulerTemplate.cc @@ -29,6 +29,7 @@ void SchedulerTemplate::set_conf_default() SingleAttribute * attribute; VectorAttribute * vattribute; string value; + map vvalue; /* #******************************************************************************* @@ -42,6 +43,7 @@ void SchedulerTemplate::set_conf_default() # DEFAULT_SCHED # LIVE_RESCHEDS # HYPERVISOR_MEM +# LOG #------------------------------------------------------------------------------- */ // ONED_PORT @@ -81,7 +83,7 @@ void SchedulerTemplate::set_conf_default() conf_default.insert(make_pair(attribute->name(),attribute)); //DEFAULT_SCHED - map vvalue; + vvalue.clear(); vvalue.insert(make_pair("POLICY","1")); vattribute = new VectorAttribute("DEFAULT_SCHED",vvalue); @@ -93,11 +95,13 @@ void SchedulerTemplate::set_conf_default() attribute = new SingleAttribute("HYPERVISOR_MEM",value); conf_default.insert(make_pair(attribute->name(),attribute)); - //LOG_SYSTEM - value = "file"; + //LOG CONFIGURATION + vvalue.clear(); + vvalue.insert(make_pair("SYSTEM","file")); + vvalue.insert(make_pair("DEBUG_LEVEL","3")); - attribute = new SingleAttribute("LOG_SYSTEM", value); - conf_default.insert(make_pair(attribute->name(),attribute)); + vattribute = new VectorAttribute("LOG",vvalue); + conf_default.insert(make_pair(vattribute->name(),vattribute)); } /* -------------------------------------------------------------------------- */ diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index 4160d1f10a..4adf0b1b44 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -191,25 +191,31 @@ int VirtualMachine::select(SqlDB * db) //-------------------------------------------------------------------------- try { - Log::MessageType clevel; - string log_system; + Log::MessageType clevel; + NebulaLog::LogType log_system; log_system = nd.get_log_system(); clevel = nd.get_debug_level(); - if ( log_system == "file" ) + switch(log_system) { - _log = new FileLog(nd.get_vm_log_filename(oid), clevel); - } - else if ( log_system == "syslog" ) - { - _log = new SysLogResource(oid, obj_type, clevel); - } - else - { - throw('Unknown log system.'); - } + case NebulaLog::FILE_TS: + case NebulaLog::FILE: + _log = new FileLog(nd.get_vm_log_filename(oid), clevel); + break; + case NebulaLog::SYSLOG: + _log = new SysLogResource(oid, obj_type, clevel); + break; + + case NebulaLog::CERR: + _log = new CerrLog(clevel); + break; + + default: + throw runtime_error("Unknown log system."); + break; + } } catch(exception &e) {