Commit 1f406d70 authored by Pavel Vainerman's avatar Pavel Vainerman

(LogServer): работа над форматом вывода списка логов

parent 7e0114b5
// --------------------------------------------------------------------------
#include <string>
#include <iomanip>
#include <getopt.h>
#include "Debug.h"
#include "UniSetTypes.h"
......@@ -132,15 +133,25 @@ int main( int argc, char** argv )
auto dlog6 = la3->create("dlog6");
la->add(la3);
for( int i = 0; i < 15; i++ )
{
ostringstream s;
s << i;
auto l = make_shared<LogAgregator>("LongLongNameWith" + s.str());
l->create("dlog1");
l->create("shortdlog2");
l->create("longnamedlog3");
la->add(l);
}
#if 0
cout << la << endl;
cout << "************ " << endl;
auto lst = la->getLogList();
for( const auto& l : lst )
cout << l.name << endl;
la->printLogList(cout);
return 0;
#endif
......
......@@ -51,7 +51,7 @@ void run_test(std::size_t concurrency, int bound, shared_ptr<SharedMemory>& shm
while (num--)
{
int v = shm->getValue(sid);
shm->getValue(sid);
}
};
......
......@@ -157,6 +157,9 @@ class LogAgregator:
static std::vector<std::string> splitFirst( const std::string& lname, const std::string s = "/" );
std::ostream& printLogList( std::ostream& os, const std::string& regexp_str = "" );
static std::ostream& printLogList( std::ostream& os, std::list<iLog>& lst );
protected:
void logOnEvent( const std::string& s );
void addLog( std::shared_ptr<DebugStream> l, const std::string& lname );
......
......@@ -143,14 +143,39 @@ std::shared_ptr<DebugStream> LogAgregator::getLog( const std::string& logname )
return findLog(logname);
}
// -------------------------------------------------------------------------
std::ostream& LogAgregator::printLogList( std::ostream& os, const std::string& regexp_str )
{
std::list<iLog> lst;
if( regexp_str.empty() )
lst = getLogList();
else
lst = getLogList(regexp_str);
}
// -------------------------------------------------------------------------
std::ostream& LogAgregator::printLogList( std::ostream& os, std::list<iLog>& lst )
{
std::string::size_type max_width = 1;
for( const auto& l : lst )
max_width = std::max(max_width, l.name.length() );
for( const auto& l : lst )
os << std::left << setw(max_width) << l.name << std::left << " [ " << Debug::str(l.log->level()) << " ]" << endl;
return os;
}
// -------------------------------------------------------------------------
std::ostream& LogAgregator::printTree( std::ostream& os, const std::string& g_tab )
{
const std::string::size_type tab_width = 15;
ostringstream s;
s << " ." << g_tab;
s << " ." << g_tab;
string s_tab(s.str());
os << g_tab << getLogName() << sep << endl; // << setw(6) << " " << "[ " << Debug::str(DebugStream::level()) << " ]" << endl;
os << std::left << g_tab << getLogName() << sep << endl; // << setw(6) << " " << "[ " << Debug::str(DebugStream::level()) << " ]" << endl;
std::list<std::shared_ptr<DebugStream>> lst;
for( const auto& l : lmap )
......@@ -166,11 +191,9 @@ std::ostream& LogAgregator::printTree( std::ostream& os, const std::string& g_ta
auto ag = dynamic_pointer_cast<LogAgregator>(l);
if( ag )
{
ag->printTree(os, s_tab);
}
else
os << s_tab << l->getLogName() << " [ " << Debug::str(l->level()) << " ]" << endl;
os << s_tab << setw(tab_width) << std::right << l->getLogName() << std::left << " [ " << Debug::str(l->level()) << " ]" << endl;
}
return os;
......@@ -178,7 +201,7 @@ std::ostream& LogAgregator::printTree( std::ostream& os, const std::string& g_ta
// -------------------------------------------------------------------------
std::ostream& operator<<( std::ostream& os, LogAgregator& la )
{
la.printTree(os,"");
la.printTree(os, "");
return os;
}
// -------------------------------------------------------------------------
......
#include <iostream>
#include <iomanip>
#include <memory>
#include <string>
#include <sstream>
......@@ -112,48 +113,30 @@ void LogSession::run()
std::list<LogAgregator::iLog> loglist;
if( !cmdLogName.empty () )
if( alog ) // если у нас "агрегатор", то работаем с его списком потоков
{
if( alog ) // если у нас "агрегатор", то работаем с его списком потоков
{
if( cmdLogName == "ALL" )
loglist = alog->getLogList();
else
loglist = alog->getLogList(cmdLogName);
}
if( cmdLogName.empty() || cmdLogName == "ALL" )
loglist = alog->getLogList();
else
loglist = alog->getLogList(cmdLogName);
}
else
{
if( cmdLogName.empty() || cmdLogName == "ALL" || log->getLogFile() == cmdLogName )
{
if( cmdLogName == "ALL" || log->getLogFile() == cmdLogName )
{
LogAgregator::iLog llog(log, log->getLogName());
loglist.push_back(llog);
}
LogAgregator::iLog llog(log, log->getLogName());
loglist.push_back(llog);
}
}
// это команда по всем логам..
// если команда "вывести список"
// выводим и завершаем работу
if( msg.cmd == LogServerTypes::cmdList )
{
ostringstream s;
s << "List of managed logs:" << endl;
s << "List of managed logs(filter='" << cmdLogName << "'):" << endl;
s << "=====================" << endl;
if( !alog )
{
s << log->getLogName() << endl;
}
else
{
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;
}
LogAgregator::printLogList(s,loglist);
s << "=====================" << endl << endl;
if( isPending(Socket::pendingOutput, cmdTimeout) )
......@@ -162,7 +145,7 @@ void LogSession::run()
tcp()->sync();
}
// по идее вывели список и завершили работу..
// вывели список и завершили работу..
cancelled = true;
disconnect();
return;
......@@ -218,6 +201,38 @@ void LogSession::run()
break;
}
}
// Выводим итоговый получившийся список (с учётом выполненных команд)
ostringstream s;
if( msg.cmd == LogServerTypes::cmdFilterMode )
{
s << "List of managed logs(filter='" << cmdLogName << "'):" << endl;
s << "=====================" << endl;
LogAgregator::printLogList(s,loglist);
s << "=====================" << endl << endl;
}
else
{
s << "List of managed logs:" << endl;
s << "=====================" << endl;
// выводим полный список
if( alog )
{
auto lst = alog->getLogList();
LogAgregator::printLogList(s,lst);
}
else
s << log->getLogName() << " [" << Debug::str(log->level()) << " ]" << endl;
s << "=====================" << endl << endl;
}
if( isPending(Socket::pendingOutput, cmdTimeout) )
{
*tcp() << s.str();
tcp()->sync();
}
}
}
}
......
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