Commit 9a5124a8 authored by Pavel Vainerman's avatar Pavel Vainerman

Версия 2.1-alt5 (модифицированный LogServer и uniset-log)

parent dcc56de5
...@@ -76,6 +76,7 @@ int main( int argc, char** argv ) ...@@ -76,6 +76,7 @@ int main( int argc, char** argv )
int cmdonly = 0; int cmdonly = 0;
timeout_t tout = 0; timeout_t tout = 0;
timeout_t rdelay = 5000; timeout_t rdelay = 5000;
bool cmdlist = false;
try try
{ {
...@@ -132,14 +133,14 @@ int main( int argc, char** argv ) ...@@ -132,14 +133,14 @@ int main( int argc, char** argv )
case 'l': case 'l':
{ {
cmdonly = 1; cmdonly = 1;
cmd = LogServerTypes::cmdList;
std::string filter(""); std::string filter("");
char* arg2 = checkArg(optind, argc, argv); char* arg2 = checkArg(optind, argc, argv);
if( arg2 ) if( arg2 )
filter = string(arg2); filter = string(arg2);
logfilter = filter; vcmd.push_back( LogReader::Command(LogServerTypes::cmdList,0, filter) );
cmdlist = true;
} }
break; break;
...@@ -237,7 +238,16 @@ int main( int argc, char** argv ) ...@@ -237,7 +238,16 @@ int main( int argc, char** argv )
lr.setCommandOnlyMode(cmdonly); lr.setCommandOnlyMode(cmdonly);
lr.setinTimeout(tout); lr.setinTimeout(tout);
lr.setReconnectDelay(rdelay); lr.setReconnectDelay(rdelay);
/*
if( cmdlist && vcmd.size() == 1 )
{
cmdonly = 1;
lr.setReadCount(1);
lr.sendCommand(addr, port, vcmd, cmdonly, verb);
return 0;
}
*/
if( !vcmd.empty() ) if( !vcmd.empty() )
lr.sendCommand(addr, port, vcmd, cmdonly, verb); lr.sendCommand(addr, port, vcmd, cmdonly, verb);
......
...@@ -114,10 +114,16 @@ int main( int argc, char** argv ) ...@@ -114,10 +114,16 @@ int main( int argc, char** argv )
} }
la->add(dlog);
auto la2 = make_shared<LogAgregator>("la2"); auto la2 = make_shared<LogAgregator>("la2");
auto dlog3 = la2->create("dlog3"); auto dlog3 = la2->create("dlog3");
auto dlog4 = la2->create("dlog4"); auto dlog4 = la2->create("dlog4");
la2->add(dlog);
la2->add(dlog2);
la->add(la2); la->add(la2);
if( la->getLog("la2/dlog3") == nullptr ) if( la->getLog("la2/dlog3") == nullptr )
...@@ -132,7 +138,7 @@ int main( int argc, char** argv ) ...@@ -132,7 +138,7 @@ int main( int argc, char** argv )
auto dlog5 = la3->create("dlog5"); auto dlog5 = la3->create("dlog5");
auto dlog6 = la3->create("dlog6"); auto dlog6 = la3->create("dlog6");
la->add(la3); la->add(la3);
#if 0
for( int i = 0; i < 15; i++ ) for( int i = 0; i < 15; i++ )
{ {
ostringstream s; ostringstream s;
...@@ -145,7 +151,7 @@ int main( int argc, char** argv ) ...@@ -145,7 +151,7 @@ int main( int argc, char** argv )
la->add(l); la->add(l);
} }
#endif
#if 0 #if 0
cout << la << endl; cout << la << endl;
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
Name: libuniset2 Name: libuniset2
Version: 2.1 Version: 2.1
Release: alt4 Release: alt5
Summary: UniSet - library for building distributed industrial control systems Summary: UniSet - library for building distributed industrial control systems
...@@ -455,6 +455,9 @@ mv -f %buildroot%python_sitelibdir_noarch/* %buildroot%python_sitelibdir/%oname ...@@ -455,6 +455,9 @@ mv -f %buildroot%python_sitelibdir_noarch/* %buildroot%python_sitelibdir/%oname
# .. # ..
%changelog %changelog
* Tue Jun 02 2015 Pavel Vainerman <pv@altlinux.ru> 2.1-alt5
- (LogServer): refactoring
* Mon Jun 01 2015 Pavel Vainerman <pv@altlinux.ru> 2.1-alt4 * Mon Jun 01 2015 Pavel Vainerman <pv@altlinux.ru> 2.1-alt4
- (LogServer): added suppport "filter mode" - (LogServer): added suppport "filter mode"
- (LogAgregator): refactoring, change show loglist format - (LogAgregator): refactoring, change show loglist format
......
...@@ -107,6 +107,10 @@ ...@@ -107,6 +107,10 @@
\note Полнота и формат поддерживаемых регулярных выражений зависит от поддержки компилятором стандарта с++11 (класс <regex>). \note Полнота и формат поддерживаемых регулярных выражений зависит от поддержки компилятором стандарта с++11 (класс <regex>).
*/ */
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
/* Т.к. в других агрегаторах может тоже встречаться такие же логи, приходится отдельно вести
* учёт подключений (conmap) и подключаться к потокам напрямую, а не к агрегатору
* иначе будет происходить дублирование информации на экране (логи смешиваются от разных агрегаторов)
*/
class LogAgregator: class LogAgregator:
public DebugStream public DebugStream
{ {
...@@ -135,6 +139,7 @@ class LogAgregator: ...@@ -135,6 +139,7 @@ class LogAgregator:
// найти лог.. // найти лог..
std::shared_ptr<DebugStream> getLog( const std::string& logname ); std::shared_ptr<DebugStream> getLog( const std::string& logname );
bool logExist( std::shared_ptr<DebugStream>& l );
struct iLog struct iLog
{ {
...@@ -162,7 +167,7 @@ class LogAgregator: ...@@ -162,7 +167,7 @@ class LogAgregator:
protected: protected:
void logOnEvent( const std::string& s ); void logOnEvent( const std::string& s );
void addLog( std::shared_ptr<DebugStream> l, const std::string& lname ); void addLog( std::shared_ptr<DebugStream> l, const std::string& lname, bool connect );
void addLogAgregator( std::shared_ptr<LogAgregator> la, const std::string& lname ); void addLogAgregator( std::shared_ptr<LogAgregator> la, const std::string& lname );
// поиск лога по составному логу.."agregator/agregator2/.../logname" // поиск лога по составному логу.."agregator/agregator2/.../logname"
...@@ -177,6 +182,9 @@ class LogAgregator: ...@@ -177,6 +182,9 @@ class LogAgregator:
private: private:
typedef std::unordered_map<std::string, std::shared_ptr<DebugStream>> LogMap; typedef std::unordered_map<std::string, std::shared_ptr<DebugStream>> LogMap;
LogMap lmap; LogMap lmap;
typedef std::unordered_map<std::shared_ptr<DebugStream>,sigc::connection> ConnectionMap;
ConnectionMap conmap;
}; };
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
#endif // LogAgregator_H_ #endif // LogAgregator_H_
......
...@@ -54,7 +54,8 @@ std::shared_ptr<DebugStream> LogAgregator::create( const std::string& logname ) ...@@ -54,7 +54,8 @@ std::shared_ptr<DebugStream> LogAgregator::create( const std::string& logname )
auto l = std::make_shared<DebugStream>(); auto l = std::make_shared<DebugStream>();
l->setLogName(logname); l->setLogName(logname);
l->signal_stream_event().connect( sigc::mem_fun(this, &LogAgregator::logOnEvent) ); auto conn = l->signal_stream_event().connect( sigc::mem_fun(this, &LogAgregator::logOnEvent) );
conmap.emplace(l,conn);
lmap[logname] = l; lmap[logname] = l;
return l; return l;
} }
...@@ -66,7 +67,7 @@ void LogAgregator::add( std::shared_ptr<DebugStream> l, const std::string& lname ...@@ -66,7 +67,7 @@ void LogAgregator::add( std::shared_ptr<DebugStream> l, const std::string& lname
if( lag ) if( lag )
addLogAgregator(lag, (lname.empty() ? l->getLogName() : lname) ); addLogAgregator(lag, (lname.empty() ? l->getLogName() : lname) );
else else
addLog(l, (lname.empty() ? l->getLogName() : lname)); addLog(l, (lname.empty() ? l->getLogName() : lname), true);
} }
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
void LogAgregator::add( std::shared_ptr<LogAgregator> loga, const std::string& lname ) void LogAgregator::add( std::shared_ptr<LogAgregator> loga, const std::string& lname )
...@@ -81,33 +82,37 @@ void LogAgregator::addLogAgregator( std::shared_ptr<LogAgregator> la, const std: ...@@ -81,33 +82,37 @@ void LogAgregator::addLogAgregator( std::shared_ptr<LogAgregator> la, const std:
if( i != lmap.end() ) if( i != lmap.end() )
return; return;
addLog(la, lname); auto lst = la->getLogList();
for( auto&& l: lst )
{
auto c = conmap.find(l.log);
if( c == conmap.end() )
{
auto conn = l.log->signal_stream_event().connect( sigc::mem_fun(this, &LogAgregator::logOnEvent) );
conmap.emplace(l.log,conn);
}
}
addLog(la, lname, false);
} }
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
void LogAgregator::addLog( std::shared_ptr<DebugStream> l, const std::string& lname ) void LogAgregator::addLog( std::shared_ptr<DebugStream> l, const std::string& lname, bool connect )
{ {
auto i = lmap.find(lname); auto i = lmap.find(lname);
if( i != lmap.end() ) if( i != lmap.end() )
return; return;
bool have = false; if( connect )
// пока делаем "не оптимальный поиск" / пробегаем по всему списку, зато не храним дополнительный map /
// на то, чтобы не подключаться к одному логу дважды,
// иначе будет дублироваие при выводе потом (на экран)
for( const auto& i : lmap )
{ {
if( i.second == l ) auto c = conmap.find(l);
if( c == conmap.end() )
{ {
have = true; auto conn = l->signal_stream_event().connect( sigc::mem_fun(this, &LogAgregator::logOnEvent) );
break; conmap.emplace(l,conn);
} }
} }
if( !have )
l->signal_stream_event().connect( sigc::mem_fun(this, &LogAgregator::logOnEvent) );
lmap[lname] = l; lmap[lname] = l;
} }
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
...@@ -224,6 +229,25 @@ std::vector<std::string> LogAgregator::splitFirst( const std::string& lname, con ...@@ -224,6 +229,25 @@ std::vector<std::string> LogAgregator::splitFirst( const std::string& lname, con
return std::move(v); return std::move(v);
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
bool LogAgregator::logExist( std::shared_ptr<DebugStream>& log )
{
for( const auto& l: lmap )
{
if( l.second == log )
return true;
bool res = false;
auto ag = dynamic_pointer_cast<LogAgregator>(l.second);
if( ag )
res = ag->logExist(log);
if( res )
return true;
}
return false;
}
// -------------------------------------------------------------------------
std::shared_ptr<DebugStream> LogAgregator::findLog( const std::string& lname ) std::shared_ptr<DebugStream> LogAgregator::findLog( const std::string& lname )
{ {
auto v = splitFirst(lname, sep); auto v = splitFirst(lname, sep);
......
...@@ -132,6 +132,8 @@ void LogReader::sendCommand( const std::string& _addr, ost::tpport_t _port, std: ...@@ -132,6 +132,8 @@ void LogReader::sendCommand( const std::string& _addr, ost::tpport_t _port, std:
if( outTimeout == 0 ) if( outTimeout == 0 )
outTimeout = TIMEOUT_INF; outTimeout = TIMEOUT_INF;
std::string listfilter("");
for( const auto& c : vcmd ) for( const auto& c : vcmd )
{ {
if( c.cmd == LogServerTypes::cmdNOP ) if( c.cmd == LogServerTypes::cmdNOP )
...@@ -175,6 +177,13 @@ void LogReader::sendCommand( const std::string& _addr, ost::tpport_t _port, std: ...@@ -175,6 +177,13 @@ void LogReader::sendCommand( const std::string& _addr, ost::tpport_t _port, std:
continue; continue;
} }
if( c.cmd == LogServerTypes::cmdList )
{
listfilter = c.logfilter;
n=0;
continue;
}
sendCommand(msg, verbose); sendCommand(msg, verbose);
break; break;
} }
...@@ -193,37 +202,31 @@ void LogReader::sendCommand( const std::string& _addr, ost::tpport_t _port, std: ...@@ -193,37 +202,31 @@ void LogReader::sendCommand( const std::string& _addr, ost::tpport_t _port, std:
// после команд.. выводим список текущий.. // после команд.. выводим список текущий..
timeout_t reply_timeout = 4000; // TIMEOUT_INF; timeout_t reply_timeout = 1000; // TIMEOUT_INF;
LogServerTypes::lsMessage msg; LogServerTypes::lsMessage msg;
msg.cmd = LogServerTypes::cmdList; msg.cmd = LogServerTypes::cmdList;
msg.data = 0; msg.data = 0;
msg.setLogName("ALL"); msg.setLogName( (listfilter.empty() ? "ALL" : listfilter) );
sendCommand(msg, verbose); sendCommand(msg, verbose);
// теперь ждём ответ.. // теперь ждём ответ..
try try
{ {
int a = 3; int a = 1;
while( a > 0 && tcp->isPending(ost::Socket::pendingInput, reply_timeout) ) while( a > 0 && tcp->isPending(ost::Socket::pendingInput, reply_timeout) )
{ {
int n = 0; int n = tcp->peek( buf, sizeof(buf) - 1 );
if( n > 0 )
do
{ {
n = tcp->peek( buf, sizeof(buf) - 1 ); tcp->read(buf, n);
buf[n] = '\0';
if( n > 0 )
{
tcp->read(buf, n);
buf[n] = '\0';
log << buf; log << buf;
a--;
}
} }
while( n > 0 );
a--;
} }
// rlog.warn() << "(LogReader): ...wait reply timeout..." << endl; // rlog.warn() << "(LogReader): ...wait reply timeout..." << endl;
......
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