Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
uniset2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UniSet project repositories
uniset2
Commits
42b6d296
Commit
42b6d296
authored
Jun 29, 2017
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(LogReader): сделал возможность задавать фильтр на выводимый тест (grep)
parent
dbed50d4
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
57 additions
and
7 deletions
+57
-7
log.cc
Utilities/ULog/log.cc
+12
-4
libuniset2.spec
conf/libuniset2.spec
+2
-0
LogReader.h
include/LogReader.h
+7
-1
LogAgregator.cc
src/Log/LogAgregator.cc
+1
-1
LogReader.cc
src/Log/LogReader.cc
+35
-1
No files found.
Utilities/ULog/log.cc
View file @
42b6d296
...
...
@@ -25,7 +25,7 @@ static struct option longopts[] =
{
"off"
,
required_argument
,
0
,
'o'
},
{
"on"
,
required_argument
,
0
,
'e'
},
{
"save-loglevels"
,
required_argument
,
0
,
'u'
},
{
"restore-loglevels"
,
required_argument
,
0
,
'
g
'
},
{
"restore-loglevels"
,
required_argument
,
0
,
'
y
'
},
{
"view-default-loglevels"
,
required_argument
,
0
,
'b'
},
{
"list"
,
optional_argument
,
0
,
'l'
},
{
"rotate"
,
optional_argument
,
0
,
'r'
},
...
...
@@ -35,6 +35,7 @@ static struct option longopts[] =
{
"reconnect-delay"
,
required_argument
,
0
,
'x'
},
{
"logfile"
,
required_argument
,
0
,
'w'
},
{
"logfile-truncate"
,
required_argument
,
0
,
'z'
},
{
"grep"
,
required_argument
,
0
,
'g'
},
{
NULL
,
0
,
0
,
0
}
};
// --------------------------------------------------------------------------
...
...
@@ -60,10 +61,11 @@ static void print_help()
printf
(
"[-e | --on] [logfilter] - On(enable) the write log file (if before disabled).
\n
"
);
printf
(
"[-r | --rotate] [logfilter] - rotate log file.
\n
"
);
printf
(
"[-u | --save-loglevels] [logfilter] - save log levels (disable restore after disconnected).
\n
"
);
printf
(
"[-
g
| --restore-loglevels] [logfilter] - restore default log levels.
\n
"
);
printf
(
"[-
y
| --restore-loglevels] [logfilter] - restore default log levels.
\n
"
);
printf
(
"[-b | --view-default-loglevels] [logfilter] - list of default log levels.
\n
"
);
printf
(
"[-l | --list] [logfilter] - List of managed logs.
\n
"
);
printf
(
"[-g | --grep pattern - Print lines matching a pattern (c++ regexp)
\n
"
);
printf
(
"[-f | --filter] logfilter - ('filter mode'). View log only from 'logfilter'(regexp)
\n
"
);
printf
(
"
\n
"
);
printf
(
"Note: 'logfilter' - regexp for name of log. Default: ALL logs.
\n
"
);
...
...
@@ -90,12 +92,13 @@ int main( int argc, char** argv )
timeout_t
rdelay
=
8000
;
string
logfile
(
""
);
bool
logtruncate
=
false
;
std
::
string
textfilter
(
""
);
try
{
while
(
1
)
{
opt
=
getopt_long
(
argc
,
argv
,
"chvlf:a:p:i:d:s:n:eorbx:w:zt:g
ub
"
,
longopts
,
&
optindex
);
opt
=
getopt_long
(
argc
,
argv
,
"chvlf:a:p:i:d:s:n:eorbx:w:zt:g
:uby:
"
,
longopts
,
&
optindex
);
if
(
opt
==
-
1
)
break
;
...
...
@@ -187,7 +190,7 @@ int main( int argc, char** argv )
}
break
;
case
'
g
'
:
// --restore-loglevels
case
'
y
'
:
// --restore-loglevels
{
LogServerTypes
::
Command
cmd
=
LogServerTypes
::
cmdRestoreLogLevel
;
std
::
string
filter
(
""
);
...
...
@@ -277,6 +280,10 @@ int main( int argc, char** argv )
logfile
=
string
(
optarg
);
break
;
case
'g'
:
textfilter
=
string
(
optarg
);
break
;
case
'z'
:
logtruncate
=
true
;
break
;
...
...
@@ -303,6 +310,7 @@ int main( int argc, char** argv )
lr
.
setCommandOnlyMode
(
cmdonly
);
lr
.
setinTimeout
(
tout
);
lr
.
setReconnectDelay
(
rdelay
);
lr
.
setTextFilter
(
textfilter
);
if
(
!
logfile
.
empty
()
)
lr
.
log
()
->
logFile
(
logfile
,
logtruncate
);
...
...
conf/libuniset2.spec
View file @
42b6d296
...
...
@@ -506,6 +506,8 @@ rm -f %buildroot%_libdir/*.la
%exclude %_pkgconfigdir/libUniSet2.pc
# history of current unpublished changes
- (LogReader): add '--grep' mode
- minor fixes
%changelog
* Wed Jun 28 2017 Pavel Vainerman <pv@altlinux.ru> 2.6-alt36
...
...
include/LogReader.h
View file @
42b6d296
...
...
@@ -75,6 +75,11 @@ namespace uniset
reconDelay
=
msec
;
}
inline
void
setTextFilter
(
const
std
::
string
&
f
)
{
textfilter
=
f
;
}
DebugStream
::
StreamEvent_Signal
signal_stream_event
();
void
setLogLevel
(
Debug
::
type
t
);
...
...
@@ -100,7 +105,8 @@ namespace uniset
std
::
string
iaddr
=
{
""
};
int
port
=
{
0
};
bool
cmdonly
{
false
};
unsigned
int
readcount
=
{
0
};
// количество циклов чтения
size_t
readcount
=
{
0
};
// количество циклов чтения
std
::
string
textfilter
=
{
""
};
DebugStream
rlog
;
std
::
shared_ptr
<
DebugStream
>
outlog
;
// рабочий лог в который выводиться полученная информация..
...
...
src/Log/LogAgregator.cc
View file @
42b6d296
...
...
@@ -315,7 +315,7 @@ namespace uniset
for
(
const
auto
&
i
:
lst
)
{
if
(
std
::
regex_
mat
ch
(
i
.
name
,
rule
)
)
if
(
std
::
regex_
sear
ch
(
i
.
name
,
rule
)
)
{
l
.
push_back
(
i
);
}
...
...
src/Log/LogReader.cc
View file @
42b6d296
...
...
@@ -19,6 +19,7 @@
#include <Poco/Net/NetException.h>
#include <iostream>
#include <sstream>
#include <regex>
#include "PassiveTimer.h"
#include "Exceptions.h"
#include "LogReader.h"
...
...
@@ -301,6 +302,8 @@ void LogReader::readlogs( const std::string& _addr, int _port, LogServerTypes::C
bool
send_ok
=
cmd
==
LogServerTypes
::
cmdNOP
?
true
:
false
;
std
::
regex
rule
(
textfilter
);
while
(
rcount
>
0
)
{
try
...
...
@@ -328,6 +331,10 @@ void LogReader::readlogs( const std::string& _addr, int _port, LogServerTypes::C
send_ok
=
true
;
}
// Если мы работаем с текстовым фильтром
// то надо читать построчно..
ostringstream
line
;
while
(
tcp
->
poll
(
UniSetTimer
::
millisecToPoco
(
inTimeout
),
Poco
::
Net
::
Socket
::
SELECT_READ
)
)
{
ssize_t
n
=
tcp
->
available
();
...
...
@@ -337,7 +344,34 @@ void LogReader::readlogs( const std::string& _addr, int _port, LogServerTypes::C
tcp
->
receiveBytes
(
buf
,
n
);
buf
[
n
]
=
'\0'
;
outlog
->
any
(
false
)
<<
buf
;
if
(
textfilter
.
empty
()
)
{
outlog
->
any
(
false
)
<<
buf
;
}
else
{
// Всё это пока не оптимально,
// но мы ведь и не спешим..
for
(
ssize_t
i
=
0
;
i
<
n
;
i
++
)
{
// пока не встретили конец строки
// наполняем line..
if
(
buf
[
i
]
!=
'\n'
)
{
line
<<
buf
[
i
];
continue
;
}
line
<<
endl
;
std
::
string
s
(
line
.
str
());
if
(
std
::
regex_search
(
s
,
rule
)
)
outlog
->
any
(
false
)
<<
s
;
line
.
str
(
""
);
}
}
}
else
if
(
n
==
0
&&
readcount
<=
0
)
break
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment