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
0217b4b1
Commit
0217b4b1
authored
Sep 10, 2014
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(Log): отладил обработку команд отключения и включения записи файла логов.
(Log): исправил ошибку в работе команды LogRotate для DebugStream. (Log): написал небольшие комментарии
parent
a20dcb5f
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
150 additions
and
55 deletions
+150
-55
ctl-cpp-common.xsl
Utilities/codegen/ctl-cpp-common.xsl
+1
-1
IOControl.cc
extensions/IOControl/IOControl.cc
+2
-2
PassiveLProcessor.cc
extensions/LogicProcessor/PassiveLProcessor.cc
+2
-2
MBExchange.cc
extensions/ModbusMaster/MBExchange.cc
+2
-2
MBSlave.cc
extensions/ModbusSlave/MBSlave.cc
+2
-2
smemory-plus.cc
extensions/SharedMemoryPlus/smemory-plus.cc
+2
-2
UNetExchange.cc
extensions/UNetUDP/UNetExchange.cc
+2
-2
UObject_SK.cc
extensions/lib/UObject_SK.cc
+1
-1
DebugStream.h
include/DebugStream.h
+2
-2
LogAgregator.h
include/LogAgregator.h
+12
-1
LogServer.h
include/LogServer.h
+34
-0
LogSession.h
include/LogSession.h
+1
-0
DebugStream.cc
src/Log/DebugStream.cc
+10
-4
LogAgregator.cc
src/Log/LogAgregator.cc
+29
-16
LogSession.cc
src/Log/LogSession.cc
+37
-17
UniSetActivator.cc
src/ObjectRepository/UniSetActivator.cc
+1
-1
dlog.cc
tests/dlog.cc
+10
-0
No files found.
Utilities/codegen/ctl-cpp-common.xsl
View file @
0217b4b1
...
...
@@ -319,7 +319,7 @@ void <xsl:value-of select="$CLASSNAME"/>_SK::sysCommand( const SystemMessage* _s
string fname( mylog.getLogFile() );
if( !fname.empty() )
{
mylog.logFile(fname.c_str());
mylog.logFile(fname.c_str()
,true
);
mylog
<<
myname
<<
"(sysCommand): ***************** mylog LOG ROTATE *****************"
<<
endl;
}
}
...
...
extensions/IOControl/IOControl.cc
View file @
0217b4b1
...
...
@@ -1226,7 +1226,7 @@ void IOControl::sysCommand( const SystemMessage* sm )
string
fname
(
ulog
.
getLogFile
()
);
if
(
!
fname
.
empty
()
)
{
ulog
.
logFile
(
fname
);
ulog
.
logFile
(
fname
,
true
);
ulog
<<
myname
<<
"(sysCommand): ***************** ulog LOG ROTATE *****************"
<<
endl
;
}
...
...
@@ -1234,7 +1234,7 @@ void IOControl::sysCommand( const SystemMessage* sm )
fname
=
dlog
.
getLogFile
();
if
(
!
fname
.
empty
()
)
{
dlog
.
logFile
(
fname
);
dlog
.
logFile
(
fname
,
true
);
dlog
<<
myname
<<
"(sysCommand): ***************** GGDEB LOG ROTATE *****************"
<<
endl
;
}
}
...
...
extensions/LogicProcessor/PassiveLProcessor.cc
View file @
0217b4b1
...
...
@@ -148,7 +148,7 @@ void PassiveLProcessor::sysCommand( const UniSetTypes::SystemMessage *sm )
string
fname
(
ulog
.
getLogFile
()
);
if
(
!
fname
.
empty
()
)
{
ulog
.
logFile
(
fname
);
ulog
.
logFile
(
fname
,
true
);
ulog
<<
myname
<<
"(sysCommand): ***************** ulog LOG ROTATE *****************"
<<
std
::
endl
;
}
...
...
@@ -156,7 +156,7 @@ void PassiveLProcessor::sysCommand( const UniSetTypes::SystemMessage *sm )
fname
=
dlog
.
getLogFile
();
if
(
!
fname
.
empty
()
)
{
dlog
.
logFile
(
fname
);
dlog
.
logFile
(
fname
,
true
);
dlog
<<
myname
<<
"(sysCommand): ***************** dlog LOG ROTATE *****************"
<<
std
::
endl
;
}
}
...
...
extensions/ModbusMaster/MBExchange.cc
View file @
0217b4b1
...
...
@@ -2562,14 +2562,14 @@ void MBExchange::sysCommand( const UniSetTypes::SystemMessage *sm )
string
fname
(
ulog
.
getLogFile
());
if
(
!
fname
.
empty
()
)
{
ulog
.
logFile
(
fname
);
ulog
.
logFile
(
fname
,
true
);
ulog
<<
myname
<<
"(sysCommand): ***************** ulog LOG ROTATE *****************"
<<
std
::
endl
;
}
dlog
<<
myname
<<
"(sysCommand): logRotate"
<<
std
::
endl
;
fname
=
dlog
.
getLogFile
();
if
(
!
fname
.
empty
()
)
{
dlog
.
logFile
(
fname
);
dlog
.
logFile
(
fname
,
true
);
dlog
<<
myname
<<
"(sysCommand): ***************** dlog LOG ROTATE *****************"
<<
std
::
endl
;
}
}
...
...
extensions/ModbusSlave/MBSlave.cc
View file @
0217b4b1
...
...
@@ -623,7 +623,7 @@ void MBSlave::sysCommand( const UniSetTypes::SystemMessage *sm )
string
fname
(
ulog
.
getLogFile
());
if
(
!
fname
.
empty
()
)
{
ulog
.
logFile
(
fname
);
ulog
.
logFile
(
fname
,
true
);
ulog
<<
myname
<<
"(sysCommand): ***************** ulog LOG ROTATE *****************"
<<
std
::
endl
;
}
...
...
@@ -631,7 +631,7 @@ void MBSlave::sysCommand( const UniSetTypes::SystemMessage *sm )
fname
=
dlog
.
getLogFile
();
if
(
!
fname
.
empty
()
)
{
dlog
.
logFile
(
fname
);
dlog
.
logFile
(
fname
,
true
);
dlog
<<
myname
<<
"(sysCommand): ***************** dlog LOG ROTATE *****************"
<<
std
::
endl
;
}
}
...
...
extensions/SharedMemoryPlus/smemory-plus.cc
View file @
0217b4b1
...
...
@@ -72,8 +72,8 @@ int main( int argc, const char **argv )
string
logfilename
=
conf
->
getArgParam
(
"--logfile"
,
"smemory-plus.log"
);
string
logname
(
conf
->
getLogDir
()
+
logfilename
);
//
UniSetExtensions::dlog.logFile( logname );
//
ulog.logFile( logname );
UniSetExtensions
::
dlog
.
logFile
(
logname
);
ulog
.
logFile
(
logname
);
conf
->
initDebug
(
UniSetExtensions
::
dlog
,
"dlog"
);
UniSetActivator
*
act
=
UniSetActivator
::
Instance
();
...
...
extensions/UNetUDP/UNetExchange.cc
View file @
0217b4b1
...
...
@@ -523,7 +523,7 @@ void UNetExchange::sysCommand( const UniSetTypes::SystemMessage *sm )
string
fname
(
ulog
.
getLogFile
());
if
(
!
fname
.
empty
()
)
{
ulog
.
logFile
(
fname
);
ulog
.
logFile
(
fname
,
true
);
ulog
<<
myname
<<
"(sysCommand): ***************** ulog LOG ROTATE *****************"
<<
std
::
endl
;
}
...
...
@@ -531,7 +531,7 @@ void UNetExchange::sysCommand( const UniSetTypes::SystemMessage *sm )
fname
=
dlog
.
getLogFile
();
if
(
!
fname
.
empty
()
)
{
dlog
.
logFile
(
fname
);
dlog
.
logFile
(
fname
,
true
);
dlog
<<
myname
<<
"(sysCommand): ***************** dlog LOG ROTATE *****************"
<<
std
::
endl
;
}
}
...
...
extensions/lib/UObject_SK.cc
View file @
0217b4b1
...
...
@@ -273,7 +273,7 @@ void UObject_SK::sysCommand( const SystemMessage* _sm )
string
fname
(
mylog
.
getLogFile
()
);
if
(
!
fname
.
empty
()
)
{
mylog
.
logFile
(
fname
.
c_str
());
mylog
.
logFile
(
fname
.
c_str
()
,
true
);
mylog
<<
myname
<<
"(sysCommand): ***************** mylog LOG ROTATE *****************"
<<
endl
;
}
}
...
...
include/DebugStream.h
View file @
0217b4b1
...
...
@@ -89,7 +89,7 @@ public:
/// Constructor, sets the log file to f, and the debug level to t.
explicit
DebugStream
(
char
const
*
f
,
Debug
::
type
t
=
Debug
::
NONE
);
DebugStream
(
char
const
*
f
,
Debug
::
type
t
=
Debug
::
NONE
,
bool
truncate
=
false
);
///
virtual
~
DebugStream
();
...
...
@@ -118,7 +118,7 @@ public:
}
/// Sets the debugstreams' logfile to f.
virtual
void
logFile
(
const
std
::
string
&
f
);
virtual
void
logFile
(
const
std
::
string
&
f
,
bool
truncate
=
false
);
inline
std
::
string
getLogFile
(){
return
fname
;
}
...
...
include/LogAgregator.h
View file @
0217b4b1
...
...
@@ -25,13 +25,24 @@ class LogAgregator:
void
delLevel
(
const
std
::
string
&
logname
,
Debug
::
type
t
);
void
level
(
const
std
::
string
&
logname
,
Debug
::
type
t
);
struct
LogInfo
{
LogInfo
()
:
log
(
0
),
logfile
(
""
){}
LogInfo
(
DebugStream
*
l
)
:
log
(
l
),
logfile
(
l
->
getLogFile
()){}
DebugStream
*
log
;
std
::
string
logfile
;
};
DebugStream
*
getLog
(
const
std
::
string
&
logname
);
LogInfo
getLogInfo
(
const
std
::
string
&
logname
);
protected
:
void
logOnEvent
(
const
std
::
string
&
s
);
private
:
typedef
std
::
list
<
DebugStream
*
>
LogList
;
typedef
std
::
list
<
LogInfo
>
LogList
;
LogList
llst
;
};
// -------------------------------------------------------------------------
...
...
include/LogServer.h
View file @
0217b4b1
...
...
@@ -10,6 +10,40 @@
#include "ThreadCreator.h"
class
LogSession
;
// -------------------------------------------------------------------------
/*! \page pgLogServer Лог сервер
Лог сервер предназначен для возможности удалённого чтения логов (DebugStream).
Ему указывается host и port для прослушивания запросов, которые можно делать при помощи
LogReader. Читающих клиентов может быть скольугодно много, на каждого создаётся своя "сессия"(LogSession).
При этом через лог сервер имеется возможность управлять включением или отключением определённых уровней логов,
записью, отключением записи или ротацией файла с логами. DebugStream за которым ведётся "слежение"
задаётся в конструкторе для LogServer.
\code
DebugStream mylog;
LogServer logsrv(mylog);
...
logsrv.run(host,port,create_thread);
...
\endcode
При этом если необходимо управлять или читать сразу несколько логов можно воспользоваться специальным классом LogAgregator.
\code
DebugStream log1;
log1.setLogName("log1");
DebugStream log2;
log2.setLogName("log2");
LogAgregator la;
la.add(log1);
la.add(log2);
LogServer logsrv(la);
...
logsrv.run(host,port,create_thread);
...
\endcode
*/
// -------------------------------------------------------------------------
class
LogServer
{
public
:
...
...
include/LogSession.h
View file @
0217b4b1
...
...
@@ -9,6 +9,7 @@
#include "DebugStream.h"
#include "PassiveTimer.h"
// -------------------------------------------------------------------------
/*! Реализация "сессии" для клиентов LogServer. */
class
LogSession
:
public
ost
::
TCPSession
{
...
...
src/Log/DebugStream.cc
View file @
0217b4b1
...
...
@@ -55,7 +55,7 @@ DebugStream::DebugStream(Debug::type t)
//--------------------------------------------------------------------------
/// Constructor, sets the log file to f, and the debug level to t.
DebugStream
::
DebugStream
(
char
const
*
f
,
Debug
::
type
t
)
DebugStream
::
DebugStream
(
char
const
*
f
,
Debug
::
type
t
,
bool
truncate
)
:
ostream
(
new
debugbuf
(
cerr
.
rdbuf
())),
dt
(
t
),
nullstream
(
new
nullbuf
),
internal
(
new
debugstream_internal
),
...
...
@@ -63,7 +63,10 @@ DebugStream::DebugStream(char const * f, Debug::type t)
fname
(
""
),
logname
(
""
)
{
internal
->
fbuf
.
open
(
f
,
ios
::
out
|
ios
::
app
);
std
::
ios_base
::
openmode
mode
=
ios
::
out
;
mode
|=
truncate
?
ios
::
trunc
:
ios
::
app
;
internal
->
fbuf
.
open
(
f
,
mode
);
delete
rdbuf
(
new
threebuf
(
cerr
.
rdbuf
(),
&
internal
->
fbuf
,
&
internal
->
sbuf
));
...
...
@@ -99,7 +102,7 @@ const DebugStream& DebugStream::operator=( const DebugStream& r )
}
//--------------------------------------------------------------------------
/// Sets the debugstreams' logfile to f.
void
DebugStream
::
logFile
(
const
std
::
string
&
f
)
void
DebugStream
::
logFile
(
const
std
::
string
&
f
,
bool
truncate
)
{
fname
=
f
;
if
(
internal
)
{
...
...
@@ -110,7 +113,10 @@ void DebugStream::logFile( const std::string& f )
if
(
!
f
.
empty
()
)
{
internal
->
fbuf
.
open
(
f
.
c_str
(),
ios
::
out
|
ios
::
app
);
std
::
ios_base
::
openmode
mode
=
ios
::
out
;
mode
|=
truncate
?
ios
::
trunc
:
ios
::
app
;
internal
->
fbuf
.
open
(
f
.
c_str
(),
mode
);
delete
rdbuf
(
new
threebuf
(
cerr
.
rdbuf
(),
&
internal
->
fbuf
,
&
internal
->
sbuf
));
}
...
...
src/Log/LogAgregator.cc
View file @
0217b4b1
...
...
@@ -16,7 +16,7 @@ LogAgregator::LogAgregator( Debug::type t ):
void
LogAgregator
::
logFile
(
const
std
::
string
&
f
)
{
DebugStream
::
logFile
(
f
);
if
(
f
.
empty
()
)
if
(
!
f
.
empty
()
)
delete
rdbuf
(
new
teebuf
(
&
internal
->
fbuf
,
&
internal
->
sbuf
));
else
delete
rdbuf
(
new
teebuf
(
&
internal
->
nbuf
,
&
internal
->
sbuf
));
...
...
@@ -36,7 +36,7 @@ void LogAgregator::add( DebugStream& l )
l
.
signal_stream_event
().
connect
(
sigc
::
mem_fun
(
this
,
&
LogAgregator
::
logOnEvent
)
);
for
(
LogList
::
iterator
i
=
llst
.
begin
();
i
!=
llst
.
end
();
i
++
)
{
if
(
&
l
==
(
*
i
)
)
if
(
&
l
==
i
->
log
)
return
;
}
...
...
@@ -46,10 +46,10 @@ void LogAgregator::add( DebugStream& l )
void
LogAgregator
::
addLevel
(
const
std
::
string
&
logname
,
Debug
::
type
t
)
{
for
(
auto
&
i
:
llst
)
{
if
(
i
->
getLogName
()
==
logname
)
{
if
(
i
.
log
->
getLogName
()
==
logname
)
{
i
->
addLevel
(
t
);
i
.
log
->
addLevel
(
t
);
break
;
}
}
...
...
@@ -58,10 +58,10 @@ void LogAgregator::addLevel( const std::string& logname, Debug::type t )
void
LogAgregator
::
delLevel
(
const
std
::
string
&
logname
,
Debug
::
type
t
)
{
for
(
auto
&
i
:
llst
)
{
if
(
i
->
getLogName
()
==
logname
)
{
if
(
i
.
log
->
getLogName
()
==
logname
)
{
i
->
delLevel
(
t
);
i
.
log
->
delLevel
(
t
);
break
;
}
}
...
...
@@ -70,10 +70,10 @@ void LogAgregator::delLevel( const std::string& logname, Debug::type t )
void
LogAgregator
::
level
(
const
std
::
string
&
logname
,
Debug
::
type
t
)
{
for
(
auto
&
i
:
llst
)
{
if
(
i
->
getLogName
()
==
logname
)
{
if
(
i
.
log
->
getLogName
()
==
logname
)
{
i
->
level
(
t
);
i
.
log
->
level
(
t
);
break
;
}
}
...
...
@@ -85,11 +85,25 @@ DebugStream* LogAgregator::getLog( const std::string& logname )
return
0
;
for
(
auto
&
i
:
llst
)
{
if
(
i
->
getLogName
()
==
logname
)
return
i
;
{
if
(
i
.
log
->
getLogName
()
==
logname
)
return
i
.
log
;
}
return
0
;
}
// -------------------------------------------------------------------------
\ No newline at end of file
// -------------------------------------------------------------------------
LogAgregator
::
LogInfo
LogAgregator
::
getLogInfo
(
const
std
::
string
&
logname
)
{
if
(
logname
.
empty
()
)
return
LogInfo
();
for
(
auto
&
i
:
llst
)
{
if
(
i
.
log
->
getLogName
()
==
logname
)
return
i
;
}
return
LogInfo
();
}
// -------------------------------------------------------------------------
src/Log/LogSession.cc
View file @
0217b4b1
...
...
@@ -66,8 +66,6 @@ void LogSession::run()
ptSessionTimeout
.
setTiming
(
sessTimeout
);
string
oldLogFile
(
log
->
getLogFile
()
);
setKeepAlive
(
true
);
// setTimeout(sessTimeout);
...
...
@@ -87,12 +85,38 @@ void LogSession::run()
slog
.
info
()
<<
peername
<<
"(run): receive command: '"
<<
msg
.
cmd
<<
"'"
<<
endl
;
string
cmdLogName
(
msg
.
logname
);
DebugStream
*
cmdlog
=
0
;
DebugStream
*
cmdlog
=
log
;
string
logfile
(
log
->
getLogFile
());
if
(
!
cmdLogName
.
empty
()
)
{
LogAgregator
*
lag
=
dynamic_cast
<
LogAgregator
*>
(
log
);
cmdlog
=
lag
?
lag
->
getLog
(
cmdLogName
)
:
log
;
if
(
lag
)
{
LogAgregator
::
LogInfo
inf
=
lag
->
getLogInfo
(
cmdLogName
);
if
(
inf
.
log
)
{
cmdlog
=
inf
.
log
;
logfile
=
inf
.
logfile
;
}
else
{
// если имя задали, но такого лога не нашлось
// то игнорируем команду
cmdlog
=
0
;
logfile
=
""
;
}
}
else
{
// если имя лога задали, а оно не совпадает с текущим
// игнорируем команду
if
(
log
->
getLogFile
()
!=
cmdLogName
)
{
cmdlog
=
0
;
logfile
=
""
;
}
}
}
// обрабатываем команды только если нашли log
...
...
@@ -106,35 +130,31 @@ void LogSession::run()
cmdlog
->
level
(
(
Debug
::
type
)
msg
.
data
);
break
;
case
LogServerTypes
:
:
cmdAddLevel
:
cmdlog
->
addLevel
((
Debug
::
type
)
msg
.
data
);
cmdlog
->
addLevel
(
(
Debug
::
type
)
msg
.
data
);
break
;
case
LogServerTypes
:
:
cmdDelLevel
:
cmdlog
->
delLevel
(
(
Debug
::
type
)
msg
.
data
);
break
;
case
LogServerTypes
:
:
cmdRotate
:
{
string
lfile
(
cmdlog
->
getLogFile
()
);
if
(
!
lfile
.
empty
()
)
cmdlog
->
logFile
(
lfile
);
}
if
(
!
logfile
.
empty
()
)
cmdlog
->
logFile
(
logfile
,
true
);
break
;
case
LogServerTypes
:
:
cmdOffLogFile
:
{
string
lfile
(
cmdlog
->
getLogFile
()
);
if
(
!
lfile
.
empty
()
)
if
(
!
logfile
.
empty
()
)
cmdlog
->
logFile
(
""
);
}
break
;
case
LogServerTypes
:
:
cmdOnLogFile
:
{
if
(
!
oldLogFile
.
empty
()
&&
oldLogFile
!=
cmdlog
->
getLogFile
()
)
cmdlog
->
logFile
(
oldLogF
ile
);
if
(
!
logfile
.
empty
()
)
cmdlog
->
logFile
(
logf
ile
);
}
break
;
default
:
slog
.
warn
()
<<
peername
<<
"(run): Unknown command '"
<<
msg
.
cmd
<<
"'"
<<
endl
;
break
;
...
...
src/ObjectRepository/UniSetActivator.cc
View file @
0217b4b1
...
...
@@ -409,7 +409,7 @@ void UniSetActivator::sysCommand( const UniSetTypes::SystemMessage *sm )
string
fname
=
ulog
.
getLogFile
();
if
(
!
fname
.
empty
()
)
{
ulog
.
logFile
(
fname
.
c_str
());
ulog
.
logFile
(
fname
.
c_str
()
,
true
);
ulog
<<
myname
<<
"(sysCommand): ***************** ulog LOG ROTATE *****************"
<<
endl
;
}
}
...
...
tests/dlog.cc
View file @
0217b4b1
...
...
@@ -63,5 +63,15 @@ int main( int argc, const char **argv )
if
(
l
!=
&
log1
)
cout
<<
"**** TEST FAILED: LogAgregator::getLog() "
<<
endl
;
cout
<<
"===== Test 3 ====="
<<
endl
;
tlog
.
level
(
Debug
::
ANY
);
tlog
.
logFile
(
"tlog.log"
);
tlog
<<
"TEST TEXT"
<<
endl
;
tlog
.
logFile
(
"tlog.log"
,
true
);
return
0
;
}
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