diff --git a/include/HostTemplate.h b/include/HostTemplate.h index 3e565c807c..c7516d4b9e 100644 --- a/include/HostTemplate.h +++ b/include/HostTemplate.h @@ -28,7 +28,10 @@ using namespace std; class HostTemplate : public TemplateSQL { public: - HostTemplate(int tid = -1):TemplateSQL(table,tid,true){}; + HostTemplate(int tid = -1, + const char separator = '^'): + TemplateSQL(table,tid,true,separator) + {}; ~HostTemplate(){}; diff --git a/include/Log.h b/include/Log.h index 1bb812aa01..be5f3776b9 100644 --- a/include/Log.h +++ b/include/Log.h @@ -37,7 +37,8 @@ public: const char *, const MessageType, const ostringstream&, - const char *); + const char *, + const MessageType); Log(const string& file_name, const MessageType level = WARNING, @@ -58,7 +59,7 @@ public: private: static const char error_names[]; - + MessageType log_level; ofstream file; diff --git a/include/Nebula.h b/include/Nebula.h index 1bbe139d34..71fc6f00a3 100644 --- a/include/Nebula.h +++ b/include/Nebula.h @@ -36,7 +36,7 @@ class Nebula { public: - + static Nebula& instance() { static Nebula nebulad; @@ -45,18 +45,19 @@ public: }; // --------------------------------------------------------------- - // Loggging + // Logging // --------------------------------------------------------------- static void log( const char * module, const Log::MessageType type, const ostringstream& message, - const char * filename = 0) + const char * filename = 0, + Log::MessageType clevel = Log::ERROR) { - static Log nebula_log(filename,Log::DEBUG,ios_base::trunc); - static pthread_mutex_t log_mutex = PTHREAD_MUTEX_INITIALIZER; - + static Log nebula_log(filename,clevel,ios_base::trunc); + static pthread_mutex_t log_mutex = PTHREAD_MUTEX_INITIALIZER; + pthread_mutex_lock(&log_mutex); nebula_log.log(module,type,message); pthread_mutex_unlock(&log_mutex); diff --git a/include/NebulaTemplate.h b/include/NebulaTemplate.h index 3d7645b808..b0cbab76e0 100644 --- a/include/NebulaTemplate.h +++ b/include/NebulaTemplate.h @@ -39,6 +39,25 @@ public: return Template::get(_name,values); }; + + void get( + const char * name, + string& values) const + { + string _name(name); + + Template::get(_name,values); + }; + + + void get( + const char * name, + int& values) const + { + string _name(name); + + Template::get(_name,values); + }; private: friend class Nebula; diff --git a/include/Scheduler.h b/include/Scheduler.h index 0e29b525c1..fdb5bb5960 100644 --- a/include/Scheduler.h +++ b/include/Scheduler.h @@ -54,9 +54,10 @@ public: const char * module, const Log::MessageType type, const ostringstream& message, - const char * filename = 0) + const char * filename = 0, + Log::MessageType clevel = Log::ERROR) { - static Log scheduler_log(filename,Log::DEBUG); + static Log scheduler_log(filename,clevel); static pthread_mutex_t log_mutex = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_lock(&log_mutex); diff --git a/include/SqliteDB.h b/include/SqliteDB.h index 391f91242c..9bf1dd08b6 100644 --- a/include/SqliteDB.h +++ b/include/SqliteDB.h @@ -122,7 +122,7 @@ public: ostringstream oss; oss << "SQL command was: " << c_str << ", error: " << err_msg; - log("ONE",Log::ERROR,oss,0); + log("ONE",Log::ERROR,oss,0,Log::ERROR); sqlite3_free(err_msg); } diff --git a/include/Template.h b/include/Template.h index fe27d74382..566da06a84 100644 --- a/include/Template.h +++ b/include/Template.h @@ -38,7 +38,10 @@ class Template { public: - Template(bool _replace_mode=false):replace_mode(_replace_mode){}; + Template(bool _replace_mode = false, + const char _separator = '='): + replace_mode(_replace_mode), + separator(_separator){}; /** * The class destructor frees all the attributes conforming the template @@ -131,6 +134,11 @@ private: * Mutex to perform just one flex-bison parsing at a time */ static pthread_mutex_t mutex; + + /** + * Character to separate key from value when dump onto a string + **/ + char separator; }; /* -------------------------------------------------------------------------- */ diff --git a/include/TemplateSQL.h b/include/TemplateSQL.h index 87c0db69ba..cee9757fc5 100644 --- a/include/TemplateSQL.h +++ b/include/TemplateSQL.h @@ -37,8 +37,9 @@ public: TemplateSQL( const char * _table, int template_id = -1, - bool replace = false): - Template(replace),table(_table),id(template_id) + bool replace = false, + const char separator = '='): + Template(replace,separator),table(_table),id(template_id) {}; virtual ~TemplateSQL(){}; diff --git a/share/etc/oned.conf b/share/etc/oned.conf index 189d801981..4d811b9a42 100644 --- a/share/etc/oned.conf +++ b/share/etc/oned.conf @@ -39,3 +39,8 @@ VM_MAD=[name="one_vmm",executable="bin/one_vmm_xen",owner="oneadmin",default="et # Port where oned will listen for xmlrpc calls. PORT=2633 + +# ########### +# DEBUG LEVEL [0=ERROR,1=WARNING,2=INFO,3=DEBUG] +# ########### +DEBUG_LEVEL=2 diff --git a/src/nebula/Nebula.cc b/src/nebula/Nebula.cc index 1fb212e7bc..9192a1a6fa 100644 --- a/src/nebula/Nebula.cc +++ b/src/nebula/Nebula.cc @@ -41,6 +41,9 @@ void Nebula::start() sigset_t mask; int signal; + const SingleAttribute * sattr; + vector attr; + nl = getenv("ONE_LOCATION"); if (nl == 0) @@ -50,23 +53,6 @@ void Nebula::start() nebula_location = nl; - // ----------------------------------------------------------- - // Log system - // ----------------------------------------------------------- - - try - { - string log_fname; - - log_fname = nebula_location + "/var/oned.log"; - - Nebula::log("ONE",Log::INFO,"Init Log system",log_fname.c_str()); - } - catch(runtime_error&) - { - throw; - } - // ----------------------------------------------------------- // Configuration // ----------------------------------------------------------- @@ -79,14 +65,64 @@ void Nebula::start() { throw runtime_error("Could not load nebula configuration file."); } - + + // ----------------------------------------------------------- + // Log system + // ----------------------------------------------------------- + ostringstream os; + + try + { + string log_fname; + int log_level_int; + log_fname = nebula_location + "/var/oned.log"; + Log::MessageType clevel = Log::ERROR; + + nebula_configuration->get("DEBUG_LEVEL", log_level_int); + + if (0 <= log_level_int && log_level_int <= 3 ) + { + clevel = static_cast(log_level_int); + } + + os << "Init OpenNEbula Log system"; + + // Initializing ONE Daemon log system + + Nebula::log("ONE", + Log::INFO, + os, + log_fname.c_str(), + clevel); + + os.str(""); + os << "Log Level: " << clevel << " [0=ERROR,1=WARNING,2=INFO,3=DEBUG]"; + + // Initializing ONE Daemon log system + + Nebula::log("ONE", + Log::INFO, + os, + log_fname.c_str(), + clevel); + + + } + catch(runtime_error&) + { + throw; + } Nebula::log("ONE",Log::INFO,"----------------------------------------------"); Nebula::log("ONE",Log::INFO," OpenNEbula Configuration File "); Nebula::log("ONE",Log::INFO,"----------------------------------------------"); + os.str(""); + + os << "\n--------------------------------------------"; os << *nebula_configuration; + os << "\n--------------------------------------------"; Nebula::log("ONE",Log::INFO,os); @@ -150,8 +186,6 @@ void Nebula::start() MadManager::mad_manager_system_init(); - const SingleAttribute * sattr; - vector attr; time_t timer_period; istringstream is; @@ -354,7 +388,7 @@ void Nebula::start() im->finalize(); rm->finalize(); - //sleep to wait drviers??? + //sleep to wait drivers??? pthread_join(vmm->get_thread_id(),0); pthread_join(lcm->get_thread_id(),0); diff --git a/src/nebula/NebulaTemplate.cc b/src/nebula/NebulaTemplate.cc index e4dd5d1d58..1563b90dcd 100644 --- a/src/nebula/NebulaTemplate.cc +++ b/src/nebula/NebulaTemplate.cc @@ -74,6 +74,12 @@ NebulaTemplate::NebulaTemplate(string& nebula_location) attribute = new SingleAttribute("VM_RDIR",value); conf_default.insert(make_pair(attribute->name(),attribute)); + + //DEBUG_LEVEL + value = Log::WARNING; + + attribute = new SingleAttribute("DEBUG_LEVEL",value); + conf_default.insert(make_pair(attribute->name(),attribute)); } /* -------------------------------------------------------------------------- */ diff --git a/src/scheduler/Scheduler.cc b/src/scheduler/Scheduler.cc index 69ad16698a..736f191db4 100644 --- a/src/scheduler/Scheduler.cc +++ b/src/scheduler/Scheduler.cc @@ -88,7 +88,10 @@ void Scheduler::start() log_fname = nebula_location + "/var/sched.log"; - Scheduler::log("SCHED",Log::INFO,"Init Log system",log_fname.c_str()); + Scheduler::log("SCHED", + Log::INFO, + "Init Scheduler Log system", + log_fname.c_str()); } catch(runtime_error &) { diff --git a/src/template/Template.cc b/src/template/Template.cc index 3afa7fdd09..75272b8090 100644 --- a/src/template/Template.cc +++ b/src/template/Template.cc @@ -243,7 +243,7 @@ ostream& operator << (ostream& os, Template& t) { s = it->second->marshall(); - os << endl << "\t" << it->first << " ^ " << *s; + os << endl << "\t" << it->first << t.separator << *s; delete s; }