logger: logarea and loglevel reimplemented; daemon socket option logarea added.
This commit is contained in:
+25
-17
@@ -78,7 +78,7 @@ std::string BaseLoop::decodeMessage(const std::string& data)
|
||||
|
||||
case get:
|
||||
if (cmd.size() < 3) {
|
||||
result << "format: get class cmd (sub)";
|
||||
result << "format: [get class cmd (sub)]";
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ std::string BaseLoop::decodeMessage(const std::string& data)
|
||||
|
||||
case set:
|
||||
if (cmd.size() != 4) {
|
||||
result << "format: set class cmd value";
|
||||
result << "format: [set class cmd value]";
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -173,7 +173,7 @@ std::string BaseLoop::decodeMessage(const std::string& data)
|
||||
|
||||
case cyc:
|
||||
if (cmd.size() < 3) {
|
||||
result << "format: cyc class cmd (sub)";
|
||||
result << "format: [cyc class cmd (sub)]";
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -201,7 +201,7 @@ std::string BaseLoop::decodeMessage(const std::string& data)
|
||||
|
||||
case dump:
|
||||
if (cmd.size() < 2) {
|
||||
result << "format: dump on|off";
|
||||
result << "format: [dump state] (on|off)";
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -210,27 +210,35 @@ std::string BaseLoop::decodeMessage(const std::string& data)
|
||||
result << "done";
|
||||
break;
|
||||
|
||||
case log:
|
||||
case logarea:
|
||||
if (cmd.size() < 2) {
|
||||
result << "format: log error|event|trace|debug";
|
||||
result << "format: [logarea area,area,..] (bas|net|bus|cyc|all)";
|
||||
break;
|
||||
}
|
||||
|
||||
if (cmd[1] == "error") L.getSink(0)->setLevel(error);
|
||||
if (cmd[1] == "event") L.getSink(0)->setLevel(event);
|
||||
if (cmd[1] == "trace") L.getSink(0)->setLevel(trace);
|
||||
if (cmd[1] == "debug") L.getSink(0)->setLevel(debug);
|
||||
L.getSink(0)->setAreas(calcArea(cmd[1]));
|
||||
result << "done";
|
||||
break;
|
||||
|
||||
case loglevel:
|
||||
if (cmd.size() < 2) {
|
||||
result << "format: [loglevel level] (error|event|trace|debug)";
|
||||
break;
|
||||
}
|
||||
|
||||
L.getSink(0)->setLevel(calcLevel(cmd[1]));
|
||||
result << "done";
|
||||
break;
|
||||
|
||||
case help:
|
||||
result << " get - fetch ebus data [get class cmd (sub)]" << std::endl
|
||||
<< " set - set ebus values [set class cmd value]" << std::endl
|
||||
<< " cyc - fetch cycle data [cyc class cmd (sub)]" << std::endl
|
||||
<< " dump - change dump state [dump on|off]" << std::endl
|
||||
<< " log - change log level [log error|event|trace|debug]" << std::endl
|
||||
<< " quit - close connection" << std::endl
|
||||
<< " help - print this page";
|
||||
result << " get - fetch ebus data [get class cmd (sub)]" << std::endl
|
||||
<< " set - set ebus values [set class cmd value]" << std::endl
|
||||
<< " cyc - fetch cycle data [cyc class cmd (sub)]" << std::endl
|
||||
<< " dump - change dump state [dump state] (on|off)" << 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
|
||||
<< " help - print this page";
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
+9
-7
@@ -65,12 +65,13 @@ private:
|
||||
WQueue<Message*> m_queue;
|
||||
|
||||
enum ClientCommand {
|
||||
get, // get ebus data
|
||||
set, // set ebus value
|
||||
cyc, // fetch cycle data
|
||||
dump, // change dump state
|
||||
log, // change log level
|
||||
help, // print commands
|
||||
get, // get ebus data
|
||||
set, // set ebus value
|
||||
cyc, // fetch cycle data
|
||||
dump, // change dump state
|
||||
logarea, // change log area
|
||||
loglevel, // change log level
|
||||
help, // print commands
|
||||
|
||||
notfound
|
||||
};
|
||||
@@ -81,7 +82,8 @@ private:
|
||||
if (strcasecmp(item.c_str(), "set") == 0) return set;
|
||||
if (strcasecmp(item.c_str(), "cyc") == 0) return cyc;
|
||||
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;
|
||||
|
||||
return notfound;
|
||||
|
||||
+18
-18
@@ -49,11 +49,11 @@ CYCData* cycdata;
|
||||
void define_args()
|
||||
{
|
||||
A.addItem("p_address", Appl::Param("FF"), "a", "address",
|
||||
"\tebus device address (default: FF)",
|
||||
"\tebus device address (FF)",
|
||||
Appl::type_string, Appl::opt_mandatory);
|
||||
|
||||
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);
|
||||
|
||||
A.addItem("p_nodevicecheck", Appl::Param(false), "n", "nodevicecheck",
|
||||
@@ -61,11 +61,11 @@ void define_args()
|
||||
Appl::type_bool, Appl::opt_none);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
A.addItem("p_foreground", Appl::Param(false), "f", "foreground",
|
||||
@@ -73,7 +73,7 @@ void define_args()
|
||||
Appl::type_bool, Appl::opt_none);
|
||||
|
||||
A.addItem("p_port", Appl::Param(8888), "p", "port",
|
||||
"\tlisten port (default: 8888)",
|
||||
"\tlisten port (8888)",
|
||||
Appl::type_int, Appl::opt_mandatory);
|
||||
|
||||
A.addItem("p_localhost", Appl::Param(false), "", "localhost",
|
||||
@@ -81,27 +81,27 @@ void define_args()
|
||||
Appl::type_bool, Appl::opt_none);
|
||||
|
||||
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);
|
||||
|
||||
A.addItem("p_logarea", Appl::Param(all), "", "logarea",
|
||||
"\tlogging area (bas=1, net=2, bus=4, cyc=8, default: all=15)",
|
||||
Appl::type_int, Appl::opt_mandatory);
|
||||
A.addItem("p_logarea", Appl::Param("all"), "", "logarea",
|
||||
"\tlogging area - bas|net|bus|cyc|all (all)",
|
||||
Appl::type_string, Appl::opt_mandatory);
|
||||
|
||||
A.addItem("p_loglevel", Appl::Param(trace), "", "loglevel",
|
||||
"\tlogging level (error=0, event=1, default: trace=2, debug=3)\n",
|
||||
Appl::type_int, Appl::opt_mandatory);
|
||||
A.addItem("p_loglevel", Appl::Param("trace"), "", "loglevel",
|
||||
"\tlogging level - error|event|trace|debug (event)\n",
|
||||
Appl::type_string, Appl::opt_mandatory);
|
||||
|
||||
A.addItem("p_dump", Appl::Param(false), "D", "dump",
|
||||
"\tenable dump",
|
||||
Appl::type_bool, Appl::opt_none);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
A.addItem("p_settings", Appl::Param(false), "", "settings",
|
||||
@@ -196,13 +196,13 @@ int main(int argc, char* argv[])
|
||||
|
||||
// make me Daemon
|
||||
if (A.getParam<bool>("p_foreground") == true) {
|
||||
L += new LogConsole(A.getParam<int>("p_logarea"),
|
||||
static_cast<const Level>(A.getParam<int>("p_loglevel")),
|
||||
L += new LogConsole(calcArea(A.getParam<const char*>("p_logarea")),
|
||||
calcLevel(A.getParam<const char*>("p_loglevel")),
|
||||
"logConsole");
|
||||
} else {
|
||||
D.run("/var/run/ebus-daemon.pid");
|
||||
L += new LogFile(A.getParam<int>("p_logarea"),
|
||||
static_cast<const Level>(A.getParam<int>("p_loglevel")),
|
||||
L += new LogFile(calcArea(A.getParam<const char*>("p_logarea")),
|
||||
calcLevel(A.getParam<const char*>("p_loglevel")),
|
||||
"logFile", A.getParam<const char*>("p_logfile"));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user