Commit 6e06e4a5 authored by Pavel Vainerman's avatar Pavel Vainerman

(LogServer): добавил команду вывода списка подключённых (контролируемых) логов,

edit todo, make style
parent 1f3682ef
......@@ -45,7 +45,6 @@ Version 2.0
uniset-codegen: добавить ключ --gen-sensor-name для генерирования name_Item.. (чтобы можно было в логах использовать текстовые названия)
- перевести PassiveTimer на использование crono:: (c++11)
- LogServer: добавил команду -l для вывода списка "доступных"(управляемых) логов
SQL:
====
......
......@@ -21,6 +21,7 @@ static struct option longopts[] =
{ "set", required_argument, 0, 's' },
{ "off", required_argument, 0, 'o' },
{ "on", required_argument, 0, 'n' },
{ "list", no_argument, 0, 'm' },
{ "rotate", required_argument, 0, 'r' },
{ "logname", required_argument, 0, 'l' },
{ "command-only", no_argument, 0, 'b' },
......@@ -49,10 +50,13 @@ static void print_help()
printf("--off, -o - Off the write log file (if enabled).\n");
printf("--on, -n - On the write log file (if before disabled).\n");
printf("--rotate, -r - rotate log file.\n");
printf("--list, -m - List of managed logs.\n");
}
// --------------------------------------------------------------------------
int main( int argc, char** argv )
{
std::ios::sync_with_stdio(false);
int optindex = 0;
int opt = 0;
int verb = 0;
......@@ -69,7 +73,7 @@ int main( int argc, char** argv )
try
{
while( (opt = getopt_long(argc, argv, "hva:p:i:d:s:l:onrbx:w:", longopts, &optindex)) != -1 )
while( (opt = getopt_long(argc, argv, "hvma:p:i:d:s:l:onrbx:w:", longopts, &optindex)) != -1 )
{
switch (opt)
{
......@@ -98,6 +102,10 @@ int main( int argc, char** argv )
}
break;
case 'm':
cmd = LogServerTypes::cmdList;
break;
case 'o':
cmd = LogServerTypes::cmdOffLogFile;
break;
......
......@@ -34,6 +34,8 @@ static void print_help()
// --------------------------------------------------------------------------
int main( int argc, char** argv )
{
std::ios::sync_with_stdio(false);
int optindex = 0;
int opt = 0;
int verb = 0;
......
......@@ -13,7 +13,7 @@ using namespace UniSetExtensions;
// -----------------------------------------------------------------------------
RRDServer::RRDServer( UniSetTypes::ObjectId objId, xmlNode* cnode, UniSetTypes::ObjectId shmId, const std::shared_ptr<SharedMemory> ic,
const string& prefix ):
UObject_SK(objId, cnode, string(prefix+"-")),
UObject_SK(objId, cnode, string(prefix + "-")),
prefix(prefix)
{
auto conf = uniset_conf();
......
......@@ -541,10 +541,10 @@ bool UNetReceiver::recv()
// -----------------------------------------------------------------------------
void UNetReceiver::initIterators()
{
for( auto&& it : d_icache )
for( auto && it : d_icache )
shm->initIterator(it.ioit);
for( auto&& it : a_icache )
for( auto && it : a_icache )
shm->initIterator(it.ioit);
}
// -----------------------------------------------------------------------------
......
......@@ -357,13 +357,13 @@ std::ostream& operator<<( std::ostream& os, UNetSender::UItem& p )
// -----------------------------------------------------------------------------
void UNetSender::initIterators()
{
for( auto&& it: dlist )
for( auto && it : dlist )
shm->initIterator(it.ioit);
}
// -----------------------------------------------------------------------------
void UNetSender::askSensors( UniversalIO::UIOCommand cmd )
{
for( auto&& it: dlist )
for( auto && it : dlist )
shm->askSensor(it.id, cmd);
}
// -----------------------------------------------------------------------------
......@@ -3,6 +3,7 @@
// -------------------------------------------------------------------------
#include <string>
#include <memory>
#include <list>
#include <unordered_map>
#include "DebugStream.h"
#include "LogServerTypes.h"
......@@ -39,6 +40,8 @@ class LogAgregator:
std::shared_ptr<DebugStream> getLog( const std::string& logname );
LogInfo getLogInfo( const std::string& logname );
std::list<std::shared_ptr<DebugStream>> getLogList();
protected:
void logOnEvent( const std::string& s );
......
......@@ -16,7 +16,8 @@ namespace LogServerTypes
cmdDelLevel, /*!< удалить уровень вывода */
cmdRotate, /*!< пересоздать файл с логами */
cmdOffLogFile, /*!< отключить запись файла логов (если включена) */
cmdOnLogFile /*!< включить запись файла логов (если была отключена) */
cmdOnLogFile, /*!< включить запись файла логов (если была отключена) */
cmdList /*!< вывести список контролируемых логов */
// cmdSetLogFile
};
......
......@@ -66,7 +66,7 @@ namespace UniSetTypes
void initLocalNode( const UniSetTypes::ObjectId nodeid );
protected:
std::string nmLocalNode={""}; // поле для оптимизации получения LocalNode
std::string nmLocalNode = {""}; // поле для оптимизации получения LocalNode
private:
......
......@@ -44,7 +44,7 @@ class UniXML_iterator:
UniXML_iterator(xmlNode* node) :
curNode(node)
{}
UniXML_iterator():curNode(0) {}
UniXML_iterator(): curNode(0) {}
std::string getProp2( const std::string& name, const std::string& defval = "" );
std::string getProp( const std::string& name );
......
......@@ -108,3 +108,13 @@ LogAgregator::LogInfo LogAgregator::getLogInfo( const std::string& logname )
return LogInfo();
}
// -------------------------------------------------------------------------
std::list<std::shared_ptr<DebugStream>> LogAgregator::getLogList()
{
std::list< std::shared_ptr<DebugStream> > l;
for( auto && i : lmap )
l.push_back(i.second.log);
return std::move(l);
}
// -------------------------------------------------------------------------
......@@ -150,65 +150,76 @@ void LogReader::readlogs( const std::string& _addr, ost::tpport_t _port, LogServ
while( n > 0 )
{
if( !isConnection() )
connect(_addr, _port, reconDelay);
if( !isConnection() )
try
{
rlog.warn() << "(LogReader): **** connection timeout.." << endl;
if( readcount > 0 )
n--;
if( n < 0 )
break;
msleep(reconDelay);
continue;
}
if( !isConnection() )
connect(_addr, _port, reconDelay);
if( !send_ok && msg.cmd != LogServerTypes::cmdNOP )
{
if( tcp->isPending(ost::Socket::pendingOutput, outTimeout) )
if( !isConnection() )
{
rlog.info() << "(LogReader): ** send command: logname='" << msg.logname << "' cmd='" << msg.cmd << "' data='" << msg.data << "'" << endl;
rlog.warn() << "(LogReader): **** connection timeout.." << endl;
if( readcount > 0 )
n--;
// LogServerTypes::lsMessage msg;
// msg.cmd = cmd;
// msg.data = data;
for( size_t i = 0; i < sizeof(msg); i++ )
(*tcp) << ((unsigned char*)(&msg))[i];
if( n < 0 )
break;
tcp->sync();
send_ok = true;
msleep(reconDelay);
continue;
}
else
rlog.warn() << "(LogReader): **** SEND COMMAND ('" << msg.cmd << "' FAILED!" << endl;
if( cmdonly )
if( !send_ok && msg.cmd != LogServerTypes::cmdNOP )
{
disconnect();
return;
if( tcp->isPending(ost::Socket::pendingOutput, outTimeout) )
{
rlog.info() << "(LogReader): ** send command: logname='" << msg.logname << "' cmd='" << msg.cmd << "' data='" << msg.data << "'" << endl;
// LogServerTypes::lsMessage msg;
// msg.cmd = cmd;
// msg.data = data;
for( size_t i = 0; i < sizeof(msg); i++ )
(*tcp) << ((unsigned char*)(&msg))[i];
tcp->sync();
send_ok = true;
}
else
rlog.warn() << "(LogReader): **** SEND COMMAND ('" << msg.cmd << "' FAILED!" << endl;
if( cmdonly )
{
disconnect();
return;
}
}
}
while( !cmdonly && tcp->isPending(ost::Socket::pendingInput, inTimeout) )
{
int n = tcp->peek( buf, sizeof(buf) - 1 );
if( n > 0 )
while( !cmdonly && tcp->isPending(ost::Socket::pendingInput, inTimeout) )
{
tcp->read(buf, n);
buf[n] = '\0';
log << buf;
int n = tcp->peek( buf, sizeof(buf) - 1 );
if( n > 0 )
{
tcp->read(buf, n);
buf[n] = '\0';
log << buf;
}
else
break;
}
else
break;
}
rlog.warn() << "(LogReader): ...connection timeout..." << endl;
send_ok = false; // ??!! делать ли?
disconnect();
rlog.warn() << "(LogReader): ...connection timeout..." << endl;
send_ok = false; // ??!! делать ли?
disconnect();
}
catch( const ost::SockException& e )
{
cerr << "(LogReader): " << e.getString() << " (" << _addr << ")" << endl;
}
catch( const std::exception& ex )
{
cerr << "(LogReader): " << ex.what() << endl;
}
if( readcount > 0 )
n--;
......
......@@ -168,6 +168,35 @@ void LogSession::run()
break;
case LogServerTypes::cmdList:
{
if( isPending(Socket::pendingOutput, cmdTimeout) )
{
ostringstream s;
s << "List of managed logs:" << endl;
s << "=====================" << endl;
auto lag = dynamic_pointer_cast<LogAgregator>(log);
if( !lag )
{
s << log->getLogName() << endl;
}
else
{
auto lst = lag->getLogList();
for( const auto& i : lst )
s << i->getLogName() << endl;
}
s << "=====================" << endl;
*tcp() << s.str();
tcp()->sync();
}
}
break;
case LogServerTypes::cmdOffLogFile:
{
if( !logfile.empty() )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment