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
d78fc2e8
Commit
d78fc2e8
authored
Feb 28, 2016
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(uniset-log): Добавил возможность записывать получаемые логи в указанный файл
parent
40c36e29
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
13 deletions
+33
-13
log.cc
Utilities/ULog/log.cc
+21
-4
LogReader.h
include/LogReader.h
+4
-2
LogReader.cc
src/Log/LogReader.cc
+7
-6
test_logserver.cc
tests/test_logserver.cc
+1
-1
No files found.
Utilities/ULog/log.cc
View file @
d78fc2e8
...
...
@@ -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
);
...
...
include/LogReader.h
View file @
d78fc2e8
...
...
@@ -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
>
out
log
;
// рабочий лог в который выводиться полученная информация..
DebugStream
::
StreamEvent_Signal
m_logsig
;
};
...
...
src/Log/LogReader.cc
View file @
d78fc2e8
...
...
@@ -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
;
...
...
tests/test_logserver.cc
View file @
d78fc2e8
...
...
@@ -244,7 +244,7 @@ TEST_CASE("MaxSessions", "[LogServer]" )
r2_thr
->
join
();
}
// --------------------------------------------------------------------------
TEST_CASE
(
"Log
a
gregator regexp"
,
"[LogAgregator]"
)
TEST_CASE
(
"Log
A
gregator regexp"
,
"[LogAgregator]"
)
{
auto
la
=
make_shared
<
LogAgregator
>
(
"ROOT"
);
auto
log1
=
la
->
create
(
"log1"
);
...
...
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