Commit 7e0114b5 authored by Pavel Vainerman's avatar Pavel Vainerman

(LogServer): реализовал поддержку режима чтения только указанных(regexp) логов..…

(LogServer): реализовал поддержку режима чтения только указанных(regexp) логов.. (thank`s за идею hd@nio14) (UniSetTypes): небольшая оптимизация.. (uniset-log): переделал работу с аргументами командной строки (LogServer): сделал для вывода списка возможность задать фильтр..(т.е. выводиться не полный список) И другие мелкие правки: make style
parent de16881f
......@@ -128,7 +128,7 @@ static bool quiet = false;
int main(int argc, char** argv)
{
// std::ios::sync_with_stdio(false);
// std::ios::sync_with_stdio(false);
try
{
......
......@@ -36,7 +36,7 @@ static char* checkArg( int ind, int argc, char* argv[] );
// --------------------------------------------------------------------------
int main( int argc, char** argv )
{
// std::ios::sync_with_stdio(false);
// std::ios::sync_with_stdio(false);
int optindex = 0;
int opt = 0;
int verb = 0;
......
......@@ -97,7 +97,7 @@ static char* checkArg( int ind, int argc, char* argv[] );
int main( int argc, char** argv )
{
// std::ios::sync_with_stdio(false);
// std::ios::sync_with_stdio(false);
Command cmd = cmdNOP;
int optindex = 0;
int opt = 0;
......
......@@ -33,7 +33,7 @@ static void print_help()
// --------------------------------------------------------------------------
int main( int argc, char** argv )
{
// std::ios::sync_with_stdio(false);
// std::ios::sync_with_stdio(false);
int optindex = 0;
int opt = 0;
int verb = 0;
......
......@@ -34,7 +34,7 @@ static void print_help()
// --------------------------------------------------------------------------
int main( int argc, char** argv )
{
// std::ios::sync_with_stdio(false);
// std::ios::sync_with_stdio(false);
int optindex = 0;
int opt = 0;
int verb = 0;
......
......@@ -83,7 +83,7 @@ static char* checkArg( int ind, int argc, char* argv[] );
int main( int argc, char** argv )
{
// std::ios::sync_with_stdio(false);
// std::ios::sync_with_stdio(false);
Command cmd = cmdNOP;
int optindex = 0;
int opt = 0;
......
......@@ -21,7 +21,7 @@ static void short_usage()
// --------------------------------------------------------------------------
int main(int argc, char** argv)
{
// std::ios::sync_with_stdio(false);
// std::ios::sync_with_stdio(false);
try
{
......
......@@ -25,7 +25,7 @@ struct ExtInfo:
// -----------------------------------------------------------------------------
int main( int argc, char** argv )
{
// std::ios::sync_with_stdio(false);
// std::ios::sync_with_stdio(false);
try
{
......
......@@ -9,7 +9,7 @@ using namespace std;
// -----------------------------------------------------------------------------
int main( int argc, const char** argv )
{
// std::ios::sync_with_stdio(false);
// std::ios::sync_with_stdio(false);
try
{
......
......@@ -13,7 +13,7 @@ static void short_usage()
// --------------------------------------------------------------------------
int main(int argc, const char** argv)
{
// std::ios::sync_with_stdio(false);
// std::ios::sync_with_stdio(false);
try
{
......
......@@ -14,6 +14,7 @@ static struct option longopts[] =
{
{ "help", no_argument, 0, 'h' },
{ "verbose", no_argument, 0, 'v' },
{ "filter", required_argument, 0, 'f' },
{ "iaddr", required_argument, 0, 'i' },
{ "port", required_argument, 0, 'p' },
{ "add", required_argument, 0, 'a' },
......@@ -21,9 +22,9 @@ static struct option longopts[] =
{ "set", required_argument, 0, 's' },
{ "off", required_argument, 0, 'o' },
{ "on", required_argument, 0, 'e' },
{ "list", no_argument, 0, 'l' },
{ "rotate", required_argument, 0, 'r' },
{ "logname", required_argument, 0, 'n' },
{ "list", optional_argument, 0, 'l' },
{ "rotate", optional_argument, 0, 'r' },
{ "logfilter", required_argument, 0, 'n' },
{ "command-only", no_argument, 0, 'b' },
{ "timeout", required_argument, 0, 'w' },
{ "reconnect-delay", required_argument, 0, 'x' },
......@@ -36,7 +37,6 @@ static void print_help()
printf("-v, --verbose - Print all messages to stdout\n");
printf("[-i|--iaddr] addr - LogServer ip or hostname.\n");
printf("[-p|--port] port - LogServer port.\n");
printf("[-n|--logname] name - Send command only for 'logname'.\n");
printf("[-b|--command-only] - Send command and break. (No read logs).\n");
printf("[-w|--timeout] msec - Timeout for wait data. Default: 0 - endless waiting\n");
printf("[-x|--reconnect-delay] msec - Pause for repeat connect to LogServer. Default: 5000 msec.\n");
......@@ -44,15 +44,20 @@ static void print_help()
printf("\n");
printf("Commands:\n");
printf("[--add | -a] info,warn,crit,... - Add log levels.\n");
printf("[--del | -d] info,warn,crit,... - Delete log levels.\n");
printf("[--set | -s] info,warn,crit,... - Set log levels.\n");
printf("--off, -o - Off the write log file (if enabled).\n");
printf("--on, -e - On(enable) the write log file (if before disabled).\n");
printf("--rotate, -r - rotate log file.\n");
printf("--list, -l - List of managed logs.\n");
printf("[--add | -a] info,warn,crit,... [logfilter] - Add log levels.\n");
printf("[--del | -d] info,warn,crit,... [logfilter] - Delete log levels.\n");
printf("[--set | -s] info,warn,crit,... [logfilter] - Set log levels.\n");
printf("--off, -o [logfilter] - Off the write log file (if enabled).\n");
printf("--on, -e [logfilter] - On(enable) the write log file (if before disabled).\n");
printf("--rotate, -r [logfilter] - rotate log file.\n");
printf("--list, -l [logfilter] - List of managed logs.\n");
printf("--filter, -f logfilter - ('filter mode'). View log only from 'logfilter'(regexp)\n");
printf("\n");
printf("Note: 'logfilter' - regexp for name of log. Default: ALL logs.\n");
}
// --------------------------------------------------------------------------
static char* checkArg( int i, int argc, char* argv[] );
// --------------------------------------------------------------------------
int main( int argc, char** argv )
{
// std::ios::sync_with_stdio(false); // нельзя отключать.. тогда "обмен с сервером" рассинхронизируется
......@@ -67,13 +72,13 @@ int main( int argc, char** argv )
int data = 0;
string sdata("");
int cmdonly = 0;
string logname("");
string logfilter("");
timeout_t tout = 0;
timeout_t rdelay = 5000;
try
{
while( (opt = getopt_long(argc, argv, "hvla:p:i:d:s:n:eorbx:w:", longopts, &optindex)) != -1 )
while( (opt = getopt_long(argc, argv, "hvlf:a:p:i:d:s:n:eorbx:w:", longopts, &optindex)) != -1 )
{
switch (opt)
{
......@@ -85,6 +90,12 @@ int main( int argc, char** argv )
{
cmd = LogServerTypes::cmdAddLevel;
sdata = string(optarg);
char* arg2 = checkArg(optind, argc, argv);
if( arg2 )
logfilter = string(arg2);
else
logfilter = "";
}
break;
......@@ -92,6 +103,12 @@ int main( int argc, char** argv )
{
cmd = LogServerTypes::cmdDelLevel;
sdata = string(optarg);
char* arg2 = checkArg(optind, argc, argv);
if( arg2 )
logfilter = string(arg2);
else
logfilter = "";
}
break;
......@@ -99,34 +116,75 @@ int main( int argc, char** argv )
{
cmd = LogServerTypes::cmdSetLevel;
sdata = string(optarg);
char* arg2 = checkArg(optind, argc, argv);
if( arg2 )
logfilter = string(arg2);
else
logfilter = "";
}
break;
case 'l':
{
cmd = LogServerTypes::cmdList;
cmdonly = 1;
break;
char* arg2 = checkArg(optind, argc, argv);
if( arg2 )
logfilter = string(arg2);
else
logfilter = "";
}
break;
case 'o':
{
cmd = LogServerTypes::cmdOffLogFile;
break;
char* arg2 = checkArg(optind, argc, argv);
if( arg2 )
logfilter = string(arg2);
else
logfilter = "";
}
break;
case 'f':
{
cmd = LogServerTypes::cmdFilterMode;
logfilter = string(optarg);
}
break;
case 'e':
{
cmd = LogServerTypes::cmdOnLogFile;
break;
char* arg2 = checkArg(optind, argc, argv);
if( arg2 )
logfilter = string(arg2);
else
logfilter = "";
}
break;
case 'r':
{
cmd = LogServerTypes::cmdRotate;
break;
char* arg2 = checkArg(optind, argc, argv);
if( arg2 )
logfilter = string(arg2);
else
logfilter = "";
}
break;
case 'i':
addr = string(optarg);
break;
case 'n':
logname = string(optarg);
break;
case 'b':
cmdonly = 1;
break;
......@@ -149,7 +207,7 @@ int main( int argc, char** argv )
case '?':
default:
printf("? argumnet\n");
printf("Unknown argumnet\n");
return 0;
}
}
......@@ -174,7 +232,7 @@ int main( int argc, char** argv )
cout << "SEND COMMAND: '" << (LogServerTypes::Command)cmd << " data='" << sdata << "'(" << (int)data << ")" << endl;
}
lr.readlogs( addr, port, (LogServerTypes::Command)cmd, data, logname, verb );
lr.readlogs( addr, port, (LogServerTypes::Command)cmd, data, logfilter, verb );
}
catch( const SystemError& err )
{
......@@ -192,3 +250,11 @@ int main( int argc, char** argv )
return 0;
}
// --------------------------------------------------------------------------
char* checkArg( int i, int argc, char* argv[] )
{
if( i < argc && (argv[i])[0] != '-' )
return argv[i];
return 0;
}
// --------------------------------------------------------------------------
......@@ -114,7 +114,7 @@ int main( int argc, char** argv )
}
auto la2 = make_shared<LogAgregator>("la2");
auto dlog3 = la2->create("dlog3");
auto dlog4 = la2->create("dlog4");
la->add(la2);
......@@ -127,18 +127,20 @@ int main( int argc, char** argv )
}
auto la3 = make_shared<LogAgregator>("la3");
auto dlog5 = la3->create("dlog5");
auto dlog6 = la3->create("dlog6");
la->add(la3);
#if 0
cout << la << endl;
cout << "************ " << endl;
auto lst = la->getLogList();
for( const auto& l: lst )
for( const auto& l : lst )
cout << l.name << endl;
return 0;
#endif
......
......@@ -40,13 +40,13 @@ void TestGen::timerInfo( const TimerMessage* tm )
{
if( tm->id == 1 )
{
askTimer(1,0);
askTimer(2,3000);
askTimer(1, 0);
askTimer(2, 3000);
}
else if( tm->id == 2 )
{
askTimer(1,2000);
askTimer(2,0);
askTimer(1, 2000);
askTimer(2, 0);
}
}
// -----------------------------------------------------------------------------
......@@ -58,6 +58,6 @@ void TestGen::sigterm( int signo )
void TestGen::sysCommand( const UniSetTypes::SystemMessage* sm )
{
if( sm->command == SystemMessage::StartUp )
askTimer(1,2000);
askTimer(1, 2000);
}
// -----------------------------------------------------------------------------
......@@ -13,7 +13,7 @@
Name: libuniset2
Version: 2.1
Release: alt3
Release: alt4
Summary: UniSet - library for building distributed industrial control systems
......@@ -455,6 +455,10 @@ mv -f %buildroot%python_sitelibdir_noarch/* %buildroot%python_sitelibdir/%oname
# ..
%changelog
* Mon Jun 01 2015 Pavel Vainerman <pv@altlinux.ru> 2.1-alt4
- (LogServer): added suppport "filter mode"
- (LogAgregator): refactoring, change show loglist format
* Sun May 31 2015 Pavel Vainerman <pv@altlinux.ru> 2.1-alt3
- (LogAgregator):
- added support agregator hierarchy
......
......@@ -62,7 +62,7 @@ IOControl::IOControl( UniSetTypes::ObjectId id, UniSetTypes::ObjectId icID,
iolog->setLogName(myname);
conf->initLogStream(iolog, prefix + "-log");
loga = make_shared<LogAgregator>(myname+"-loga");
loga = make_shared<LogAgregator>(myname + "-loga");
loga->add(iolog);
loga->add(ulog());
loga->add(dlog());
......
......@@ -51,7 +51,7 @@ MBExchange::MBExchange( UniSetTypes::ObjectId objId, UniSetTypes::ObjectId shmId
mblog->setLogName(myname);
conf->initLogStream(mblog, prefix + "-log");
loga = make_shared<LogAgregator>(myname+"-loga");
loga = make_shared<LogAgregator>(myname + "-loga");
loga->add(mblog);
loga->add(ulog());
loga->add(dlog());
......
......@@ -100,8 +100,9 @@ std::shared_ptr<ModbusClient> MBTCPMaster::initMB( bool reopen )
mbinfo << myname << "(init): ipaddr=" << iaddr << " port=" << port << endl;
auto l = loga->create(myname+"-exchangelog");
auto l = loga->create(myname + "-exchangelog");
mbtcp->setLog(l);
if( ic )
ic->logAgregator()->add(loga);
}
......
......@@ -104,6 +104,7 @@ MBTCPMultiMaster::MBTCPMultiMaster( UniSetTypes::ObjectId objId, UniSetTypes::Ob
auto l = loga->create(sinf.myname);
sinf.mbtcp->setLog(l);
if( ic )
ic->logAgregator()->add(loga);
......
......@@ -131,8 +131,9 @@ std::shared_ptr<ModbusClient> RTUExchange::initMB( bool reopen )
if( defSpeed != ComPort::ComSpeed0 )
mbrtu->setSpeed(defSpeed);
auto l = loga->create(myname+"-exchangelog");
auto l = loga->create(myname + "-exchangelog");
mbrtu->setLog(l);
if( ic )
ic->logAgregator()->add(loga);
......
......@@ -39,7 +39,7 @@ MBSlave::MBSlave( UniSetTypes::ObjectId objId, UniSetTypes::ObjectId shmId, cons
mblog->setLogName(myname);
conf->initLogStream(mblog, prefix + "-log");
loga = make_shared<LogAgregator>(myname+"-loga");
loga = make_shared<LogAgregator>(myname + "-loga");
loga->add(mblog);
loga->add(ulog());
loga->add(dlog());
......
......@@ -156,7 +156,7 @@ void MBTCPMultiSlave::execute_tcp()
return;
}
auto l = loga->create(myname+"-exchangelog");
auto l = loga->create(myname + "-exchangelog");
sslot->setLog(l);
for( auto && i : cmap )
......
......@@ -28,7 +28,7 @@ UNetExchange::UNetExchange( UniSetTypes::ObjectId objId, UniSetTypes::ObjectId s
unetlog->setLogName(myname);
conf->initLogStream(unetlog, prefix + "-log");
loga = make_shared<LogAgregator>(myname+"-loga");
loga = make_shared<LogAgregator>(myname + "-loga");
loga->add(unetlog);
loga->add(ulog());
loga->add(dlog());
......
......@@ -137,16 +137,28 @@ class DebugStream : public std::ostream
}
// имя лог файла можно установить отдельно, но не вклчать запись..
inline void setLogFile( const std::string& n ){ fname = n; }
inline void setLogFile( const std::string& n )
{
fname = n;
}
// включена ли запись лог-файла
inline bool isOnLogFile(){ return isWriteLogFile; }
inline bool isOnLogFile()
{
return isWriteLogFile;
}
// включить запись лог файла
inline void onLogFile( bool truncate=false ){ logFile(fname,truncate); }
inline void onLogFile( bool truncate = false )
{
logFile(fname, truncate);
}
// отключить запись логфайла
inline void offLogFile(){ logFile(""); }
inline void offLogFile()
{
logFile("");
}
/// Returns true if t is part of the current debug level.
inline bool debugging(Debug::type t = Debug::ANY) const
......
......@@ -3,6 +3,7 @@
// -------------------------------------------------------------------------
#include <string>
#include <memory>
#include <regex>
#include <list>
#include <vector>
#include <unordered_map>
......@@ -111,17 +112,17 @@ class LogAgregator:
{
public:
const std::string sep= {"/"}; /*< раздедитель для имён подчинённых агрегаторов */
const std::string sep = {"/"}; /*< раздедитель для имён подчинённых агрегаторов */
explicit LogAgregator( const std::string& name, Debug::type t );
explicit LogAgregator( const std::string& name="" );
explicit LogAgregator( const std::string& name = "" );
virtual ~LogAgregator();
virtual void logFile( const std::string& f, bool truncate = false ) override;
void add( std::shared_ptr<LogAgregator> log, const std::string& lname="" );
void add( std::shared_ptr<DebugStream> log, const std::string& lname="" );
void add( std::shared_ptr<LogAgregator> log, const std::string& lname = "" );
void add( std::shared_ptr<DebugStream> log, const std::string& lname = "" );
std::shared_ptr<DebugStream> create( const std::string& logname );
......@@ -132,16 +133,12 @@ class LogAgregator:
void offLogFile( const std::string& logname );
void onLogFile( const std::string& logname );
// найти лог..
std::shared_ptr<DebugStream> getLog( const std::string& logname );
friend std::ostream& operator<<(std::ostream& os, LogAgregator& la );
friend std::ostream& operator<<(std::ostream& os, std::shared_ptr<LogAgregator> la );
static std::vector<std::string> split_first( const std::string& lname, const std::string s = "/" );
struct iLog
{
iLog( std::shared_ptr<DebugStream>& l, const std::string& nm ):log(l),name(nm){}
iLog( std::shared_ptr<DebugStream>& l, const std::string& nm ): log(l), name(nm) {}
std::shared_ptr<DebugStream> log;
std::string name;
......@@ -155,6 +152,11 @@ class LogAgregator:
std::list<iLog> getLogList();
std::list<iLog> getLogList( const std::string& regexp_str );
friend std::ostream& operator<<(std::ostream& os, LogAgregator& la );
friend std::ostream& operator<<(std::ostream& os, std::shared_ptr<LogAgregator> la );
static std::vector<std::string> splitFirst( const std::string& lname, const std::string s = "/" );
protected:
void logOnEvent( const std::string& s );
void addLog( std::shared_ptr<DebugStream> l, const std::string& lname );
......@@ -164,13 +166,13 @@ class LogAgregator:
std::shared_ptr<DebugStream> findLog( const std::string& lname );
// вывод в виде "дерева"
std::ostream& print_tree(std::ostream& os, const std::string& g_tab="");
std::ostream& printTree(std::ostream& os, const std::string& g_tab = "");
// получить список с именами (длинными) и с указателями на логи
std::list<iLog> makeLogNameList( const std::string& prefix );
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;
};
// -------------------------------------------------------------------------
......
......@@ -17,7 +17,8 @@ namespace LogServerTypes
cmdRotate, /*!< пересоздать файл с логами */
cmdOffLogFile, /*!< отключить запись файла логов (если включена) */
cmdOnLogFile, /*!< включить запись файла логов (если была отключена) */
cmdList /*!< вывести список контролируемых логов */
cmdList, /*!< вывести список контролируемых логов */
cmdFilterMode /*!< включить режим работы "фильтр" - вывод только от интересующих логов, заданных в lognmae (regexp) */
// cmdSetLogFile
};
......@@ -33,7 +34,7 @@ namespace LogServerTypes
Command cmd;
unsigned int data;
static const size_t MAXLOGNAME = 20;
static const size_t MAXLOGNAME = 30;
char logname[MAXLOGNAME + 1]; // +1 reserverd for '\0'
void setLogName( const std::string& name );
......
......@@ -68,6 +68,7 @@ class LogSession:
std::string caddr;
std::shared_ptr<DebugStream> log;
std::shared_ptr<LogAgregator> alog;
sigc::connection conn;
// PassiveTimer ptSessionTimeout;
FinalSlot slFin;
......
#include <memory>
#include <iomanip>
#include <regex>
#include <sstream>
#include "DebugExtBuf.h"
#include "LogAgregator.h"
......@@ -8,7 +7,7 @@
using namespace std;
// -------------------------------------------------------------------------
LogAgregator::LogAgregator( const std::string& name ):
LogAgregator(name,Debug::ANY)
LogAgregator(name, Debug::ANY)
{
}
// ------------------------------------------------------------------------
......@@ -63,43 +62,26 @@ std::shared_ptr<DebugStream> LogAgregator::create( const std::string& logname )
void LogAgregator::add( std::shared_ptr<DebugStream> l, const std::string& lname )
{
auto lag = std::dynamic_pointer_cast<LogAgregator>(l);
if( lag )
addLogAgregator(lag, (lname.empty() ? l->getLogName(): lname) );
addLogAgregator(lag, (lname.empty() ? l->getLogName() : lname) );
else
addLog(l,(lname.empty() ? l->getLogName(): lname));
addLog(l, (lname.empty() ? l->getLogName() : lname));
}
// ------------------------------------------------------------------------
void LogAgregator::add( std::shared_ptr<LogAgregator> loga, const std::string& lname )
{
addLogAgregator(loga, (lname.empty() ? loga->getLogName(): lname) );
addLogAgregator(loga, (lname.empty() ? loga->getLogName() : lname) );
}
// -------------------------------------------------------------------------
void LogAgregator::addLogAgregator( std::shared_ptr<LogAgregator> la, const std::string& lname )
{
auto i = lmap.find(lname);
if( i != lmap.end() )
return;
addLog(la,lname);
#if 0
auto lst = la->getLogList();
for( auto&& l: lst )
{
auto lag = std::dynamic_pointer_cast<LogAgregator>(l.log);
if( lag )
{
std::ostringstream s;
s << lname << sep << lag->getLogName();
addLogAgregator(lag,s.str()); // рекурсия..
}
else
{
std::ostringstream s;
s << lname << sep << l.log->getLogName();
addLog(l.log,s.str());
}
}
#endif
addLog(la, lname);
}
// ------------------------------------------------------------------------
void LogAgregator::addLog( std::shared_ptr<DebugStream> l, const std::string& lname )
......@@ -161,7 +143,7 @@ std::shared_ptr<DebugStream> LogAgregator::getLog( const std::string& logname )
return findLog(logname);
}
// -------------------------------------------------------------------------
std::ostream& LogAgregator::print_tree( std::ostream& os, const std::string& g_tab )
std::ostream& LogAgregator::printTree( std::ostream& os, const std::string& g_tab )
{
ostringstream s;
s << " ." << g_tab;
......@@ -170,17 +152,22 @@ std::ostream& LogAgregator::print_tree( std::ostream& os, const std::string& g_t
os << g_tab << getLogName() << sep << endl; // << setw(6) << " " << "[ " << Debug::str(DebugStream::level()) << " ]" << endl;
std::list<std::shared_ptr<DebugStream>> lst;
for( const auto& l: lmap )
for( const auto& l : lmap )
lst.push_back(l.second);
lst.sort([](const std::shared_ptr<DebugStream>& a, const std::shared_ptr<DebugStream>& b) { return a->getLogName() < b->getLogName(); });
lst.sort([](const std::shared_ptr<DebugStream>& a, const std::shared_ptr<DebugStream>& b)
{
return a->getLogName() < b->getLogName();
});
for( auto&& l: lst )
for( auto && l : lst )
{
auto ag = dynamic_pointer_cast<LogAgregator>(l);
if( ag )
{
ag->print_tree(os,s_tab);
ag->printTree(os, s_tab);
}
else
os << s_tab << l->getLogName() << " [ " << Debug::str(l->level()) << " ]" << endl;
......@@ -191,7 +178,7 @@ std::ostream& LogAgregator::print_tree( std::ostream& os, const std::string& g_t
// -------------------------------------------------------------------------
std::ostream& operator<<( std::ostream& os, LogAgregator& la )
{
la.print_tree(os);
la.printTree(os,"");
return os;
}
// -------------------------------------------------------------------------
......@@ -200,26 +187,28 @@ std::ostream& operator<<(std::ostream& os, std::shared_ptr<LogAgregator> la )
return os << *(la.get());
}
// -------------------------------------------------------------------------
std::vector<std::string> LogAgregator::split_first( const std::string& lname, const std::string s )
std::vector<std::string> LogAgregator::splitFirst( const std::string& lname, const std::string s )
{
string::size_type pos = lname.find(s);
if( pos == string::npos )
{
vector<string> v{lname,""};
vector<string> v{lname, ""};
return std::move(v);
}
vector<string> v={lname.substr(0, pos), lname.substr(pos+1, lname.length()) };
vector<string> v = {lname.substr(0, pos), lname.substr(pos + 1, lname.length()) };
return std::move(v);
}
// -------------------------------------------------------------------------
std::shared_ptr<DebugStream> LogAgregator::findLog( const std::string& lname )
{
auto v = split_first(lname,sep);
auto v = splitFirst(lname, sep);
if( v[1].empty() )
{
auto l = lmap.find(lname);
if( l == lmap.end() )
return nullptr;
......@@ -227,10 +216,12 @@ std::shared_ptr<DebugStream> LogAgregator::findLog( const std::string& lname )
}
auto l = lmap.find(v[0]);
if( l == lmap.end() )
return nullptr;
auto ag = dynamic_pointer_cast<LogAgregator>(l->second);
if( !ag )
return l->second;
......@@ -246,7 +237,8 @@ std::list<LogAgregator::iLog> LogAgregator::getLogList( const std::string& regex
std::regex rule(regex_str);
auto lst = getLogList();
for( const auto& i: lst )
for( const auto& i : lst )
{
if( std::regex_match(i.name, rule) )
{
......@@ -265,7 +257,10 @@ std::list<LogAgregator::iLog> LogAgregator::getLogList( const std::string& regex
std::list<LogAgregator::iLog> LogAgregator::getLogList()
{
std::list<LogAgregator::iLog> lst = makeLogNameList("");
lst.sort([](const LogAgregator::iLog& a, const LogAgregator::iLog& b) { return a.name < b.name; });
lst.sort([](const LogAgregator::iLog & a, const LogAgregator::iLog & b)
{
return a.name < b.name;
});
return std::move(lst);
}
// -------------------------------------------------------------------------
......@@ -278,17 +273,18 @@ std::list<LogAgregator::iLog> LogAgregator::makeLogNameList( const std::string&
string p(s.str());
string p2(p+sep);
string p2(p + sep);
for( auto&& l : lmap )
for( auto && l : lmap )
{
auto ag = dynamic_pointer_cast<LogAgregator>(l.second);
if( ag )
lst.splice(lst.end(), ag->makeLogNameList(p2));
else
{
std::string nm(p2+l.second->getLogName());
LogAgregator::iLog il(l.second,std::move(nm) );
std::string nm(p2 + l.second->getLogName());
LogAgregator::iLog il(l.second, std::move(nm) );
lst.push_back( std::move(il) );
}
}
......@@ -299,6 +295,7 @@ std::list<LogAgregator::iLog> LogAgregator::makeLogNameList( const std::string&
void LogAgregator::offLogFile( const std::string& logname )
{
auto l = findLog(logname);
if( l )
l->offLogFile();
}
......@@ -306,7 +303,9 @@ void LogAgregator::offLogFile( const std::string& logname )
void LogAgregator::onLogFile( const std::string& logname )
{
auto l = findLog(logname);
if( l )
l->onLogFile();
}
// -------------------------------------------------------------------------
......@@ -205,8 +205,8 @@ void LogReader::readlogs( const std::string& _addr, ost::tpport_t _port, LogServ
log << buf;
// if( msg.cmd == LogServerTypes::cmdList )
// break;
// if( msg.cmd == LogServerTypes::cmdList )
// break;
}
else
break;
......
......@@ -28,6 +28,9 @@ std::ostream& LogServerTypes::operator<<(std::ostream& os, LogServerTypes::Comma
case LogServerTypes::cmdList:
return os << "cmdList";
case LogServerTypes::cmdFilterMode:
return os << "cmdFilterMode";
default:
return os << "Unknown";
}
......
......@@ -46,11 +46,12 @@ LogSession::LogSession( ost::TCPSocket& server, std::shared_ptr<DebugStream>& _l
//slog.addLevel(Debug::ANY);
if( log )
log->signal_stream_event().connect( sigc::mem_fun(this, &LogSession::logOnEvent) );
conn = log->signal_stream_event().connect( sigc::mem_fun(this, &LogSession::logOnEvent) );
else
slog.crit() << "LOG NULL!!" << endl;
auto ag = dynamic_pointer_cast<LogAgregator>(log);
if( ag )
alog = ag;
}
......@@ -124,7 +125,7 @@ void LogSession::run()
{
if( cmdLogName == "ALL" || log->getLogFile() == cmdLogName )
{
LogAgregator::iLog llog(log,log->getLogName());
LogAgregator::iLog llog(log, log->getLogName());
loglist.push_back(llog);
}
}
......@@ -136,14 +137,23 @@ void LogSession::run()
ostringstream s;
s << "List of managed logs:" << endl;
s << "=====================" << endl;
if( !alog )
{
s << log->getLogName() << endl;
}
else
{
s << alog << endl;
if( !cmdLogName.empty() )
{
auto lst = alog->getLogList(cmdLogName);
for( const auto& l: lst )
s << l.name << " [ " << Debug::str(l.log->level()) << " ]" << endl;
}
else
s << alog << endl;
}
s << "=====================" << endl << endl;
if( isPending(Socket::pendingOutput, cmdTimeout) )
......@@ -158,8 +168,15 @@ void LogSession::run()
return;
}
if( msg.cmd == LogServerTypes::cmdFilterMode )
{
// отлючаем старый обработчик
if( conn )
conn.disconnect();
}
// обрабатываем команды только если нашли подходящие логи
for( auto&& l : loglist )
for( auto && l : loglist )
{
// Обработка команд..
// \warning Работа с логом ведётся без mutex-а, хотя он разделяется отдельными потоками
......@@ -179,18 +196,22 @@ void LogSession::run()
case LogServerTypes::cmdRotate:
l.log->onLogFile(true);
break;
break;
case LogServerTypes::cmdList: // обработали выше (в начале)
break;
break;
case LogServerTypes::cmdOffLogFile:
l.log->offLogFile();
break;
break;
case LogServerTypes::cmdOnLogFile:
l.log->onLogFile();
break;
break;
case LogServerTypes::cmdFilterMode:
l.log->signal_stream_event().connect( sigc::mem_fun(this, &LogSession::logOnEvent) );
break;
default:
slog.warn() << peername << "(run): Unknown command '" << msg.cmd << "'" << endl;
......
......@@ -213,7 +213,7 @@ UniSetTypes::IDList UniSetTypes::explode( const string& str, char sep )
}
while( pos != string::npos );
return l;
return std::move(l);
}
// -------------------------------------------------------------------------
std::vector<std::string> UniSetTypes::explode_str( const string& str, char sep )
......@@ -236,7 +236,7 @@ std::vector<std::string> UniSetTypes::explode_str( const string& str, char sep )
}
while( pos != string::npos );
return v;
return std::move(v);
}
// ------------------------------------------------------------------------------------------
bool UniSetTypes::is_digit( const std::string& s )
......
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