1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-21 18:03:38 +03:00

Added DEBUG_LEVEL to oned.conf. Task for ticket #5.

git-svn-id: http://svn.opennebula.org/trunk@3 3034c82b-c49b-4eb3-8279-a7acafdc01c0
This commit is contained in:
Constantino Vázquez Blanco 2008-06-18 15:58:44 +00:00
parent 6eb9fed97d
commit 3db8342e8f
13 changed files with 120 additions and 38 deletions

View File

@ -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(){};

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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);

View File

@ -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);
}

View File

@ -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;
};
/* -------------------------------------------------------------------------- */

View File

@ -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(){};

View File

@ -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

View File

@ -41,6 +41,9 @@ void Nebula::start()
sigset_t mask;
int signal;
const SingleAttribute * sattr;
vector<const Attribute *> 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::MessageType>(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<const Attribute *> 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);

View File

@ -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));
}
/* -------------------------------------------------------------------------- */

View File

@ -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 &)
{

View File

@ -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;
}