Commit d78fc2e8 authored by Pavel Vainerman's avatar Pavel Vainerman

(uniset-log): Добавил возможность записывать получаемые логи в указанный файл

parent 40c36e29
......@@ -27,8 +27,10 @@ static struct option longopts[] =
{ "rotate", optional_argument, 0, 'r' },
{ "logfilter", required_argument, 0, 'n' },
{ "command-only", no_argument, 0, 'c' },
{ "timeout", required_argument, 0, 'w' },
{ "timeout", required_argument, 0, 't' },
{ "reconnect-delay", required_argument, 0, 'x' },
{ "logfile", required_argument, 0, 'w' },
{ "logfile-truncate", required_argument, 0, 'z' },
{ NULL, 0, 0, 0 }
};
// --------------------------------------------------------------------------
......@@ -39,8 +41,10 @@ static void print_help()
printf("[-i|--iaddr] addr - LogServer ip or hostname.\n");
printf("[-p|--port] port - LogServer port.\n");
printf("[-c|--command-only] - Send command and break. (No read logs).\n");
printf("[-w|--timeout] msec - Timeout for wait data. Default: 0 - endless waiting\n");
printf("[-t|--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");
printf("[-w|--logfile] logfile - Save log to 'logfile'.\n");
printf("[-z|--logfile-truncate] - Truncate log file before write. Use with -w|--logfile \n");
printf("\n");
printf("Commands:\n");
......@@ -76,12 +80,14 @@ int main( int argc, char** argv )
int cmdonly = 0;
timeout_t tout = 0;
timeout_t rdelay = 5000;
string logfile("");
bool logtruncate = false;
try
{
while(1)
{
opt = getopt_long(argc, argv, "chvlf:a:p:i:d:s:n:eorbx:w:", longopts, &optindex);
opt = getopt_long(argc, argv, "chvlf:a:p:i:d:s:n:eorbx:w:zt:", longopts, &optindex);
if( opt == -1 )
break;
......@@ -215,10 +221,18 @@ int main( int argc, char** argv )
rdelay = uni_atoi(optarg);
break;
case 'w':
case 't':
tout = uni_atoi(optarg);
break;
case 'w':
logfile = string(optarg);
break;
case 'z':
logtruncate = true;
break;
case 'v':
verb = 1;
break;
......@@ -242,6 +256,9 @@ int main( int argc, char** argv )
lr.setinTimeout(tout);
lr.setReconnectDelay(rdelay);
if( !logfile.empty() )
lr.log()->logFile(logfile,logtruncate);
if( !vcmd.empty() )
lr.sendCommand(addr, port, vcmd, cmdonly, verb);
......
......@@ -59,7 +59,9 @@ class LogReader
DebugStream::StreamEvent_Signal signal_stream_event();
void setLogLevel( Debug::type );
void setLogLevel( Debug::type t );
inline std::shared_ptr<DebugStream> log(){ return outlog; }
protected:
......@@ -81,7 +83,7 @@ class LogReader
unsigned int readcount = { 0 }; // количество циклов чтения
DebugStream rlog;
DebugStream log; // рабочий лог в который выводиться полученная информация..
std::shared_ptr<DebugStream> outlog; // рабочий лог в который выводиться полученная информация..
DebugStream::StreamEvent_Signal m_logsig;
};
......
......@@ -17,8 +17,10 @@ LogReader::LogReader():
cmdonly(false),
readcount(0)
{
log.level(Debug::ANY);
log.signal_stream_event().connect( sigc::mem_fun(this, &LogReader::logOnEvent) );
outlog = std::make_shared<DebugStream>();
outlog->level(Debug::ANY);
outlog->signal_stream_event().connect( sigc::mem_fun(this, &LogReader::logOnEvent) );
}
// -------------------------------------------------------------------------
......@@ -30,14 +32,13 @@ LogReader::~LogReader()
// -------------------------------------------------------------------------
void LogReader::setLogLevel( Debug::type t )
{
log.level(t);
outlog->level(t);
}
// -------------------------------------------------------------------------
DebugStream::StreamEvent_Signal LogReader::signal_stream_event()
{
return m_logsig;
}
// -------------------------------------------------------------------------
void LogReader::connect( const std::string& addr, ost::tpport_t _port, timeout_t msec )
{
......@@ -223,7 +224,7 @@ void LogReader::sendCommand( const std::string& _addr, ost::tpport_t _port, std:
tcp->read(buf, n);
buf[n] = '\0';
log << buf;
outlog->any(false) << buf;
}
a--;
......@@ -305,7 +306,7 @@ void LogReader::readlogs( const std::string& _addr, ost::tpport_t _port, LogServ
tcp->read(buf, n);
buf[n] = '\0';
log << buf;
outlog->any(false) << buf;
}
else if( n == 0 && readcount <= 0 )
break;
......
......@@ -244,7 +244,7 @@ TEST_CASE("MaxSessions", "[LogServer]" )
r2_thr->join();
}
// --------------------------------------------------------------------------
TEST_CASE("Logagregator regexp", "[LogAgregator]" )
TEST_CASE("LogAgregator regexp", "[LogAgregator]" )
{
auto la = make_shared<LogAgregator>("ROOT");
auto log1 = la->create("log1");
......
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