logger: logarea and loglevel reimplemented; daemon socket option logarea added.
This commit is contained in:
+20
-12
@@ -78,7 +78,7 @@ std::string BaseLoop::decodeMessage(const std::string& data)
|
|||||||
|
|
||||||
case get:
|
case get:
|
||||||
if (cmd.size() < 3) {
|
if (cmd.size() < 3) {
|
||||||
result << "format: get class cmd (sub)";
|
result << "format: [get class cmd (sub)]";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,7 +120,7 @@ std::string BaseLoop::decodeMessage(const std::string& data)
|
|||||||
|
|
||||||
case set:
|
case set:
|
||||||
if (cmd.size() != 4) {
|
if (cmd.size() != 4) {
|
||||||
result << "format: set class cmd value";
|
result << "format: [set class cmd value]";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,7 +173,7 @@ std::string BaseLoop::decodeMessage(const std::string& data)
|
|||||||
|
|
||||||
case cyc:
|
case cyc:
|
||||||
if (cmd.size() < 3) {
|
if (cmd.size() < 3) {
|
||||||
result << "format: cyc class cmd (sub)";
|
result << "format: [cyc class cmd (sub)]";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -201,7 +201,7 @@ std::string BaseLoop::decodeMessage(const std::string& data)
|
|||||||
|
|
||||||
case dump:
|
case dump:
|
||||||
if (cmd.size() < 2) {
|
if (cmd.size() < 2) {
|
||||||
result << "format: dump on|off";
|
result << "format: [dump state] (on|off)";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -210,16 +210,23 @@ std::string BaseLoop::decodeMessage(const std::string& data)
|
|||||||
result << "done";
|
result << "done";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case log:
|
case logarea:
|
||||||
if (cmd.size() < 2) {
|
if (cmd.size() < 2) {
|
||||||
result << "format: log error|event|trace|debug";
|
result << "format: [logarea area,area,..] (bas|net|bus|cyc|all)";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cmd[1] == "error") L.getSink(0)->setLevel(error);
|
L.getSink(0)->setAreas(calcArea(cmd[1]));
|
||||||
if (cmd[1] == "event") L.getSink(0)->setLevel(event);
|
result << "done";
|
||||||
if (cmd[1] == "trace") L.getSink(0)->setLevel(trace);
|
break;
|
||||||
if (cmd[1] == "debug") L.getSink(0)->setLevel(debug);
|
|
||||||
|
case loglevel:
|
||||||
|
if (cmd.size() < 2) {
|
||||||
|
result << "format: [loglevel level] (error|event|trace|debug)";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
L.getSink(0)->setLevel(calcLevel(cmd[1]));
|
||||||
result << "done";
|
result << "done";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -227,8 +234,9 @@ std::string BaseLoop::decodeMessage(const std::string& data)
|
|||||||
result << " get - fetch ebus data [get class cmd (sub)]" << std::endl
|
result << " get - fetch ebus data [get class cmd (sub)]" << std::endl
|
||||||
<< " set - set ebus values [set class cmd value]" << std::endl
|
<< " set - set ebus values [set class cmd value]" << std::endl
|
||||||
<< " cyc - fetch cycle data [cyc class cmd (sub)]" << std::endl
|
<< " cyc - fetch cycle data [cyc class cmd (sub)]" << std::endl
|
||||||
<< " dump - change dump state [dump on|off]" << std::endl
|
<< " dump - change dump state [dump state] (on|off)" << std::endl
|
||||||
<< " log - change log level [log error|event|trace|debug]" << std::endl
|
<< " logarea - change log area [logarea area,area,..] (bas|net|bus|cyc|all)" << std::endl
|
||||||
|
<< " loglevel - change log level [loglevel level] (error|event|trace|debug)" << std::endl
|
||||||
<< " quit - close connection" << std::endl
|
<< " quit - close connection" << std::endl
|
||||||
<< " help - print this page";
|
<< " help - print this page";
|
||||||
break;
|
break;
|
||||||
|
|||||||
+4
-2
@@ -69,7 +69,8 @@ private:
|
|||||||
set, // set ebus value
|
set, // set ebus value
|
||||||
cyc, // fetch cycle data
|
cyc, // fetch cycle data
|
||||||
dump, // change dump state
|
dump, // change dump state
|
||||||
log, // change log level
|
logarea, // change log area
|
||||||
|
loglevel, // change log level
|
||||||
help, // print commands
|
help, // print commands
|
||||||
|
|
||||||
notfound
|
notfound
|
||||||
@@ -81,7 +82,8 @@ private:
|
|||||||
if (strcasecmp(item.c_str(), "set") == 0) return set;
|
if (strcasecmp(item.c_str(), "set") == 0) return set;
|
||||||
if (strcasecmp(item.c_str(), "cyc") == 0) return cyc;
|
if (strcasecmp(item.c_str(), "cyc") == 0) return cyc;
|
||||||
if (strcasecmp(item.c_str(), "dump") == 0) return dump;
|
if (strcasecmp(item.c_str(), "dump") == 0) return dump;
|
||||||
if (strcasecmp(item.c_str(), "log") == 0) return log;
|
if (strcasecmp(item.c_str(), "logarea") == 0) return logarea;
|
||||||
|
if (strcasecmp(item.c_str(), "loglevel") == 0) return loglevel;
|
||||||
if (strcasecmp(item.c_str(), "help") == 0) return help;
|
if (strcasecmp(item.c_str(), "help") == 0) return help;
|
||||||
|
|
||||||
return notfound;
|
return notfound;
|
||||||
|
|||||||
+18
-18
@@ -49,11 +49,11 @@ CYCData* cycdata;
|
|||||||
void define_args()
|
void define_args()
|
||||||
{
|
{
|
||||||
A.addItem("p_address", Appl::Param("FF"), "a", "address",
|
A.addItem("p_address", Appl::Param("FF"), "a", "address",
|
||||||
"\tebus device address (default: FF)",
|
"\tebus device address (FF)",
|
||||||
Appl::type_string, Appl::opt_mandatory);
|
Appl::type_string, Appl::opt_mandatory);
|
||||||
|
|
||||||
A.addItem("p_device", Appl::Param("/dev/ttyUSB0"), "d", "device",
|
A.addItem("p_device", Appl::Param("/dev/ttyUSB0"), "d", "device",
|
||||||
"\tebus device (serial or network) (default: /dev/ttyUSB0)",
|
"\tebus device (serial or network) (/dev/ttyUSB0)",
|
||||||
Appl::type_string, Appl::opt_mandatory);
|
Appl::type_string, Appl::opt_mandatory);
|
||||||
|
|
||||||
A.addItem("p_nodevicecheck", Appl::Param(false), "n", "nodevicecheck",
|
A.addItem("p_nodevicecheck", Appl::Param(false), "n", "nodevicecheck",
|
||||||
@@ -61,11 +61,11 @@ void define_args()
|
|||||||
Appl::type_bool, Appl::opt_none);
|
Appl::type_bool, Appl::opt_none);
|
||||||
|
|
||||||
A.addItem("p_retries", Appl::Param(2), "r", "retries",
|
A.addItem("p_retries", Appl::Param(2), "r", "retries",
|
||||||
"\tnumber retries send ebus command (default: 2)\n",
|
"\tnumber retries send ebus command (2)\n",
|
||||||
Appl::type_int, Appl::opt_mandatory);
|
Appl::type_int, Appl::opt_mandatory);
|
||||||
|
|
||||||
A.addItem("p_ebusconfdir", Appl::Param("/etc/ebus-daemon"), "e", "ebusconfdir",
|
A.addItem("p_ebusconfdir", Appl::Param("/etc/ebus-daemon"), "e", "ebusconfdir",
|
||||||
"directory for ebus configuration (default: /etc/ebus-daemon)\n",
|
"directory for ebus configuration (/etc/ebus-daemon)\n",
|
||||||
Appl::type_string, Appl::opt_mandatory);
|
Appl::type_string, Appl::opt_mandatory);
|
||||||
|
|
||||||
A.addItem("p_foreground", Appl::Param(false), "f", "foreground",
|
A.addItem("p_foreground", Appl::Param(false), "f", "foreground",
|
||||||
@@ -73,7 +73,7 @@ void define_args()
|
|||||||
Appl::type_bool, Appl::opt_none);
|
Appl::type_bool, Appl::opt_none);
|
||||||
|
|
||||||
A.addItem("p_port", Appl::Param(8888), "p", "port",
|
A.addItem("p_port", Appl::Param(8888), "p", "port",
|
||||||
"\tlisten port (default: 8888)",
|
"\tlisten port (8888)",
|
||||||
Appl::type_int, Appl::opt_mandatory);
|
Appl::type_int, Appl::opt_mandatory);
|
||||||
|
|
||||||
A.addItem("p_localhost", Appl::Param(false), "", "localhost",
|
A.addItem("p_localhost", Appl::Param(false), "", "localhost",
|
||||||
@@ -81,27 +81,27 @@ void define_args()
|
|||||||
Appl::type_bool, Appl::opt_none);
|
Appl::type_bool, Appl::opt_none);
|
||||||
|
|
||||||
A.addItem("p_logfile", Appl::Param("/var/log/ebus-daemon.log"), "l", "logfile",
|
A.addItem("p_logfile", Appl::Param("/var/log/ebus-daemon.log"), "l", "logfile",
|
||||||
"\tlog file name (default: /var/log/ebus-daemon.log)",
|
"\tlog file name (/var/log/ebus-daemon.log)",
|
||||||
Appl::type_string, Appl::opt_mandatory);
|
Appl::type_string, Appl::opt_mandatory);
|
||||||
|
|
||||||
A.addItem("p_logarea", Appl::Param(all), "", "logarea",
|
A.addItem("p_logarea", Appl::Param("all"), "", "logarea",
|
||||||
"\tlogging area (bas=1, net=2, bus=4, cyc=8, default: all=15)",
|
"\tlogging area - bas|net|bus|cyc|all (all)",
|
||||||
Appl::type_int, Appl::opt_mandatory);
|
Appl::type_string, Appl::opt_mandatory);
|
||||||
|
|
||||||
A.addItem("p_loglevel", Appl::Param(trace), "", "loglevel",
|
A.addItem("p_loglevel", Appl::Param("trace"), "", "loglevel",
|
||||||
"\tlogging level (error=0, event=1, default: trace=2, debug=3)\n",
|
"\tlogging level - error|event|trace|debug (event)\n",
|
||||||
Appl::type_int, Appl::opt_mandatory);
|
Appl::type_string, Appl::opt_mandatory);
|
||||||
|
|
||||||
A.addItem("p_dump", Appl::Param(false), "D", "dump",
|
A.addItem("p_dump", Appl::Param(false), "D", "dump",
|
||||||
"\tenable dump",
|
"\tenable dump",
|
||||||
Appl::type_bool, Appl::opt_none);
|
Appl::type_bool, Appl::opt_none);
|
||||||
|
|
||||||
A.addItem("p_dumpfile", Appl::Param("/tmp/ebus_dump.bin"), "", "dumpfile",
|
A.addItem("p_dumpfile", Appl::Param("/tmp/ebus_dump.bin"), "", "dumpfile",
|
||||||
"\tdump file name (default: /tmp/ebus_dump.bin)",
|
"\tdump file name (/tmp/ebus_dump.bin)",
|
||||||
Appl::type_string, Appl::opt_mandatory);
|
Appl::type_string, Appl::opt_mandatory);
|
||||||
|
|
||||||
A.addItem("p_dumpsize", Appl::Param(100), "", "dumpsize",
|
A.addItem("p_dumpsize", Appl::Param(100), "", "dumpsize",
|
||||||
"\tmax size for dump file in kB (default: 100)\n",
|
"\tmax size for dump file in kB (100)\n",
|
||||||
Appl::type_long, Appl::opt_mandatory);
|
Appl::type_long, Appl::opt_mandatory);
|
||||||
|
|
||||||
A.addItem("p_settings", Appl::Param(false), "", "settings",
|
A.addItem("p_settings", Appl::Param(false), "", "settings",
|
||||||
@@ -196,13 +196,13 @@ int main(int argc, char* argv[])
|
|||||||
|
|
||||||
// make me Daemon
|
// make me Daemon
|
||||||
if (A.getParam<bool>("p_foreground") == true) {
|
if (A.getParam<bool>("p_foreground") == true) {
|
||||||
L += new LogConsole(A.getParam<int>("p_logarea"),
|
L += new LogConsole(calcArea(A.getParam<const char*>("p_logarea")),
|
||||||
static_cast<const Level>(A.getParam<int>("p_loglevel")),
|
calcLevel(A.getParam<const char*>("p_loglevel")),
|
||||||
"logConsole");
|
"logConsole");
|
||||||
} else {
|
} else {
|
||||||
D.run("/var/run/ebus-daemon.pid");
|
D.run("/var/run/ebus-daemon.pid");
|
||||||
L += new LogFile(A.getParam<int>("p_logarea"),
|
L += new LogFile(calcArea(A.getParam<const char*>("p_logarea")),
|
||||||
static_cast<const Level>(A.getParam<int>("p_loglevel")),
|
calcLevel(A.getParam<const char*>("p_loglevel")),
|
||||||
"logFile", A.getParam<const char*>("p_logfile"));
|
"logFile", A.getParam<const char*>("p_logfile"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+38
-2
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
@@ -30,7 +31,42 @@
|
|||||||
static const char* AreaNames[Size_of_Area] = { "bas", "net", "bus", "cyc" };
|
static const char* AreaNames[Size_of_Area] = { "bas", "net", "bus", "cyc" };
|
||||||
static const char* LevelNames[Size_of_Level] = { "error", "event", "trace", "debug" };
|
static const char* LevelNames[Size_of_Level] = { "error", "event", "trace", "debug" };
|
||||||
|
|
||||||
LogMessage::LogMessage(const Area area, const Level level, const std::string text, const Status status)
|
int calcArea(const std::string area)
|
||||||
|
{
|
||||||
|
int m_area = 0;
|
||||||
|
|
||||||
|
// prepare data
|
||||||
|
std::string token;
|
||||||
|
std::istringstream stream(area);
|
||||||
|
std::vector<std::string> cmd;
|
||||||
|
|
||||||
|
while (std::getline(stream, token, ',') != 0)
|
||||||
|
cmd.push_back(token);
|
||||||
|
|
||||||
|
for (std::vector<std::string>::iterator it = cmd.begin() ; it != cmd.end(); ++it)
|
||||||
|
for (int i = 0; i < Size_of_Area; i++) {
|
||||||
|
if (strcasecmp("all", it->c_str()) == 0)
|
||||||
|
return (pow(2, (int)Size_of_Area) - 1);
|
||||||
|
|
||||||
|
if (strcasecmp(AreaNames[i], it->c_str()) == 0)
|
||||||
|
m_area += pow(2, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
return m_area;
|
||||||
|
}
|
||||||
|
|
||||||
|
int calcLevel(const std::string level)
|
||||||
|
{
|
||||||
|
int m_level = event;
|
||||||
|
for (int i = 0; i < Size_of_Level; i++)
|
||||||
|
if (strcasecmp(LevelNames[i], level.c_str()) == 0)
|
||||||
|
return i;
|
||||||
|
|
||||||
|
return m_level;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
LogMessage::LogMessage(const int area, const int level, const std::string text, const Status status)
|
||||||
: m_area(area), m_level(level), m_text(text), m_status(status)
|
: m_area(area), m_level(level), m_text(text), m_status(status)
|
||||||
{
|
{
|
||||||
char time[24];
|
char time[24];
|
||||||
@@ -145,7 +181,7 @@ LogInstance& LogInstance::operator-= (const LogSink* sink)
|
|||||||
return (*this);
|
return (*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LogInstance::log(const Area area, const Level level, const std::string& data, ...)
|
void LogInstance::log(const int area, const int level, const std::string& data, ...)
|
||||||
{
|
{
|
||||||
if (m_running == true) {
|
if (m_running == true) {
|
||||||
char* tmp;
|
char* tmp;
|
||||||
|
|||||||
+19
-15
@@ -31,13 +31,17 @@
|
|||||||
enum Area { bas=1, net=2, bus=4, cyc=8, all=15, Size_of_Area=4 };
|
enum Area { bas=1, net=2, bus=4, cyc=8, all=15, Size_of_Area=4 };
|
||||||
enum Level { error=0, event, trace, debug, Size_of_Level };
|
enum Level { error=0, event, trace, debug, Size_of_Level };
|
||||||
|
|
||||||
|
int calcArea(const std::string area);
|
||||||
|
int calcLevel(const std::string level);
|
||||||
|
|
||||||
|
|
||||||
class LogMessage
|
class LogMessage
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum Status { Run, End };
|
enum Status { Run, End };
|
||||||
|
|
||||||
LogMessage(const Area area, const Level level, const std::string text, const Status status);
|
LogMessage(const int area, const int level, const std::string text, const Status status);
|
||||||
|
|
||||||
~LogMessage() {}
|
~LogMessage() {}
|
||||||
|
|
||||||
@@ -49,15 +53,15 @@ public:
|
|||||||
{ m_area = src.m_area; m_level = src.m_level; m_text = src.m_text;
|
{ m_area = src.m_area; m_level = src.m_level; m_text = src.m_text;
|
||||||
m_status = src.m_status; m_time = src.m_time; }
|
m_status = src.m_status; m_time = src.m_time; }
|
||||||
|
|
||||||
Area getArea() const { return (m_area); }
|
int getArea() const { return (m_area); }
|
||||||
Level getLevel() const { return(m_level); }
|
int getLevel() const { return(m_level); }
|
||||||
std::string getText() const { return (m_text.c_str()); }
|
std::string getText() const { return (m_text.c_str()); }
|
||||||
Status getStatus() const { return (m_status); }
|
Status getStatus() const { return (m_status); }
|
||||||
std::string getTime() const { return (m_time.c_str()); }
|
std::string getTime() const { return (m_time.c_str()); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Area m_area;
|
int m_area;
|
||||||
Level m_level;
|
int m_level;
|
||||||
std::string m_text;
|
std::string m_text;
|
||||||
Status m_status;
|
Status m_status;
|
||||||
std::string m_time;
|
std::string m_time;
|
||||||
@@ -70,7 +74,7 @@ class LogSink : public Thread
|
|||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
LogSink(const unsigned char areas, const Level level, const Type type, const char* name)
|
LogSink(const int areas, const int level, const Type type, const char* name)
|
||||||
: m_areas(areas), m_level(level), m_type(type), m_name(name) {}
|
: m_areas(areas), m_level(level), m_type(type), m_name(name) {}
|
||||||
|
|
||||||
virtual ~LogSink() {}
|
virtual ~LogSink() {}
|
||||||
@@ -79,11 +83,11 @@ public:
|
|||||||
|
|
||||||
void* run();
|
void* run();
|
||||||
|
|
||||||
unsigned char getAreas() const { return (m_areas); }
|
int getAreas() const { return (m_areas); }
|
||||||
void setAreas(const unsigned char areas) { m_areas = areas; }
|
void setAreas(const int& areas) { m_areas = areas; }
|
||||||
|
|
||||||
Level getLevel() const { return (m_level); }
|
int getLevel() const { return (m_level); }
|
||||||
void setLevel(const Level level) { m_level = level; }
|
void setLevel(const int& level) { m_level = level; }
|
||||||
|
|
||||||
Type getType() const { return (m_type); }
|
Type getType() const { return (m_type); }
|
||||||
const char* getName() const { return (m_name.c_str()); }
|
const char* getName() const { return (m_name.c_str()); }
|
||||||
@@ -92,8 +96,8 @@ protected:
|
|||||||
WQueue<LogMessage*> m_queue;
|
WQueue<LogMessage*> m_queue;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
unsigned char m_areas;
|
int m_areas;
|
||||||
Level m_level;
|
int m_level;
|
||||||
Type m_type;
|
Type m_type;
|
||||||
std::string m_name;
|
std::string m_name;
|
||||||
|
|
||||||
@@ -105,7 +109,7 @@ class LogConsole : public LogSink
|
|||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
LogConsole(const unsigned char areas, const Level level, const char* name)
|
LogConsole(const int areas, const int level, const char* name)
|
||||||
: LogSink(areas, level, Console, name), m_instance(++m_numInstance)
|
: LogSink(areas, level, Console, name), m_instance(++m_numInstance)
|
||||||
{ this->start(name); }
|
{ this->start(name); }
|
||||||
|
|
||||||
@@ -123,7 +127,7 @@ class LogFile : public LogSink
|
|||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
LogFile(const unsigned char areas, const Level level, const char* name, const char* filename)
|
LogFile(const int areas, const int level, const char* name, const char* filename)
|
||||||
: LogSink(areas, level, Logfile, name), m_filename(filename), m_instance(++m_numInstance)
|
: LogSink(areas, level, Logfile, name), m_filename(filename), m_instance(++m_numInstance)
|
||||||
{ this->start(name); }
|
{ this->start(name); }
|
||||||
|
|
||||||
@@ -149,7 +153,7 @@ public:
|
|||||||
LogInstance& operator+= (LogSink* sink);
|
LogInstance& operator+= (LogSink* sink);
|
||||||
LogInstance& operator-= (const LogSink* sink);
|
LogInstance& operator-= (const LogSink* sink);
|
||||||
|
|
||||||
void log(const Area area, const Level level, const std::string& text, ...);
|
void log(const int area, const int level, const std::string& text, ...);
|
||||||
|
|
||||||
int getNumberOfSinks() const { return(m_sinks.size()); }
|
int getNumberOfSinks() const { return(m_sinks.size()); }
|
||||||
LogSink* getSink(const int Index) const { return(m_sinks[Index]); }
|
LogSink* getSink(const int Index) const { return(m_sinks[Index]); }
|
||||||
|
|||||||
Reference in New Issue
Block a user