Commit 51bb5408 authored by Pavel Vainerman's avatar Pavel Vainerman

Переписал механизм работы с логами. Теперь ulog и dlog не глобальные

объекты, а глобальные shared_ptr<DebugStream>. Это необходимо для дальнейшей работы с LogAgregator и LogServer.
parent 0d95ed8d
...@@ -69,7 +69,7 @@ MBSlave::~MBSlave() ...@@ -69,7 +69,7 @@ MBSlave::~MBSlave()
delete rscomm; delete rscomm;
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
void MBSlave::setLog( DebugStream& dlog ) void MBSlave::setLog( std::shared_ptr<DebugStream> dlog )
{ {
if( rscomm ) if( rscomm )
rscomm->setLog(dlog); rscomm->setLog(dlog);
......
...@@ -35,7 +35,7 @@ class MBSlave ...@@ -35,7 +35,7 @@ class MBSlave
void execute(); /*!< основной цикл работы */ void execute(); /*!< основной цикл работы */
void setLog( DebugStream& dlog ); void setLog( std::shared_ptr<DebugStream> dlog );
protected: protected:
// действия при завершении работы // действия при завершении работы
......
...@@ -66,7 +66,7 @@ MBTCPServer::~MBTCPServer() ...@@ -66,7 +66,7 @@ MBTCPServer::~MBTCPServer()
delete sslot; delete sslot;
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
void MBTCPServer::setLog( DebugStream& dlog ) void MBTCPServer::setLog( std::shared_ptr<DebugStream> dlog )
{ {
if( sslot ) if( sslot )
sslot->setLog(dlog); sslot->setLog(dlog);
......
...@@ -30,7 +30,7 @@ class MBTCPServer ...@@ -30,7 +30,7 @@ class MBTCPServer
} }
void execute(); /*!< основной цикл работы */ void execute(); /*!< основной цикл работы */
void setLog( DebugStream& dlog ); void setLog( std::shared_ptr<DebugStream> dlog );
protected: protected:
// действия при завершении работы // действия при завершении работы
......
...@@ -42,7 +42,7 @@ int main( int argc, char **argv ) ...@@ -42,7 +42,7 @@ int main( int argc, char **argv )
string dev("/dev/ttyS0"); string dev("/dev/ttyS0");
string speed("38400"); string speed("38400");
ModbusRTU::ModbusAddr myaddr = 0x01; ModbusRTU::ModbusAddr myaddr = 0x01;
DebugStream dlog; auto dlog = make_shared<DebugStream>();
int use485 = 0; int use485 = 0;
int replyVal=-1; int replyVal=-1;
int replyVal2=-1; int replyVal2=-1;
...@@ -99,7 +99,7 @@ int main( int argc, char **argv ) ...@@ -99,7 +99,7 @@ int main( int argc, char **argv )
<< " myaddr=" << ModbusRTU::addr2str(myaddr) << " myaddr=" << ModbusRTU::addr2str(myaddr)
<< endl; << endl;
dlog.addLevel( Debug::type(Debug::CRIT | Debug::WARN | Debug::INFO) ); dlog->addLevel( Debug::type(Debug::CRIT | Debug::WARN | Debug::INFO) );
} }
MBSlave mbs(myaddr,dev,speed,use485); MBSlave mbs(myaddr,dev,speed,use485);
......
...@@ -114,7 +114,7 @@ int main( int argc, char **argv ) ...@@ -114,7 +114,7 @@ int main( int argc, char **argv )
ModbusRTU::DiagnosticsSubFunction subfunc = ModbusRTU::subEcho; ModbusRTU::DiagnosticsSubFunction subfunc = ModbusRTU::subEcho;
ModbusRTU::ModbusData dat = 0; ModbusRTU::ModbusData dat = 0;
int tout = 2000; int tout = 2000;
DebugStream dlog; auto dlog = make_shared<DebugStream>();
string tofile(""); string tofile("");
int use485 = 0; int use485 = 0;
int ncycles = -1; int ncycles = -1;
...@@ -370,7 +370,7 @@ int main( int argc, char **argv ) ...@@ -370,7 +370,7 @@ int main( int argc, char **argv )
ModbusRTUMaster mb(dev,use485); ModbusRTUMaster mb(dev,use485);
if( verb ) if( verb )
dlog.addLevel( Debug::type(Debug::CRIT | Debug::WARN | Debug::INFO) ); dlog->addLevel( Debug::type(Debug::CRIT | Debug::WARN | Debug::INFO) );
mb.setTimeout(tout); mb.setTimeout(tout);
mb.setSpeed(speed); mb.setSpeed(speed);
......
...@@ -40,7 +40,7 @@ int main( int argc, char **argv ) ...@@ -40,7 +40,7 @@ int main( int argc, char **argv )
int port = 502; int port = 502;
string iaddr("127.0.0.1"); string iaddr("127.0.0.1");
ModbusRTU::ModbusAddr myaddr = 0x01; ModbusRTU::ModbusAddr myaddr = 0x01;
DebugStream dlog; auto dlog = make_shared<DebugStream>();
bool ignoreAddr = false; bool ignoreAddr = false;
int replyVal=-1; int replyVal=-1;
...@@ -93,7 +93,7 @@ int main( int argc, char **argv ) ...@@ -93,7 +93,7 @@ int main( int argc, char **argv )
<< " myaddr=" << ModbusRTU::addr2str(myaddr) << " myaddr=" << ModbusRTU::addr2str(myaddr)
<< endl; << endl;
dlog.addLevel( Debug::ANY ); dlog->addLevel( Debug::ANY );
} }
MBTCPServer mbs(myaddr,iaddr,port,verb); MBTCPServer mbs(myaddr,iaddr,port,verb);
......
...@@ -91,7 +91,7 @@ int main( int argc, char **argv ) ...@@ -91,7 +91,7 @@ int main( int argc, char **argv )
ModbusRTU::DiagnosticsSubFunction subfunc = ModbusRTU::subEcho; ModbusRTU::DiagnosticsSubFunction subfunc = ModbusRTU::subEcho;
ModbusRTU::ModbusData dat = 0; ModbusRTU::ModbusData dat = 0;
int tout = 2000; int tout = 2000;
DebugStream dlog; auto dlog = make_shared<DebugStream>();
int ncycles = -1; int ncycles = -1;
ModbusRTU::ModbusByte devID = 0; ModbusRTU::ModbusByte devID = 0;
ModbusRTU::ModbusByte objID = 0; ModbusRTU::ModbusByte objID = 0;
...@@ -256,7 +256,7 @@ int main( int argc, char **argv ) ...@@ -256,7 +256,7 @@ int main( int argc, char **argv )
<< " timeout=" << tout << " msec " << " timeout=" << tout << " msec "
<< endl; << endl;
dlog.addLevel( Debug::type(Debug::CRIT | Debug::WARN | Debug::INFO) ); dlog->addLevel( Debug::type(Debug::CRIT | Debug::WARN | Debug::INFO) );
} }
ModbusTCPMaster mb; ModbusTCPMaster mb;
......
...@@ -121,7 +121,7 @@ void <xsl:value-of select="$CLASSNAME"/>_SK::preSensorInfo( const UniSetTypes::S ...@@ -121,7 +121,7 @@ void <xsl:value-of select="$CLASSNAME"/>_SK::preSensorInfo( const UniSetTypes::S
if( _sm->id == <xsl:value-of select="../../@name"/> ) if( _sm->id == <xsl:value-of select="../../@name"/> )
{ {
<xsl:call-template name="setprefix"/><xsl:value-of select="../../@name"/> = _sm->value; <xsl:call-template name="setprefix"/><xsl:value-of select="../../@name"/> = _sm->value;
mylog.level( Debug::type(_sm->value) ); mylog->level( Debug::type(_sm->value) );
} }
</xsl:if> </xsl:if>
</xsl:if> </xsl:if>
......
...@@ -162,7 +162,7 @@ void <xsl:value-of select="$CLASSNAME"/>_SK::preSensorInfo( const UniSetTypes::S ...@@ -162,7 +162,7 @@ void <xsl:value-of select="$CLASSNAME"/>_SK::preSensorInfo( const UniSetTypes::S
if( _sm->id == <xsl:value-of select="@name"/> ) if( _sm->id == <xsl:value-of select="@name"/> )
{ {
<xsl:call-template name="setprefix"/><xsl:value-of select="@name"/> = _sm->value; <xsl:call-template name="setprefix"/><xsl:value-of select="@name"/> = _sm->value;
mylog.level( Debug::type(_sm->value) ); mylog->level( Debug::type(_sm->value) );
} }
</xsl:if> </xsl:if>
</xsl:if> </xsl:if>
......
...@@ -171,22 +171,23 @@ ...@@ -171,22 +171,23 @@
void updateValues(); void updateValues();
void setMsg( UniSetTypes::ObjectId code, bool state ); void setMsg( UniSetTypes::ObjectId code, bool state );
DebugStream mylog; std::shared_ptr&lt;DebugStream&gt; mylog;
void init_dlog( DebugStream&amp; d ); void init_dlog( std::shared_ptr&lt;DebugStream&gt; d );
// "синтаксический сахар"..для логов // "синтаксический сахар"..для логов
#define myinfo if( mylog.debugging(Debug::INFO) ) mylog #define myinfo if( mylog->debugging(Debug::INFO) ) mylog->any()
#define mywarn if( mylog.debugging(Debug::WARN) ) mylog #define mywarn if( mylog->debugging(Debug::WARN) ) mylog->any()
#define mycrit if( mylog.debugging(Debug::CRIT) ) mylog #define mycrit if( mylog->debugging(Debug::CRIT) ) mylog->any()
#define mylog1 if( mylog.debugging(Debug::LEVEL1) ) mylog #define mylog1 if( mylog->debugging(Debug::LEVEL1) ) mylog->any()
#define mylog2 if( mylog.debugging(Debug::LEVEL2) ) mylog #define mylog2 if( mylog->debugging(Debug::LEVEL2) ) mylog->any()
#define mylog3 if( mylog.debugging(Debug::LEVEL3) ) mylog #define mylog3 if( mylog->debugging(Debug::LEVEL3) ) mylog->any()
#define mylog4 if( mylog.debugging(Debug::LEVEL4) ) mylog #define mylog4 if( mylog->debugging(Debug::LEVEL4) ) mylog->any()
#define mylog5 if( mylog.debugging(Debug::LEVEL5) ) mylog #define mylog5 if( mylog->debugging(Debug::LEVEL5) ) mylog->any()
#define mylog6 if( mylog.debugging(Debug::LEVEL6) ) mylog #define mylog6 if( mylog->debugging(Debug::LEVEL6) ) mylog->any()
#define mylog7 if( mylog.debugging(Debug::LEVEL7) ) mylog #define mylog7 if( mylog->debugging(Debug::LEVEL7) ) mylog->any()
#define mylog8 if( mylog.debugging(Debug::LEVEL8) ) mylog #define mylog8 if( mylog->debugging(Debug::LEVEL8) ) mylog->any()
#define mylog9 if( mylog.debugging(Debug::LEVEL9) ) mylog #define mylog9 if( mylog->debugging(Debug::LEVEL9) ) mylog->any()
#define mylogany mylog->any()
</xsl:template> </xsl:template>
<xsl:template name="COMMON-HEAD-PROTECTED"> <xsl:template name="COMMON-HEAD-PROTECTED">
...@@ -257,7 +258,7 @@ ...@@ -257,7 +258,7 @@
<xsl:template name="COMMON-CC-FILE"> <xsl:template name="COMMON-CC-FILE">
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
void <xsl:value-of select="$CLASSNAME"/>_SK::init_dlog( DebugStream&amp; d ) void <xsl:value-of select="$CLASSNAME"/>_SK::init_dlog( std::shared_ptr&lt;DebugStream&gt; d )
{ {
<xsl:value-of select="$CLASSNAME"/>_SK::mylog = d; <xsl:value-of select="$CLASSNAME"/>_SK::mylog = d;
} }
...@@ -295,7 +296,7 @@ void <xsl:value-of select="$CLASSNAME"/>_SK::sysCommand( const SystemMessage* _s ...@@ -295,7 +296,7 @@ void <xsl:value-of select="$CLASSNAME"/>_SK::sysCommand( const SystemMessage* _s
switch( _sm->command ) switch( _sm->command )
{ {
case SystemMessage::WatchDog: case SystemMessage::WatchDog:
ulog &lt;&lt; myname &lt;&lt; "(sysCommand): WatchDog" &lt;&lt; endl; ulogany &lt;&lt; myname &lt;&lt; "(sysCommand): WatchDog" &lt;&lt; endl;
if( !active || !ptStartUpTimeout.checkTime() ) if( !active || !ptStartUpTimeout.checkTime() )
{ {
uwarn &lt;&lt; myname &lt;&lt; "(sysCommand): игнорируем WatchDog, потому-что только-что стартанули" &lt;&lt; endl; uwarn &lt;&lt; myname &lt;&lt; "(sysCommand): игнорируем WatchDog, потому-что только-что стартанули" &lt;&lt; endl;
...@@ -324,12 +325,12 @@ void <xsl:value-of select="$CLASSNAME"/>_SK::sysCommand( const SystemMessage* _s ...@@ -324,12 +325,12 @@ void <xsl:value-of select="$CLASSNAME"/>_SK::sysCommand( const SystemMessage* _s
case SystemMessage::LogRotate: case SystemMessage::LogRotate:
{ {
// переоткрываем логи // переоткрываем логи
mylog &lt;&lt; myname &lt;&lt; "(sysCommand): logRotate" &lt;&lt; endl; mylogany &lt;&lt; myname &lt;&lt; "(sysCommand): logRotate" &lt;&lt; endl;
string fname( mylog.getLogFile() ); string fname( mylog->getLogFile() );
if( !fname.empty() ) if( !fname.empty() )
{ {
mylog.logFile(fname.c_str(),true); mylog->logFile(fname.c_str(),true);
mylog &lt;&lt; myname &lt;&lt; "(sysCommand): ***************** mylog LOG ROTATE *****************" &lt;&lt; endl; mylogany &lt;&lt; myname &lt;&lt; "(sysCommand): ***************** mylog LOG ROTATE *****************" &lt;&lt; endl;
} }
} }
break; break;
...@@ -485,6 +486,7 @@ void <xsl:value-of select="$CLASSNAME"/>_SK::waitSM( int wait_msec, ObjectId _te ...@@ -485,6 +486,7 @@ void <xsl:value-of select="$CLASSNAME"/>_SK::waitSM( int wait_msec, ObjectId _te
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
// generate timestamp: <xsl:value-of select="date:date()"/> // generate timestamp: <xsl:value-of select="date:date()"/>
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#include &lt;memory&gt;
#include <xsl:call-template name="preinclude"/>Configuration.h<xsl:call-template name="postinclude"/> #include <xsl:call-template name="preinclude"/>Configuration.h<xsl:call-template name="postinclude"/>
#include <xsl:call-template name="preinclude"/>Exceptions.h<xsl:call-template name="postinclude"/> #include <xsl:call-template name="preinclude"/>Exceptions.h<xsl:call-template name="postinclude"/>
#include "<xsl:value-of select="$SK_H_FILENAME"/>" #include "<xsl:value-of select="$SK_H_FILENAME"/>"
...@@ -618,7 +620,8 @@ end_private(false) ...@@ -618,7 +620,8 @@ end_private(false)
throw SystemError( err.str() ); throw SystemError( err.str() );
} }
mylog.setLogName(myname); mylog = make_shared&lt;DebugStream&gt;();
mylog-&gt;setLogName(myname);
<xsl:for-each select="//smap/item"> <xsl:for-each select="//smap/item">
<xsl:if test="normalize-space(@no_check_id)!='1'"> <xsl:if test="normalize-space(@no_check_id)!='1'">
...@@ -942,7 +945,8 @@ askPause(uniset_conf()->getPIntProp(cnode,"askPause",2000)) ...@@ -942,7 +945,8 @@ askPause(uniset_conf()->getPIntProp(cnode,"askPause",2000))
throw SystemError( err.str() ); throw SystemError( err.str() );
} }
mylog.setLogName(myname); mylog = make_shared&lt;DebugStream&gt;();
mylog-&gt;setLogName(myname);
si.node = conf->getLocalNode(); si.node = conf->getLocalNode();
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#ifndef <xsl:value-of select="$CLASSNAME"/>_SK_H_ #ifndef <xsl:value-of select="$CLASSNAME"/>_SK_H_
#define <xsl:value-of select="$CLASSNAME"/>_SK_H_ #define <xsl:value-of select="$CLASSNAME"/>_SK_H_
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#include &lt;memory&gt;
<xsl:if test="normalize-space($BASECLASS)!=''">#include <xsl:call-template name="preinclude"/><xsl:value-of select="normalize-space($BASECLASS)"/>.h<xsl:call-template name="postinclude"/></xsl:if> <xsl:if test="normalize-space($BASECLASS)!=''">#include <xsl:call-template name="preinclude"/><xsl:value-of select="normalize-space($BASECLASS)"/>.h<xsl:call-template name="postinclude"/></xsl:if>
<xsl:if test="normalize-space($BASECLASS)=''">#include <xsl:call-template name="preinclude"/>UniSetObject.h<xsl:call-template name="postinclude"/></xsl:if> <xsl:if test="normalize-space($BASECLASS)=''">#include <xsl:call-template name="preinclude"/>UniSetObject.h<xsl:call-template name="postinclude"/></xsl:if>
#include <xsl:call-template name="preinclude"/>LT_Object.h<xsl:call-template name="postinclude"/> #include <xsl:call-template name="preinclude"/>LT_Object.h<xsl:call-template name="postinclude"/>
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#ifndef <xsl:value-of select="$CLASSNAME"/>_SK_H_ #ifndef <xsl:value-of select="$CLASSNAME"/>_SK_H_
#define <xsl:value-of select="$CLASSNAME"/>_SK_H_ #define <xsl:value-of select="$CLASSNAME"/>_SK_H_
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#include &lt;memory&gt;
#include &lt;string&gt; #include &lt;string&gt;
<xsl:if test="normalize-space($BASECLASS)!=''">#include <xsl:call-template name="preinclude"/><xsl:value-of select="normalize-space($BASECLASS)"/>.h<xsl:call-template name="postinclude"/></xsl:if> <xsl:if test="normalize-space($BASECLASS)!=''">#include <xsl:call-template name="preinclude"/><xsl:value-of select="normalize-space($BASECLASS)"/>.h<xsl:call-template name="postinclude"/></xsl:if>
<xsl:if test="normalize-space($BASECLASS)=''">#include <xsl:call-template name="preinclude"/>UniSetObject.h<xsl:call-template name="postinclude"/></xsl:if> <xsl:if test="normalize-space($BASECLASS)=''">#include <xsl:call-template name="preinclude"/>UniSetObject.h<xsl:call-template name="postinclude"/></xsl:if>
......
...@@ -70,7 +70,7 @@ int main( int argc,char* argv[] ) ...@@ -70,7 +70,7 @@ int main( int argc,char* argv[] )
string logfilename = conf->getArgParam("--logfile","<xsl:value-of select="$CLASSNAME"/>.log"); string logfilename = conf->getArgParam("--logfile","<xsl:value-of select="$CLASSNAME"/>.log");
string logname( conf->getLogDir() + logfilename ); string logname( conf->getLogDir() + logfilename );
obj.mylog.logFile( logname.c_str() ); obj.mylog->logFile( logname.c_str() );
auto act = UniSetActivator::Instance(); auto act = UniSetActivator::Instance();
act-&gt;add(obj.get_ptr()); act-&gt;add(obj.get_ptr());
......
...@@ -76,7 +76,7 @@ int main( int argc, const char** argv ) ...@@ -76,7 +76,7 @@ int main( int argc, const char** argv )
string logfilename = conf->getArgParam("--logfile","<xsl:value-of select="$CLASSNAME"/>.log"); string logfilename = conf->getArgParam("--logfile","<xsl:value-of select="$CLASSNAME"/>.log");
string logname( conf->getLogDir() + logfilename ); string logname( conf->getLogDir() + logfilename );
obj.mylog.logFile( logname.c_str() ); obj.mylog->logFile( logname.c_str() );
</xsl:if> </xsl:if>
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
Name: libuniset2 Name: libuniset2
Version: 2.0 Version: 2.0
Release: alt12 Release: alt13
Summary: UniSet - library for building distributed industrial control systems Summary: UniSet - library for building distributed industrial control systems
...@@ -406,6 +406,10 @@ mv -f %buildroot%python_sitelibdir_noarch/* %buildroot%python_sitelibdir/%oname ...@@ -406,6 +406,10 @@ mv -f %buildroot%python_sitelibdir_noarch/* %buildroot%python_sitelibdir/%oname
%exclude %_pkgconfigdir/libUniSet2.pc %exclude %_pkgconfigdir/libUniSet2.pc
%changelog %changelog
* Fri Jan 23 2015 Pavel Vainerman <pv@altlinux.ru> 2.0-alt13
- refactoring ulog and dlog: Objects converted to shared_ptr<DebugStream>
for subsequent use LogAgregator.
* Fri Jan 23 2015 Pavel Vainerman <pv@altlinux.ru> 2.0-alt12 * Fri Jan 23 2015 Pavel Vainerman <pv@altlinux.ru> 2.0-alt12
- refactoring LogAgregator,LogServer,LogSesson --> use shared_ptr - refactoring LogAgregator,LogServer,LogSesson --> use shared_ptr
- fixed bug in MBExchange (read prop_prefix) - fixed bug in MBExchange (read prop_prefix)
......
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
using namespace UniSetTypes; using namespace UniSetTypes;
using namespace std; using namespace std;
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
const Debug::type DBLEVEL = Debug::LEVEL1; #define dblog if( ulog()->debugging(DBLogInfoLevel) ) (*(ulog().get()))[DBLogInfoLevel]
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
DBServer_MySQL::DBServer_MySQL(ObjectId id): DBServer_MySQL::DBServer_MySQL(ObjectId id):
DBServer(id), DBServer(id),
...@@ -128,8 +128,7 @@ void DBServer_MySQL::confirmInfo( const UniSetTypes::ConfirmMessage* cem ) ...@@ -128,8 +128,7 @@ void DBServer_MySQL::confirmInfo( const UniSetTypes::ConfirmMessage* cem )
<< " AND time='" << timeToString(cem->time, ":") <<" '" << " AND time='" << timeToString(cem->time, ":") <<" '"
<< " AND time_usec='" << cem->time_usec <<" '"; << " AND time_usec='" << cem->time_usec <<" '";
if( ulog.debugging(DBLEVEL) ) dblog << myname << "(update_confirm): " << data.str() << endl;
ulog[DBLEVEL] << myname << "(update_confirm): " << data.str() << endl;
if( !writeToBase(data.str()) ) if( !writeToBase(data.str()) )
{ {
...@@ -148,8 +147,7 @@ void DBServer_MySQL::confirmInfo( const UniSetTypes::ConfirmMessage* cem ) ...@@ -148,8 +147,7 @@ void DBServer_MySQL::confirmInfo( const UniSetTypes::ConfirmMessage* cem )
//-------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------
bool DBServer_MySQL::writeToBase( const string& query ) bool DBServer_MySQL::writeToBase( const string& query )
{ {
if( ulog.debugging(DBLogInfoLevel) ) dblog << myname << "(writeToBase): " << query << endl;
ulog[DBLogInfoLevel] << myname << "(writeToBase): " << query << endl;
// cout << "DBServer_MySQL: " << query << endl; // cout << "DBServer_MySQL: " << query << endl;
if( !db || !connect_ok ) if( !db || !connect_ok )
{ {
...@@ -235,8 +233,7 @@ void DBServer_MySQL::sensorInfo( const UniSetTypes::SensorMessage* si ) ...@@ -235,8 +233,7 @@ void DBServer_MySQL::sensorInfo( const UniSetTypes::SensorMessage* si )
<< val << "','" // value << val << "','" // value
<< si->node << "')"; // node << si->node << "')"; // node
if( ulog.debugging(DBLEVEL) ) dblog << myname << "(insert_main_history): " << data.str() << endl;
ulog[DBLEVEL] << myname << "(insert_main_history): " << data.str() << endl;
if( !writeToBase(data.str()) ) if( !writeToBase(data.str()) )
{ {
...@@ -256,8 +253,7 @@ void DBServer_MySQL::sensorInfo( const UniSetTypes::SensorMessage* si ) ...@@ -256,8 +253,7 @@ void DBServer_MySQL::sensorInfo( const UniSetTypes::SensorMessage* si )
void DBServer_MySQL::init_dbserver() void DBServer_MySQL::init_dbserver()
{ {
DBServer::init_dbserver(); DBServer::init_dbserver();
if( ulog.debugging(DBLogInfoLevel) ) dblog << myname << "(init): ..." << endl;
ulog[DBLogInfoLevel] << myname << "(init): ..." << endl;
if( connect_ok ) if( connect_ok )
{ {
...@@ -283,7 +279,7 @@ void DBServer_MySQL::init_dbserver() ...@@ -283,7 +279,7 @@ void DBServer_MySQL::init_dbserver()
UniXML::iterator it(node); UniXML::iterator it(node);
ulog[DBLogInfoLevel] << myname << "(init): init connection.." << endl; dblog << myname << "(init): init connection.." << endl;
string dbname(conf->getProp(node,"dbname")); string dbname(conf->getProp(node,"dbname"));
string dbnode(conf->getProp(node,"dbnode")); string dbnode(conf->getProp(node,"dbnode"));
string user(conf->getProp(node,"dbuser")); string user(conf->getProp(node,"dbuser"));
...@@ -306,8 +302,7 @@ void DBServer_MySQL::init_dbserver() ...@@ -306,8 +302,7 @@ void DBServer_MySQL::init_dbserver()
if( dbnode.empty() ) if( dbnode.empty() )
dbnode = "localhost"; dbnode = "localhost";
if( ulog.debugging(DBLogInfoLevel) ) dblog << myname << "(init): connect dbnode=" << dbnode
ulog[DBLogInfoLevel] << myname << "(init): connect dbnode=" << dbnode
<< "\tdbname=" << dbname << "\tdbname=" << dbname
<< " pingTime=" << PingTime << " pingTime=" << PingTime
<< " ReconnectTime=" << ReconnectTime << endl; << " ReconnectTime=" << ReconnectTime << endl;
...@@ -323,8 +318,7 @@ void DBServer_MySQL::init_dbserver() ...@@ -323,8 +318,7 @@ void DBServer_MySQL::init_dbserver()
} }
else else
{ {
if( ulog.debugging(DBLogInfoLevel) ) dblog << myname << "(init): connect [OK]" << endl;
ulog[DBLogInfoLevel] << myname << "(init): connect [OK]" << endl;
connect_ok = true; connect_ok = true;
askTimer(DBServer_MySQL::ReconnectTimer,0); askTimer(DBServer_MySQL::ReconnectTimer,0);
askTimer(DBServer_MySQL::PingTimer,PingTime); askTimer(DBServer_MySQL::PingTimer,PingTime);
...@@ -350,8 +344,7 @@ void DBServer_MySQL::createTables( MySQLInterface *db ) ...@@ -350,8 +344,7 @@ void DBServer_MySQL::createTables( MySQLInterface *db )
{ {
if( it.getName() != "comment" ) if( it.getName() != "comment" )
{ {
if( ulog.debugging(DBLogInfoLevel) ) dblog << myname << "(createTables): create " << it.getName() << endl;
ulog[DBLogInfoLevel] << myname << "(createTables): create " << it.getName() << endl;
ostringstream query; ostringstream query;
query << "CREATE TABLE " << conf->getProp(it,"name") << "(" << conf->getProp(it,"create") << ")"; query << "CREATE TABLE " << conf->getProp(it,"name") << "(" << conf->getProp(it,"create") << ")";
if( !db->query(query.str()) ) if( !db->query(query.str()) )
...@@ -376,16 +369,14 @@ void DBServer_MySQL::timerInfo( const UniSetTypes::TimerMessage* tm ) ...@@ -376,16 +369,14 @@ void DBServer_MySQL::timerInfo( const UniSetTypes::TimerMessage* tm )
else else
{ {
connect_ok = true; connect_ok = true;
if( ulog.debugging(DBLogInfoLevel) ) dblog << myname << "(timerInfo): DB ping ok" << endl;
ulog[DBLogInfoLevel] << myname << "(timerInfo): DB ping ok" << endl;
} }
} }
break; break;
case DBServer_MySQL::ReconnectTimer: case DBServer_MySQL::ReconnectTimer:
{ {
if( ulog.debugging(DBLogInfoLevel) ) dblog << myname << "(timerInfo): reconnect timer" << endl;
ulog[DBLogInfoLevel] << myname << "(timerInfo): reconnect timer" << endl;
if( db->isConnection() ) if( db->isConnection() )
{ {
if( db->ping() ) if( db->ping() )
......
...@@ -32,7 +32,7 @@ int main(int argc, char** argv) ...@@ -32,7 +32,7 @@ int main(int argc, char** argv)
{ {
if( ID != UniSetTypes::DefaultObjectId ) if( ID != UniSetTypes::DefaultObjectId )
{ {
ulog.warn() << "(DBServer::main): переопределяем ID заданнй в " uwarn << "(DBServer::main): переопределяем ID заданный в "
<< conf->getConfFileName() << endl; << conf->getConfFileName() << endl;
} }
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "Debug.h" #include "Debug.h"
#include "UniXML.h" #include "UniXML.h"
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
#define dblog if( ulog()->debugging(DBLogInfoLevel) ) (*(ulog().get()))[DBLogInfoLevel]
using namespace UniSetTypes; using namespace UniSetTypes;
using namespace std; using namespace std;
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
...@@ -126,8 +127,7 @@ void DBServer_SQLite::confirmInfo( const UniSetTypes::ConfirmMessage* cem ) ...@@ -126,8 +127,7 @@ void DBServer_SQLite::confirmInfo( const UniSetTypes::ConfirmMessage* cem )
<< " AND time='" << timeToString(cem->time, ":") <<" '" << " AND time='" << timeToString(cem->time, ":") <<" '"
<< " AND time_usec='" << cem->time_usec <<" '"; << " AND time_usec='" << cem->time_usec <<" '";
if( ulog.debugging(DBLEVEL) ) dblog << myname << "(update_confirm): " << data.str() << endl;
ulog[DBLEVEL] << myname << "(update_confirm): " << data.str() << endl;
if( !writeToBase(data.str()) ) if( !writeToBase(data.str()) )
{ {
...@@ -146,8 +146,7 @@ void DBServer_SQLite::confirmInfo( const UniSetTypes::ConfirmMessage* cem ) ...@@ -146,8 +146,7 @@ void DBServer_SQLite::confirmInfo( const UniSetTypes::ConfirmMessage* cem )
//-------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------
bool DBServer_SQLite::writeToBase( const string& query ) bool DBServer_SQLite::writeToBase( const string& query )
{ {
if( ulog.debugging(DBLogInfoLevel) ) dblog << myname << "(writeToBase): " << query << endl;
ulog[DBLogInfoLevel] << myname << "(writeToBase): " << query << endl;
// cout << "DBServer_SQLite: " << query << endl; // cout << "DBServer_SQLite: " << query << endl;
if( !db || !connect_ok ) if( !db || !connect_ok )
{ {
...@@ -220,8 +219,7 @@ void DBServer_SQLite::sensorInfo( const UniSetTypes::SensorMessage *si ) ...@@ -220,8 +219,7 @@ void DBServer_SQLite::sensorInfo( const UniSetTypes::SensorMessage *si )
<< val << "','" // value << val << "','" // value
<< si->node << "')"; // node << si->node << "')"; // node
if( ulog.debugging(DBLEVEL) ) dblog << myname << "(insert_main_history): " << data.str() << endl;
ulog[DBLEVEL] << myname << "(insert_main_history): " << data.str() << endl;
if( !writeToBase(data.str()) ) if( !writeToBase(data.str()) )
{ {
...@@ -241,8 +239,7 @@ void DBServer_SQLite::sensorInfo( const UniSetTypes::SensorMessage *si ) ...@@ -241,8 +239,7 @@ void DBServer_SQLite::sensorInfo( const UniSetTypes::SensorMessage *si )
void DBServer_SQLite::init_dbserver() void DBServer_SQLite::init_dbserver()
{ {
DBServer::init_dbserver(); DBServer::init_dbserver();
if( ulog.debugging(DBLogInfoLevel) ) dblog << myname << "(init): ..." << endl;
ulog[DBLogInfoLevel] << myname << "(init): ..." << endl;
if( connect_ok ) if( connect_ok )
{ {
...@@ -268,7 +265,7 @@ void DBServer_SQLite::init_dbserver() ...@@ -268,7 +265,7 @@ void DBServer_SQLite::init_dbserver()
UniXML::iterator it(node); UniXML::iterator it(node);
ulog[DBLogInfoLevel] << myname << "(init): init connection.." << endl; dblog << myname << "(init): init connection.." << endl;
string dbfile(conf->getProp(node,"dbfile")); string dbfile(conf->getProp(node,"dbfile"));
tblMap[UniSetTypes::Message::SensorInfo] = "main_history"; tblMap[UniSetTypes::Message::SensorInfo] = "main_history";
...@@ -285,8 +282,7 @@ void DBServer_SQLite::init_dbserver() ...@@ -285,8 +282,7 @@ void DBServer_SQLite::init_dbserver()
else else
lastRemove = false; lastRemove = false;
if( ulog.debugging(DBLogInfoLevel) ) dblog << myname << "(init): connect dbfile=" << dbfile
ulog[DBLogInfoLevel] << myname << "(init): connect dbfile=" << dbfile
<< " pingTime=" << PingTime << " pingTime=" << PingTime
<< " ReconnectTime=" << ReconnectTime << endl; << " ReconnectTime=" << ReconnectTime << endl;
...@@ -301,8 +297,7 @@ void DBServer_SQLite::init_dbserver() ...@@ -301,8 +297,7 @@ void DBServer_SQLite::init_dbserver()
} }
else else
{ {
if( ulog.debugging(DBLogInfoLevel) ) dblog << myname << "(init): connect [OK]" << endl;
ulog[DBLogInfoLevel] << myname << "(init): connect [OK]" << endl;
connect_ok = true; connect_ok = true;
askTimer(DBServer_SQLite::ReconnectTimer,0); askTimer(DBServer_SQLite::ReconnectTimer,0);
askTimer(DBServer_SQLite::PingTimer,PingTime); askTimer(DBServer_SQLite::PingTimer,PingTime);
...@@ -327,8 +322,7 @@ void DBServer_SQLite::createTables( SQLiteInterface *db ) ...@@ -327,8 +322,7 @@ void DBServer_SQLite::createTables( SQLiteInterface *db )
{ {
if( it.getName() != "comment" ) if( it.getName() != "comment" )
{ {
if( ulog.debugging(DBLogInfoLevel) ) dblog << myname << "(createTables): create " << it.getName() << endl;
ulog[DBLogInfoLevel] << myname << "(createTables): create " << it.getName() << endl;
ostringstream query; ostringstream query;
query << "CREATE TABLE " << conf->getProp(it,"name") << "(" << conf->getProp(it,"create") << ")"; query << "CREATE TABLE " << conf->getProp(it,"name") << "(" << conf->getProp(it,"create") << ")";
if( !db->query(query.str()) ) if( !db->query(query.str()) )
...@@ -353,16 +347,14 @@ void DBServer_SQLite::timerInfo( const UniSetTypes::TimerMessage* tm ) ...@@ -353,16 +347,14 @@ void DBServer_SQLite::timerInfo( const UniSetTypes::TimerMessage* tm )
else else
{ {
connect_ok = true; connect_ok = true;
if( ulog.debugging(DBLogInfoLevel) ) dblog << myname << "(timerInfo): DB ping ok" << endl;
ulog[DBLogInfoLevel] << myname << "(timerInfo): DB ping ok" << endl;
} }
} }
break; break;
case DBServer_SQLite::ReconnectTimer: case DBServer_SQLite::ReconnectTimer:
{ {
if( ulog.debugging(DBLogInfoLevel) ) dblog << myname << "(timerInfo): reconnect timer" << endl;
ulog[DBLogInfoLevel] << myname << "(timerInfo): reconnect timer" << endl;
if( db->isConnection() ) if( db->isConnection() )
{ {
if( db->ping() ) if( db->ping() )
......
...@@ -32,7 +32,7 @@ int main(int argc, char** argv) ...@@ -32,7 +32,7 @@ int main(int argc, char** argv)
{ {
if( ID != UniSetTypes::DefaultObjectId ) if( ID != UniSetTypes::DefaultObjectId )
{ {
ulog.warn() << "(DBServer::main): переопределяем ID заданнй в " uwarn << "(DBServer::main): переопределяем ID заданнй в "
<< conf->getConfFileName() << endl; << conf->getConfFileName() << endl;
} }
......
...@@ -718,7 +718,7 @@ bool IOControl::initIOItem( UniXML::iterator& it ) ...@@ -718,7 +718,7 @@ bool IOControl::initIOItem( UniXML::iterator& it )
std::string prop_prefix( prefix+"_" ); std::string prop_prefix( prefix+"_" );
if( !IOBase::initItem(&inf,it,shm,prop_prefix,false,&dlog,myname,filtersize,filterT) ) if( !IOBase::initItem(&inf,it,shm,prop_prefix,false,dlog(),myname,filtersize,filterT) )
return false; return false;
// если вектор уже заполнен // если вектор уже заполнен
...@@ -733,8 +733,7 @@ bool IOControl::initIOItem( UniXML::iterator& it ) ...@@ -733,8 +733,7 @@ bool IOControl::initIOItem( UniXML::iterator& it )
{ {
IOPriority p(prior,maxItem); IOPriority p(prior,maxItem);
pmap.push_back(p); pmap.push_back(p);
if( dlog.debugging(Debug::LEVEL3) ) dlog3 << myname << "(readItem): add to priority list: " <<
dlog[Debug::LEVEL3] << myname << "(readItem): add to priority list: " <<
it.getProp("name") it.getProp("name")
<< " priority=" << prior << endl; << " priority=" << prior << endl;
} }
...@@ -743,8 +742,7 @@ bool IOControl::initIOItem( UniXML::iterator& it ) ...@@ -743,8 +742,7 @@ bool IOControl::initIOItem( UniXML::iterator& it )
if( inf.t_ai != DefaultObjectId ) if( inf.t_ai != DefaultObjectId )
{ {
iomap[maxItem++] = std::move(inf); iomap[maxItem++] = std::move(inf);
if( dlog.debugging(Debug::LEVEL3) ) dlog3 << myname << "(readItem): add threshold '" << it.getProp("name")
dlog[Debug::LEVEL3] << myname << "(readItem): add threshold '" << it.getProp("name")
<< " for '" << uniset_conf()->oind->getNameById(inf.t_ai) << endl; << " for '" << uniset_conf()->oind->getNameById(inf.t_ai) << endl;
return true; return true;
} }
...@@ -1224,20 +1222,20 @@ void IOControl::sysCommand( const SystemMessage* sm ) ...@@ -1224,20 +1222,20 @@ void IOControl::sysCommand( const SystemMessage* sm )
case SystemMessage::LogRotate: case SystemMessage::LogRotate:
{ {
// переоткрываем логи // переоткрываем логи
ulog << myname << "(sysCommand): logRotate" << endl; ulogany << myname << "(sysCommand): logRotate" << endl;
string fname( ulog.getLogFile() ); string fname( ulog()->getLogFile() );
if( !fname.empty() ) if( !fname.empty() )
{ {
ulog.logFile(fname,true); ulog()->logFile(fname,true);
ulog << myname << "(sysCommand): ***************** ulog LOG ROTATE *****************" << endl; ulogany << myname << "(sysCommand): ***************** ulog LOG ROTATE *****************" << endl;
} }
dlog << myname << "(sysCommand): logRotate" << endl; dlogany << myname << "(sysCommand): logRotate" << endl;
fname = dlog.getLogFile(); fname = dlog()->getLogFile();
if( !fname.empty() ) if( !fname.empty() )
{ {
dlog.logFile(fname,true); dlog()->logFile(fname,true);
dlog << myname << "(sysCommand): ***************** GGDEB LOG ROTATE *****************" << endl; dlogany << myname << "(sysCommand): ***************** GGDEB LOG ROTATE *****************" << endl;
} }
} }
break; break;
......
...@@ -24,11 +24,11 @@ int main(int argc, const char **argv) ...@@ -24,11 +24,11 @@ int main(int argc, const char **argv)
{ {
auto conf = uniset_init(argc, argv); auto conf = uniset_init(argc, argv);
conf->initDebug(dlog,"dlog"); conf->initDebug(dlog(),"dlog");
string logfilename = conf->getArgParam("--io-logfile","iocontrol.log"); string logfilename = conf->getArgParam("--io-logfile","iocontrol.log");
string logname( conf->getLogDir() + logfilename ); string logname( conf->getLogDir() + logfilename );
dlog.logFile( logname ); dlog()->logFile( logname );
ulog.logFile( logname ); ulog()->logFile( logname );
ObjectId shmID = DefaultObjectId; ObjectId shmID = DefaultObjectId;
string sID = conf->getArgParam("--smemory-id"); string sID = conf->getArgParam("--smemory-id");
...@@ -58,10 +58,10 @@ int main(int argc, const char **argv) ...@@ -58,10 +58,10 @@ int main(int argc, const char **argv)
SystemMessage sm(SystemMessage::StartUp); SystemMessage sm(SystemMessage::StartUp);
act->broadcast( sm.transport_msg() ); act->broadcast( sm.transport_msg() );
ulog << "\n\n\n"; ulogany << "\n\n\n";
ulog << "(main): -------------- IOControl START -------------------------\n\n"; ulogany << "(main): -------------- IOControl START -------------------------\n\n";
dlog << "\n\n\n"; dlogany << "\n\n\n";
dlog << "(main): -------------- IOControl START -------------------------\n\n"; dlogany << "(main): -------------- IOControl START -------------------------\n\n";
act->run(true); act->run(true);
msleep(500); msleep(500);
ic->execute(); ic->execute();
......
...@@ -146,20 +146,20 @@ void PassiveLProcessor::sysCommand( const UniSetTypes::SystemMessage *sm ) ...@@ -146,20 +146,20 @@ void PassiveLProcessor::sysCommand( const UniSetTypes::SystemMessage *sm )
case SystemMessage::LogRotate: case SystemMessage::LogRotate:
{ {
// переоткрываем логи // переоткрываем логи
ulog << myname << "(sysCommand): logRotate" << std::endl; ulogany << myname << "(sysCommand): logRotate" << std::endl;
string fname (ulog.getLogFile() ); string fname (ulog()->getLogFile() );
if( !fname.empty() ) if( !fname.empty() )
{ {
ulog.logFile(fname,true); ulog()->logFile(fname,true);
ulog << myname << "(sysCommand): ***************** ulog LOG ROTATE *****************" << std::endl; ulogany << myname << "(sysCommand): ***************** ulog LOG ROTATE *****************" << std::endl;
} }
dlog << myname << "(sysCommand): logRotate" << std::endl; dlogany << myname << "(sysCommand): logRotate" << std::endl;
fname = dlog.getLogFile(); fname = dlog()->getLogFile();
if( !fname.empty() ) if( !fname.empty() )
{ {
dlog.logFile(fname,true); dlog()->logFile(fname,true);
dlog << myname << "(sysCommand): ***************** dlog LOG ROTATE *****************" << std::endl; dlogany << myname << "(sysCommand): ***************** dlog LOG ROTATE *****************" << std::endl;
} }
} }
break; break;
......
...@@ -18,13 +18,13 @@ int main(int argc, const char **argv) ...@@ -18,13 +18,13 @@ int main(int argc, const char **argv)
if( logfilename.empty() ) if( logfilename.empty() )
logfilename = "logicproc.log"; logfilename = "logicproc.log";
conf->initDebug(dlog,"dlog"); conf->initDebug(dlog(),"dlog");
std::ostringstream logname; std::ostringstream logname;
string dir(conf->getLogDir()); string dir(conf->getLogDir());
logname << dir << logfilename; logname << dir << logfilename;
ulog.logFile( logname.str() ); ulog()->logFile( logname.str() );
dlog.logFile( logname.str() ); dlog()->logFile( logname.str() );
string schema = conf->getArgParam("--schema"); string schema = conf->getArgParam("--schema");
if( schema.empty() ) if( schema.empty() )
......
...@@ -20,13 +20,13 @@ int main(int argc, const char **argv) ...@@ -20,13 +20,13 @@ int main(int argc, const char **argv)
if( logfilename.empty() ) if( logfilename.empty() )
logfilename = "logicproc.log"; logfilename = "logicproc.log";
conf->initDebug(dlog,"dlog"); conf->initDebug(dlog(),"dlog");
std::ostringstream logname; std::ostringstream logname;
string dir(conf->getLogDir()); string dir(conf->getLogDir());
logname << dir << logfilename; logname << dir << logfilename;
ulog.logFile( logname.str() ); ulog()->logFile( logname.str() );
dlog.logFile( logname.str() ); dlog()->logFile( logname.str() );
string schema = conf->getArgParam("--schema"); string schema = conf->getArgParam("--schema");
if( schema.empty() ) if( schema.empty() )
...@@ -76,10 +76,10 @@ int main(int argc, const char **argv) ...@@ -76,10 +76,10 @@ int main(int argc, const char **argv)
SystemMessage sm(SystemMessage::StartUp); SystemMessage sm(SystemMessage::StartUp);
act->broadcast( sm.transport_msg() ); act->broadcast( sm.transport_msg() );
ulog << "\n\n\n"; ulogany << "\n\n\n";
ulog << "(main): -------------- IOControl START -------------------------\n\n"; ulogany << "(main): -------------- IOControl START -------------------------\n\n";
dlog << "\n\n\n"; dlogany << "\n\n\n";
dlog << "(main): -------------- IOControl START -------------------------\n\n"; dlogany << "(main): -------------- IOControl START -------------------------\n\n";
act->run(false); act->run(false);
return 0; return 0;
} }
......
...@@ -582,7 +582,7 @@ bool MBExchange::preInitRead( InitList::iterator& p ) ...@@ -582,7 +582,7 @@ bool MBExchange::preInitRead( InitList::iterator& p )
RTUDevice* dev = p->dev; RTUDevice* dev = p->dev;
int q_count = p->p.rnum; int q_count = p->p.rnum;
if( dlog.is_level3() ) if( dlog()->is_level3() )
{ {
dlog3 << myname << "(preInitRead): poll " dlog3 << myname << "(preInitRead): poll "
<< " mbaddr=" << ModbusRTU::addr2str(dev->mbaddr) << " mbaddr=" << ModbusRTU::addr2str(dev->mbaddr)
...@@ -817,7 +817,7 @@ bool MBExchange::pollRTU( RTUDevice* dev, RegMap::iterator& it ) ...@@ -817,7 +817,7 @@ bool MBExchange::pollRTU( RTUDevice* dev, RegMap::iterator& it )
return false; return false;
} }
if( dlog.debugging(Debug::LEVEL3) ) if( dlog()->is_level3() )
{ {
dlog3 << myname << "(pollRTU): poll " dlog3 << myname << "(pollRTU): poll "
<< " mbaddr=" << ModbusRTU::addr2str(dev->mbaddr) << " mbaddr=" << ModbusRTU::addr2str(dev->mbaddr)
...@@ -1887,7 +1887,7 @@ MBExchange::RSProperty* MBExchange::addProp( PList& plist, RSProperty&& p ) ...@@ -1887,7 +1887,7 @@ MBExchange::RSProperty* MBExchange::addProp( PList& plist, RSProperty&& p )
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
bool MBExchange::initRSProperty( RSProperty& p, UniXML::iterator& it ) bool MBExchange::initRSProperty( RSProperty& p, UniXML::iterator& it )
{ {
if( !IOBase::initItem(&p,it,shm,prop_prefix,false,&dlog,myname) ) if( !IOBase::initItem(&p,it,shm,prop_prefix,false,dlog(),myname) )
return false; return false;
// проверяем не пороговый ли это датчик (т.е. не связанный с обменом) // проверяем не пороговый ли это датчик (т.е. не связанный с обменом)
...@@ -2570,19 +2570,19 @@ void MBExchange::sysCommand( const UniSetTypes::SystemMessage *sm ) ...@@ -2570,19 +2570,19 @@ void MBExchange::sysCommand( const UniSetTypes::SystemMessage *sm )
case SystemMessage::LogRotate: case SystemMessage::LogRotate:
{ {
// переоткрываем логи // переоткрываем логи
ulog << myname << "(sysCommand): logRotate" << std::endl; ulogany << myname << "(sysCommand): logRotate" << std::endl;
string fname(ulog.getLogFile()); string fname(ulog()->getLogFile());
if( !fname.empty() ) if( !fname.empty() )
{ {
ulog.logFile(fname,true); ulog()->logFile(fname,true);
ulog << myname << "(sysCommand): ***************** ulog LOG ROTATE *****************" << std::endl; ulogany << myname << "(sysCommand): ***************** ulog LOG ROTATE *****************" << std::endl;
} }
dlog << myname << "(sysCommand): logRotate" << std::endl; dlogany << myname << "(sysCommand): logRotate" << std::endl;
fname = dlog.getLogFile(); fname = dlog()->getLogFile();
if( !fname.empty() ) if( !fname.empty() )
{ {
dlog.logFile(fname,true); dlog()->logFile(fname,true);
dlog << myname << "(sysCommand): ***************** dlog LOG ROTATE *****************" << std::endl; dlogany << myname << "(sysCommand): ***************** dlog LOG ROTATE *****************" << std::endl;
} }
} }
break; break;
...@@ -2799,7 +2799,7 @@ bool MBExchange::poll() ...@@ -2799,7 +2799,7 @@ bool MBExchange::poll()
// { // {
dlog3 << myname << "(poll): FAILED ask addr=" << ModbusRTU::addr2str(d->mbaddr) dlog3 << myname << "(poll): FAILED ask addr=" << ModbusRTU::addr2str(d->mbaddr)
<< " reg=" << ModbusRTU::dat2str(it->second->mbreg) << " reg=" << ModbusRTU::dat2str(it->second->mbreg)
<< " for sensors: "; print_plist(dlog(Debug::LEVEL3),it->second->slst) << " for sensors: "; print_plist(dlog()->level3(),it->second->slst)
<< endl << " err: " << ex << endl; << endl << " err: " << ex << endl;
// d->resp_real = false; // d->resp_real = false;
......
...@@ -72,7 +72,7 @@ pollThread(0) ...@@ -72,7 +72,7 @@ pollThread(0)
pollThread = new ThreadCreator<MBTCPMaster>(this, &MBTCPMaster::poll_thread); pollThread = new ThreadCreator<MBTCPMaster>(this, &MBTCPMaster::poll_thread);
pollThread->setFinalAction(this,&MBTCPMaster::final_thread); pollThread->setFinalAction(this,&MBTCPMaster::final_thread);
if( dlog.is_info() ) if( dlog()->is_info() )
printMap(rmap); printMap(rmap);
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
...@@ -117,8 +117,8 @@ std::shared_ptr<ModbusClient> MBTCPMaster::initMB( bool reopen ) ...@@ -117,8 +117,8 @@ std::shared_ptr<ModbusClient> MBTCPMaster::initMB( bool reopen )
dinfo << myname << "(init): ipaddr=" << iaddr << " port=" << port << endl; dinfo << myname << "(init): ipaddr=" << iaddr << " port=" << port << endl;
if( dlog.is_level9() ) if( dlog()->is_level9() )
mbtcp->setLog(dlog); mbtcp->setLog(dlog());
} }
catch( ModbusRTU::mbException& ex ) catch( ModbusRTU::mbException& ex )
{ {
......
...@@ -116,8 +116,8 @@ checkThread(0) ...@@ -116,8 +116,8 @@ checkThread(0)
n << sinf.ip << ":" << sinf.port; n << sinf.ip << ":" << sinf.port;
sinf.myname = n.str(); sinf.myname = n.str();
if( dlog.is_level9() ) if( dlog()->is_level9() )
sinf.mbtcp->setLog(dlog); sinf.mbtcp->setLog(dlog());
mblist.push_back(sinf); mblist.push_back(sinf);
...@@ -154,7 +154,7 @@ checkThread(0) ...@@ -154,7 +154,7 @@ checkThread(0)
// неудачной попытки запросов по одному из каналов, то ПЕРЕОПРЕДЕЛЯЕМ reopen, на timeout.. // неудачной попытки запросов по одному из каналов, то ПЕРЕОПРЕДЕЛЯЕМ reopen, на timeout..
ptReopen.setTiming(ptTimeout.getInterval()); ptReopen.setTiming(ptTimeout.getInterval());
if( dlog.is_info() ) if( dlog()->is_info() )
printMap(rmap); printMap(rmap);
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
......
...@@ -71,7 +71,7 @@ rs_pre_clean(false) ...@@ -71,7 +71,7 @@ rs_pre_clean(false)
initMB(false); initMB(false);
if( dlog.is_info() ) if( dlog()->is_info() )
printMap(rmap); printMap(rmap);
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
...@@ -123,8 +123,8 @@ std::shared_ptr<ModbusClient> RTUExchange::initMB( bool reopen ) ...@@ -123,8 +123,8 @@ std::shared_ptr<ModbusClient> RTUExchange::initMB( bool reopen )
if( defSpeed != ComPort::ComSpeed0 ) if( defSpeed != ComPort::ComSpeed0 )
mbrtu->setSpeed(defSpeed); mbrtu->setSpeed(defSpeed);
if( dlog.debugging(Debug::LEVEL9) ) if( dlog()->is_level9() )
mbrtu->setLog(dlog); mbrtu->setLog(dlog());
if( recv_timeout > 0 ) if( recv_timeout > 0 )
mbrtu->setTimeout(recv_timeout); mbrtu->setTimeout(recv_timeout);
...@@ -271,8 +271,8 @@ bool RTUExchange::poll() ...@@ -271,8 +271,8 @@ bool RTUExchange::poll()
// { // {
dlog3 << myname << "(poll): FAILED ask addr=" << ModbusRTU::addr2str(d->mbaddr) dlog3 << myname << "(poll): FAILED ask addr=" << ModbusRTU::addr2str(d->mbaddr)
<< " reg=" << ModbusRTU::dat2str(it->second->mbreg) << " reg=" << ModbusRTU::dat2str(it->second->mbreg)
<< " for sensors: "; print_plist(dlog(Debug::LEVEL3), it->second->slst); << " for sensors: "; print_plist(dlog()->level3(), it->second->slst);
dlog(Debug::LEVEL3) << " err: " << ex << endl; dlog()->level3() << " err: " << ex << endl;
// d->resp_real = false; // d->resp_real = false;
// } // }
......
...@@ -30,13 +30,13 @@ int main( int argc, const char** argv ) ...@@ -30,13 +30,13 @@ int main( int argc, const char** argv )
if( logfilename.empty() ) if( logfilename.empty() )
logfilename = "mbtcpmaster.log"; logfilename = "mbtcpmaster.log";
conf->initDebug(dlog,"dlog"); conf->initDebug(dlog(),"dlog");
std::ostringstream logname; std::ostringstream logname;
string dir(conf->getLogDir()); string dir(conf->getLogDir());
logname << dir << logfilename; logname << dir << logfilename;
ulog.logFile( logname.str() ); ulog()->logFile( logname.str() );
dlog.logFile( logname.str() ); dlog()->logFile( logname.str() );
ObjectId shmID = DefaultObjectId; ObjectId shmID = DefaultObjectId;
string sID = conf->getArgParam("--smemory-id"); string sID = conf->getArgParam("--smemory-id");
...@@ -64,12 +64,11 @@ int main( int argc, const char** argv ) ...@@ -64,12 +64,11 @@ int main( int argc, const char** argv )
SystemMessage sm(SystemMessage::StartUp); SystemMessage sm(SystemMessage::StartUp);
act->broadcast( sm.transport_msg() ); act->broadcast( sm.transport_msg() );
ulog << "\n\n\n"; ulogany << "\n\n\n";
ulog << "(main): -------------- MBTCP Exchange START -------------------------\n\n"; ulogany << "(main): -------------- MBTCP Exchange START -------------------------\n\n";
dlog << "\n\n\n"; dlogany << "\n\n\n";
dlog << "(main): -------------- MBTCP Exchange START -------------------------\n\n"; dlogany << "(main): -------------- MBTCP Exchange START -------------------------\n\n";
act->run(false); act->run(false);
on_sigchild(SIGTERM);
return 0; return 0;
} }
catch( Exception& ex ) catch( Exception& ex )
...@@ -84,6 +83,5 @@ int main( int argc, const char** argv ) ...@@ -84,6 +83,5 @@ int main( int argc, const char** argv )
dcrit << "(mbtcpmaster): catch ..." << std::endl; dcrit << "(mbtcpmaster): catch ..." << std::endl;
} }
on_sigchild(SIGTERM);
return 1; return 1;
} }
...@@ -67,7 +67,7 @@ int main( int argc, char **argv ) ...@@ -67,7 +67,7 @@ int main( int argc, char **argv )
ModbusRTU::ModbusData reg = 0; ModbusRTU::ModbusData reg = 0;
ModbusRTU::ModbusAddr slaveaddr = 0x00; ModbusRTU::ModbusAddr slaveaddr = 0x00;
int tout = 2000; int tout = 2000;
DebugStream dlog; auto dlog = make_shared<DebugStream>();
// string tofile(""); // string tofile("");
int use485 = 0; int use485 = 0;
int ncycles = -1; int ncycles = -1;
...@@ -169,7 +169,7 @@ int main( int argc, char **argv ) ...@@ -169,7 +169,7 @@ int main( int argc, char **argv )
ModbusRTUMaster mb(dev,use485); ModbusRTUMaster mb(dev,use485);
if( verb ) if( verb )
dlog.addLevel(Debug::ANY); dlog->addLevel(Debug::ANY);
mb.setTimeout(tout); mb.setTimeout(tout);
mb.setSpeed(speed); mb.setSpeed(speed);
......
...@@ -88,7 +88,7 @@ int main( int argc, char **argv ) ...@@ -88,7 +88,7 @@ int main( int argc, char **argv )
ModbusRTU::ModbusAddr beg = 0; ModbusRTU::ModbusAddr beg = 0;
ModbusRTU::ModbusAddr end = 255; ModbusRTU::ModbusAddr end = 255;
int tout = 20; int tout = 20;
DebugStream dlog; auto dlog = make_shared<DebugStream>();
//string tofile(""); //string tofile("");
int use485 = 0; int use485 = 0;
ComPort::StopBits sbits = ComPort::OneBit; ComPort::StopBits sbits = ComPort::OneBit;
...@@ -233,7 +233,7 @@ int main( int argc, char **argv ) ...@@ -233,7 +233,7 @@ int main( int argc, char **argv )
ModbusRTUMaster mb(dev,use485); ModbusRTUMaster mb(dev,use485);
if( verb ) if( verb )
dlog.addLevel( Debug::type(Debug::CRIT | Debug::WARN | Debug::INFO) ); dlog->addLevel( Debug::type(Debug::CRIT | Debug::WARN | Debug::INFO) );
mb.setTimeout(tout); mb.setTimeout(tout);
mb.setSpeed(speed); mb.setSpeed(speed);
......
...@@ -29,13 +29,13 @@ int main( int argc, const char** argv ) ...@@ -29,13 +29,13 @@ int main( int argc, const char** argv )
if( logfilename.empty() ) if( logfilename.empty() )
logfilename = "mbtcpmultimaster.log"; logfilename = "mbtcpmultimaster.log";
conf->initDebug(dlog,"dlog"); conf->initDebug(dlog(),"dlog");
std::ostringstream logname; std::ostringstream logname;
string dir(conf->getLogDir()); string dir(conf->getLogDir());
logname << dir << logfilename; logname << dir << logfilename;
ulog.logFile( logname.str() ); ulog()->logFile( logname.str() );
dlog.logFile( logname.str() ); dlog()->logFile( logname.str() );
ObjectId shmID = DefaultObjectId; ObjectId shmID = DefaultObjectId;
string sID = conf->getArgParam("--smemory-id"); string sID = conf->getArgParam("--smemory-id");
...@@ -63,14 +63,12 @@ int main( int argc, const char** argv ) ...@@ -63,14 +63,12 @@ int main( int argc, const char** argv )
SystemMessage sm(SystemMessage::StartUp); SystemMessage sm(SystemMessage::StartUp);
act->broadcast( sm.transport_msg() ); act->broadcast( sm.transport_msg() );
ulog << "\n\n\n"; ulogany << "\n\n\n";
ulog << "(main): -------------- MBTCPMulti Exchange START -------------------------\n\n"; ulogany << "(main): -------------- MBTCPMulti Exchange START -------------------------\n\n";
dlog << "\n\n\n"; dlogany << "\n\n\n";
dlog << "(main): -------------- MBTCPMulti Exchange START -------------------------\n\n"; dlogany << "(main): -------------- MBTCPMulti Exchange START -------------------------\n\n";
act->run(false); act->run(false);
on_sigchild(SIGTERM);
return 0; return 0;
} }
catch( Exception& ex ) catch( Exception& ex )
...@@ -82,6 +80,5 @@ int main( int argc, const char** argv ) ...@@ -82,6 +80,5 @@ int main( int argc, const char** argv )
dcrit << "(mbtcpmultimaster): catch ..." << std::endl; dcrit << "(mbtcpmultimaster): catch ..." << std::endl;
} }
on_sigchild(SIGTERM);
return 1; return 1;
} }
...@@ -28,13 +28,13 @@ int main( int argc, char** argv ) ...@@ -28,13 +28,13 @@ int main( int argc, char** argv )
if( logfilename.empty() ) if( logfilename.empty() )
logfilename = "rtuexchange.log"; logfilename = "rtuexchange.log";
conf->initDebug(dlog,"dlog"); conf->initDebug(dlog(),"dlog");
std::ostringstream logname; std::ostringstream logname;
string dir(conf->getLogDir()); string dir(conf->getLogDir());
logname << dir << logfilename; logname << dir << logfilename;
ulog.logFile( logname.str() ); ulog()->logFile( logname.str() );
dlog.logFile( logname.str() ); dlog()->logFile( logname.str() );
ObjectId shmID = DefaultObjectId; ObjectId shmID = DefaultObjectId;
string sID = conf->getArgParam("--smemory-id"); string sID = conf->getArgParam("--smemory-id");
...@@ -62,14 +62,12 @@ int main( int argc, char** argv ) ...@@ -62,14 +62,12 @@ int main( int argc, char** argv )
SystemMessage sm(SystemMessage::StartUp); SystemMessage sm(SystemMessage::StartUp);
act->broadcast( sm.transport_msg() ); act->broadcast( sm.transport_msg() );
ulog << "\n\n\n"; ulogany << "\n\n\n";
ulog << "(main): -------------- RTU Exchange START -------------------------\n\n"; ulogany << "(main): -------------- RTU Exchange START -------------------------\n\n";
dlog << "\n\n\n"; dlogany << "\n\n\n";
dlog << "(main): -------------- RTU Exchange START -------------------------\n\n"; dlogany << "(main): -------------- RTU Exchange START -------------------------\n\n";
act->run(false); act->run(false);
on_sigchild(SIGTERM);
return 0; return 0;
} }
catch( Exception& ex ) catch( Exception& ex )
...@@ -81,6 +79,5 @@ int main( int argc, char** argv ) ...@@ -81,6 +79,5 @@ int main( int argc, char** argv )
dcrit << "(rtuexchange): catch ..." << std::endl; dcrit << "(rtuexchange): catch ..." << std::endl;
} }
on_sigchild(SIGTERM);
return 1; return 1;
} }
...@@ -38,7 +38,7 @@ int main( int argc, char **argv ) ...@@ -38,7 +38,7 @@ int main( int argc, char **argv )
string speed("38400"); string speed("38400");
ModbusRTU::ModbusAddr slaveaddr = 0x01; ModbusRTU::ModbusAddr slaveaddr = 0x01;
int tout = 2000; int tout = 2000;
DebugStream dlog; auto dlog = make_shared<DebugStream>();
int use485 = 0; int use485 = 0;
try try
...@@ -93,7 +93,7 @@ int main( int argc, char **argv ) ...@@ -93,7 +93,7 @@ int main( int argc, char **argv )
std::shared_ptr<ModbusRTUMaster> mb = std::make_shared<ModbusRTUMaster>(dev,use485); std::shared_ptr<ModbusRTUMaster> mb = std::make_shared<ModbusRTUMaster>(dev,use485);
if( verb ) if( verb )
dlog.addLevel( Debug::type(Debug::CRIT | Debug::WARN | Debug::INFO) ); dlog->addLevel( Debug::type(Debug::CRIT | Debug::WARN | Debug::INFO) );
mb->setTimeout(tout); mb->setTimeout(tout);
mb->setSpeed(speed); mb->setSpeed(speed);
......
...@@ -80,7 +80,7 @@ MBTCPTestServer::~MBTCPTestServer() ...@@ -80,7 +80,7 @@ MBTCPTestServer::~MBTCPTestServer()
delete sslot; delete sslot;
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
void MBTCPTestServer::setLog( DebugStream& dlog ) void MBTCPTestServer::setLog( std::shared_ptr<DebugStream> dlog )
{ {
if( sslot ) if( sslot )
sslot->setLog(dlog); sslot->setLog(dlog);
......
...@@ -33,7 +33,7 @@ class MBTCPTestServer ...@@ -33,7 +33,7 @@ class MBTCPTestServer
void runThread(); /*!< запуск с отдельным потоком */ void runThread(); /*!< запуск с отдельным потоком */
void execute(); /*!< основной цикл работы */ void execute(); /*!< основной цикл работы */
void setLog( DebugStream& dlog ); void setLog( std::shared_ptr<DebugStream> dlog );
inline bool isRunning(){ return isrunning; } inline bool isRunning(){ return isrunning; }
......
...@@ -32,8 +32,8 @@ int main(int argc, char* argv[] ) ...@@ -32,8 +32,8 @@ int main(int argc, char* argv[] )
try try
{ {
auto conf = uniset_init(argc,argv); auto conf = uniset_init(argc,argv);
conf->initDebug(dlog,"dlog"); conf->initDebug(dlog(),"dlog");
dlog.logFile("./smtest.log"); dlog()->logFile("./smtest.log");
bool apart = findArgParam("--apart",argc,argv) != -1; bool apart = findArgParam("--apart",argc,argv) != -1;
......
...@@ -32,8 +32,8 @@ int main(int argc, char* argv[] ) ...@@ -32,8 +32,8 @@ int main(int argc, char* argv[] )
try try
{ {
auto conf = uniset_init(argc,argv); auto conf = uniset_init(argc,argv);
conf->initDebug(dlog,"dlog"); conf->initDebug(dlog(),"dlog");
dlog.logFile("./smtest.log"); dlog()->logFile("./smtest.log");
bool apart = findArgParam("--apart",argc,argv) != -1; bool apart = findArgParam("--apart",argc,argv) != -1;
......
...@@ -92,7 +92,7 @@ prefix(prefix) ...@@ -92,7 +92,7 @@ prefix(prefix)
rs->setRecvTimeout(2000); rs->setRecvTimeout(2000);
rs->setAfterSendPause(aftersend_pause); rs->setAfterSendPause(aftersend_pause);
rs->setReplyTimeout(reply_tout); rs->setReplyTimeout(reply_tout);
rs->setLog(dlog); rs->setLog(dlog());
mbslot = std::static_pointer_cast<ModbusServerSlot>(rs); mbslot = std::static_pointer_cast<ModbusServerSlot>(rs);
thr = make_shared< ThreadCreator<MBSlave> >(this,&MBSlave::execute_rtu); thr = make_shared< ThreadCreator<MBSlave> >(this,&MBSlave::execute_rtu);
...@@ -122,8 +122,8 @@ prefix(prefix) ...@@ -122,8 +122,8 @@ prefix(prefix)
thr->setFinalAction(this,&MBSlave::finalThread); thr->setFinalAction(this,&MBSlave::finalThread);
dinfo << myname << "(init): init TCP connection ok. " << " inet=" << iaddr << " port=" << port << endl; dinfo << myname << "(init): init TCP connection ok. " << " inet=" << iaddr << " port=" << port << endl;
if( dlog.debugging(Debug::LEVEL9) ) if( dlog()->is_level9() )
mbtcp->setLog(dlog); mbtcp->setLog(dlog());
} }
else else
throw UniSetTypes::SystemError(myname+"(MBSlave): Unknown slave type. Use: --mbs-type [RTU|TCP]"); throw UniSetTypes::SystemError(myname+"(MBSlave): Unknown slave type. Use: --mbs-type [RTU|TCP]");
...@@ -626,20 +626,20 @@ void MBSlave::sysCommand( const UniSetTypes::SystemMessage *sm ) ...@@ -626,20 +626,20 @@ void MBSlave::sysCommand( const UniSetTypes::SystemMessage *sm )
case SystemMessage::LogRotate: case SystemMessage::LogRotate:
{ {
// переоткрываем логи // переоткрываем логи
ulog << myname << "(sysCommand): logRotate" << std::endl; ulogany << myname << "(sysCommand): logRotate" << std::endl;
string fname(ulog.getLogFile()); string fname(ulog()->getLogFile());
if( !fname.empty() ) if( !fname.empty() )
{ {
ulog.logFile(fname,true); ulog()->logFile(fname,true);
ulog << myname << "(sysCommand): ***************** ulog LOG ROTATE *****************" << std::endl; ulogany << myname << "(sysCommand): ***************** ulog LOG ROTATE *****************" << std::endl;
} }
dlog << myname << "(sysCommand): logRotate" << std::endl; dlogany << myname << "(sysCommand): logRotate" << std::endl;
fname = dlog.getLogFile(); fname = dlog()->getLogFile();
if( !fname.empty() ) if( !fname.empty() )
{ {
dlog.logFile(fname,true); dlog()->logFile(fname,true);
dlog << myname << "(sysCommand): ***************** dlog LOG ROTATE *****************" << std::endl; dlogany << myname << "(sysCommand): ***************** dlog LOG ROTATE *****************" << std::endl;
} }
} }
break; break;
...@@ -816,7 +816,7 @@ bool MBSlave::initItem( UniXML::iterator& it ) ...@@ -816,7 +816,7 @@ bool MBSlave::initItem( UniXML::iterator& it )
string prop_prefix(prefix+"_"); string prop_prefix(prefix+"_");
if( !IOBase::initItem( static_cast<IOBase*>(&p),it,shm,prop_prefix,false,&dlog,myname) ) if( !IOBase::initItem( static_cast<IOBase*>(&p),it,shm,prop_prefix,false,dlog(),myname) )
return false; return false;
if( mbregFromID ) if( mbregFromID )
...@@ -1512,7 +1512,7 @@ mbErrCode MBSlave::readInputRegisters( ReadInputMessage& query, ReadInputRetMess ...@@ -1512,7 +1512,7 @@ mbErrCode MBSlave::readInputRegisters( ReadInputMessage& query, ReadInputRetMess
ModbusRTU::mbErrCode MBSlave::setDateTime( ModbusRTU::SetDateTimeMessage& query, ModbusRTU::mbErrCode MBSlave::setDateTime( ModbusRTU::SetDateTimeMessage& query,
ModbusRTU::SetDateTimeRetMessage& reply ) ModbusRTU::SetDateTimeRetMessage& reply )
{ {
return ModbusServer::replySetDateTime(query,reply,&dlog); return ModbusServer::replySetDateTime(query,reply,dlog());
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
ModbusRTU::mbErrCode MBSlave::remoteService( ModbusRTU::RemoteServiceMessage& query, ModbusRTU::mbErrCode MBSlave::remoteService( ModbusRTU::RemoteServiceMessage& query,
...@@ -1532,7 +1532,7 @@ ModbusRTU::mbErrCode MBSlave::fileTransfer( ModbusRTU::FileTransferMessage& quer ...@@ -1532,7 +1532,7 @@ ModbusRTU::mbErrCode MBSlave::fileTransfer( ModbusRTU::FileTransferMessage& quer
return ModbusRTU::erBadDataValue; return ModbusRTU::erBadDataValue;
std::string fname(it->second); std::string fname(it->second);
return ModbusServer::replyFileTransfer( fname,query,reply,&dlog ); return ModbusServer::replyFileTransfer( fname,query,reply,dlog() );
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
ModbusRTU::mbErrCode MBSlave::readCoilStatus( ReadCoilMessage& query, ModbusRTU::mbErrCode MBSlave::readCoilStatus( ReadCoilMessage& query,
......
...@@ -145,8 +145,8 @@ void MBTCPMultiSlave::execute_tcp() ...@@ -145,8 +145,8 @@ void MBTCPMultiSlave::execute_tcp()
return; return;
} }
if( dlog.debugging(Debug::LEVEL9) ) if( dlog()->is_level9() )
sslot->setLog(dlog); sslot->setLog(dlog());
for( auto &i: cmap ) for( auto &i: cmap )
i.second.ptTimeout.reset(); i.second.ptTimeout.reset();
...@@ -184,8 +184,7 @@ void MBTCPMultiSlave::execute_tcp() ...@@ -184,8 +184,7 @@ void MBTCPMultiSlave::execute_tcp()
{ {
ClientInfo& c(it.second); ClientInfo& c(it.second);
if( dlog.is_level4() ) dlog4 << myname << "(work): " << c.iaddr << " resp=" << (c.invert ? c.ptTimeout.checkTime() : !c.ptTimeout.checkTime())
dlog4 << myname << "(work): " << c.iaddr << " resp=" << (c.invert ? c.ptTimeout.checkTime() : !c.ptTimeout.checkTime())
<< " askcount=" << c.askCount << " askcount=" << c.askCount
<< endl; << endl;
......
...@@ -37,10 +37,10 @@ int main(int argc, const char **argv) ...@@ -37,10 +37,10 @@ int main(int argc, const char **argv)
std::ostringstream logname; std::ostringstream logname;
string dir(conf->getLogDir()); string dir(conf->getLogDir());
logname << dir << logfilename; logname << dir << logfilename;
ulog.logFile( logname.str() ); ulog()->logFile( logname.str() );
dlog.logFile( logname.str() ); dlog()->logFile( logname.str() );
conf->initDebug(dlog,"dlog"); conf->initDebug(dlog(),"dlog");
ObjectId shmID = DefaultObjectId; ObjectId shmID = DefaultObjectId;
string sID = conf->getArgParam("--smemory-id"); string sID = conf->getArgParam("--smemory-id");
...@@ -67,13 +67,13 @@ int main(int argc, const char **argv) ...@@ -67,13 +67,13 @@ int main(int argc, const char **argv)
SystemMessage sm(SystemMessage::StartUp); SystemMessage sm(SystemMessage::StartUp);
act->broadcast( sm.transport_msg() ); act->broadcast( sm.transport_msg() );
ulog << "\n\n\n"; ulogany << "\n\n\n";
ulog << "(main): -------------- MBSlave START -------------------------\n\n"; ulogany << "(main): -------------- MBSlave START -------------------------\n\n";
dlog << "\n\n\n"; dlogany << "\n\n\n";
dlog << "(main): -------------- MBSlave START -------------------------\n\n"; dlogany << "(main): -------------- MBSlave START -------------------------\n\n";
act->run(false); act->run(false);
on_sigchild(SIGTERM); // on_sigchild(SIGTERM);
return 0; return 0;
} }
catch( SystemError& err ) catch( SystemError& err )
...@@ -93,7 +93,7 @@ int main(int argc, const char **argv) ...@@ -93,7 +93,7 @@ int main(int argc, const char **argv)
dcrit << "(mbslave): catch(...)" << endl; dcrit << "(mbslave): catch(...)" << endl;
} }
on_sigchild(SIGTERM); // on_sigchild(SIGTERM);
return 1; return 1;
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
...@@ -37,10 +37,10 @@ int main(int argc, const char **argv) ...@@ -37,10 +37,10 @@ int main(int argc, const char **argv)
std::ostringstream logname; std::ostringstream logname;
string dir(conf->getLogDir()); string dir(conf->getLogDir());
logname << dir << logfilename; logname << dir << logfilename;
ulog.logFile( logname.str() ); ulog()->logFile( logname.str() );
dlog.logFile( logname.str() ); dlog()->logFile( logname.str() );
conf->initDebug(dlog,"dlog"); conf->initDebug(dlog(),"dlog");
ObjectId shmID = DefaultObjectId; ObjectId shmID = DefaultObjectId;
string sID = conf->getArgParam("--smemory-id"); string sID = conf->getArgParam("--smemory-id");
...@@ -67,13 +67,12 @@ int main(int argc, const char **argv) ...@@ -67,13 +67,12 @@ int main(int argc, const char **argv)
SystemMessage sm(SystemMessage::StartUp); SystemMessage sm(SystemMessage::StartUp);
act->broadcast( sm.transport_msg() ); act->broadcast( sm.transport_msg() );
ulog << "\n\n\n"; ulogany << "\n\n\n";
ulog << "(main): -------------- MBTCPMultiSlave START -------------------------\n\n"; ulogany << "(main): -------------- MBTCPMultiSlave START -------------------------\n\n";
dlog << "\n\n\n"; dlogany << "\n\n\n";
dlog << "(main): -------------- MBTCPMultiSlave START -------------------------\n\n"; dlogany << "(main): -------------- MBTCPMultiSlave START -------------------------\n\n";
act->run(false); act->run(false);
on_sigchild(SIGTERM);
return 0; return 0;
} }
catch( SystemError& err ) catch( SystemError& err )
...@@ -93,7 +92,6 @@ int main(int argc, const char **argv) ...@@ -93,7 +92,6 @@ int main(int argc, const char **argv)
dcrit << "(mbslave): catch(...)" << endl; dcrit << "(mbslave): catch(...)" << endl;
} }
on_sigchild(SIGTERM);
return 1; return 1;
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
...@@ -32,7 +32,7 @@ int main(int argc, char* argv[] ) ...@@ -32,7 +32,7 @@ int main(int argc, char* argv[] )
try try
{ {
auto conf = uniset_init(argc,argv); auto conf = uniset_init(argc,argv);
conf->initDebug(dlog,"dlog"); conf->initDebug(dlog(),"dlog");
bool apart = findArgParam("--apart",argc,argv) != -1; bool apart = findArgParam("--apart",argc,argv) != -1;
......
...@@ -12,7 +12,7 @@ using namespace UniSetTypes; ...@@ -12,7 +12,7 @@ using namespace UniSetTypes;
using namespace UniSetExtensions; using namespace UniSetExtensions;
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
RRDServer::RRDServer( UniSetTypes::ObjectId objId, xmlNode* cnode, UniSetTypes::ObjectId shmId, const std::shared_ptr<SharedMemory> ic, RRDServer::RRDServer( UniSetTypes::ObjectId objId, xmlNode* cnode, UniSetTypes::ObjectId shmId, const std::shared_ptr<SharedMemory> ic,
const string& prefix, DebugStream& log ): const string& prefix, std::shared_ptr<DebugStream> log ):
UObject_SK(objId,cnode), UObject_SK(objId,cnode),
prefix(prefix) prefix(prefix)
{ {
...@@ -25,7 +25,7 @@ prefix(prefix) ...@@ -25,7 +25,7 @@ prefix(prefix)
{ {
ostringstream err; ostringstream err;
err << myname << "(init): empty rrd list..."; err << myname << "(init): empty rrd list...";
mylog << err.str() << endl; mycrit << err.str() << endl;
throw NameNotFound(err.str()); throw NameNotFound(err.str());
} }
......
#ifndef _RRDServer_H_ #ifndef _RRDServer_H_
#define _RRDServer_H_ #define _RRDServer_H_
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#include <memory>
#include "UObject_SK.h" #include "UObject_SK.h"
#include "SMInterface.h" #include "SMInterface.h"
#include "SharedMemory.h" #include "SharedMemory.h"
...@@ -59,7 +60,7 @@ class RRDServer: ...@@ -59,7 +60,7 @@ class RRDServer:
{ {
public: public:
RRDServer( UniSetTypes::ObjectId objId, xmlNode* cnode, UniSetTypes::ObjectId shmID, const std::shared_ptr<SharedMemory> ic=nullptr, RRDServer( UniSetTypes::ObjectId objId, xmlNode* cnode, UniSetTypes::ObjectId shmID, const std::shared_ptr<SharedMemory> ic=nullptr,
const std::string& prefix="rrd", DebugStream& log=UniSetExtensions::dlog ); const std::string& prefix="rrd", std::shared_ptr<DebugStream> log=UniSetExtensions::dlog() );
virtual ~RRDServer(); virtual ~RRDServer();
/*! глобальная функция для инициализации объекта */ /*! глобальная функция для инициализации объекта */
......
...@@ -30,13 +30,13 @@ int main( int argc, const char** argv ) ...@@ -30,13 +30,13 @@ int main( int argc, const char** argv )
if( logfilename.empty() ) if( logfilename.empty() )
logfilename = "rrdstorage.log"; logfilename = "rrdstorage.log";
conf->initDebug(dlog,"dlog"); conf->initDebug(dlog(),"dlog");
std::ostringstream logname; std::ostringstream logname;
string dir(conf->getLogDir()); string dir(conf->getLogDir());
logname << dir << logfilename; logname << dir << logfilename;
ulog.logFile( logname.str() ); ulog()->logFile( logname.str() );
dlog.logFile( logname.str() ); dlog()->logFile( logname.str() );
ObjectId shmID = DefaultObjectId; ObjectId shmID = DefaultObjectId;
string sID = conf->getArgParam("--smemory-id"); string sID = conf->getArgParam("--smemory-id");
...@@ -64,10 +64,10 @@ int main( int argc, const char** argv ) ...@@ -64,10 +64,10 @@ int main( int argc, const char** argv )
SystemMessage sm(SystemMessage::StartUp); SystemMessage sm(SystemMessage::StartUp);
act->broadcast( sm.transport_msg() ); act->broadcast( sm.transport_msg() );
ulog << "\n\n\n"; ulogany << "\n\n\n";
ulog << "(main): -------------- RRDServer START -------------------------\n\n"; ulogany << "(main): -------------- RRDServer START -------------------------\n\n";
dlog << "\n\n\n"; dlogany << "\n\n\n";
dlog << "(main): -------------- RRDServer START -------------------------\n\n"; dlogany << "(main): -------------- RRDServer START -------------------------\n\n";
act->run(false); act->run(false);
return 0; return 0;
} }
......
...@@ -23,11 +23,11 @@ int main(int argc, const char **argv) ...@@ -23,11 +23,11 @@ int main(int argc, const char **argv)
{ {
auto conf = uniset_init(argc, argv); auto conf = uniset_init(argc, argv);
conf->initDebug(dlog,"dlog"); conf->initDebug(dlog(),"dlog");
string logfilename = conf->getArgParam("--logfile", "smemory.log"); string logfilename = conf->getArgParam("--logfile", "smemory.log");
string logname( conf->getLogDir() + logfilename ); string logname( conf->getLogDir() + logfilename );
ulog.logFile( logname ); ulog()->logFile( logname );
dlog.logFile( logname ); dlog()->logFile( logname );
auto shm = SharedMemory::init_smemory(argc, argv); auto shm = SharedMemory::init_smemory(argc, argv);
if( !shm ) if( !shm )
...@@ -43,19 +43,19 @@ int main(int argc, const char **argv) ...@@ -43,19 +43,19 @@ int main(int argc, const char **argv)
} }
catch( SystemError& err ) catch( SystemError& err )
{ {
dlog.crit() << "(smemory): " << err << endl; dcrit << "(smemory): " << err << endl;
} }
catch( Exception& ex ) catch( Exception& ex )
{ {
dlog.crit() << "(smemory): " << ex << endl; dcrit << "(smemory): " << ex << endl;
} }
catch( std::exception& e ) catch( std::exception& e )
{ {
dlog.crit() << "(smemory): " << e.what() << endl; dcrit << "(smemory): " << e.what() << endl;
} }
catch(...) catch(...)
{ {
dlog.crit() << "(smemory): catch(...)" << endl; dcrit << "(smemory): catch(...)" << endl;
} }
return 1; return 1;
......
...@@ -72,9 +72,9 @@ int main( int argc, const char **argv ) ...@@ -72,9 +72,9 @@ int main( int argc, const char **argv )
string logfilename = conf->getArgParam("--logfile", "smemory-plus.log"); string logfilename = conf->getArgParam("--logfile", "smemory-plus.log");
string logname( conf->getLogDir() + logfilename ); string logname( conf->getLogDir() + logfilename );
UniSetExtensions::dlog.logFile( logname ); UniSetExtensions::dlog()->logFile( logname );
ulog.logFile( logname ); ulog()->logFile( logname );
conf->initDebug(UniSetExtensions::dlog,"dlog"); conf->initDebug(UniSetExtensions::dlog(),"dlog");
auto act = UniSetActivator::Instance(); auto act = UniSetActivator::Instance();
act->signal_terminate_event().connect( &activator_terminate ); act->signal_terminate_event().connect( &activator_terminate );
...@@ -102,8 +102,7 @@ int main( int argc, const char **argv ) ...@@ -102,8 +102,7 @@ int main( int argc, const char **argv )
p << "io"; p << "io";
if( i > 0 ) p << i; if( i > 0 ) p << i;
if( dlog.is_info() ) dinfo << "(smemory-plus): add IOControl(" << p.str() << ")" << endl;
dlog.info() << "(smemory-plus): add IOControl(" << p.str() << ")" << endl;
auto ic = IOControl::init_iocontrol(argc,argv,shm->getId(),shm,p.str()); auto ic = IOControl::init_iocontrol(argc,argv,shm->getId(),shm,p.str());
if( !ic ) if( !ic )
...@@ -132,8 +131,7 @@ int main( int argc, const char **argv ) ...@@ -132,8 +131,7 @@ int main( int argc, const char **argv )
p << "rtu"; p << "rtu";
if( i > 0 ) p << i; if( i > 0 ) p << i;
if( dlog.is_info() ) dinfo << "(smemory-plus): add RTUExchange(" << p.str() << ")" << endl;
dlog.info() << "(smemory-plus): add RTUExchange(" << p.str() << ")" << endl;
auto rtu = RTUExchange::init_rtuexchange(argc,argv,shm->getId(),shm,p.str()); auto rtu = RTUExchange::init_rtuexchange(argc,argv,shm->getId(),shm,p.str());
if( !rtu ) if( !rtu )
...@@ -156,8 +154,7 @@ int main( int argc, const char **argv ) ...@@ -156,8 +154,7 @@ int main( int argc, const char **argv )
p << "mbs"; p << "mbs";
if( i > 0 ) p << i; if( i > 0 ) p << i;
if( dlog.is_info() ) dinfo << "(smemory-plus): add MBSlave(" << p.str() << ")" << endl;
dlog.info() << "(smemory-plus): add MBSlave(" << p.str() << ")" << endl;
auto mbs = MBSlave::init_mbslave(argc,argv,shm->getId(),shm,p.str()); auto mbs = MBSlave::init_mbslave(argc,argv,shm->getId(),shm,p.str());
if( !mbs ) if( !mbs )
...@@ -182,8 +179,7 @@ int main( int argc, const char **argv ) ...@@ -182,8 +179,7 @@ int main( int argc, const char **argv )
p << "mbtcp"; p << "mbtcp";
if( i > 0 ) p << i; if( i > 0 ) p << i;
if( dlog.is_info() ) dinfo << "(smemory-plus): add MBTCPMaster(" << p.str() << ")" << endl;
dlog.info() << "(smemory-plus): add MBTCPMaster(" << p.str() << ")" << endl;
auto mbm1 = MBTCPMaster::init_mbmaster(argc,argv,shm->getId(),shm,p.str()); auto mbm1 = MBTCPMaster::init_mbmaster(argc,argv,shm->getId(),shm,p.str());
if( !mbm1 ) if( !mbm1 )
...@@ -200,8 +196,7 @@ int main( int argc, const char **argv ) ...@@ -200,8 +196,7 @@ int main( int argc, const char **argv )
if( unet == NULL ) if( unet == NULL )
return 1; return 1;
if( dlog.is_info() ) dinfo << "(smemory-plus): add UNetExchnage.." << endl;
dlog.info() << "(smemory-plus): add UNetExchnage.." << endl;
act->add(unet); act->add(unet);
} }
...@@ -218,8 +213,8 @@ int main( int argc, const char **argv ) ...@@ -218,8 +213,8 @@ int main( int argc, const char **argv )
#endif #endif
LogAgregator la; LogAgregator la;
la.add(ulog); la.add(ulog());
la.add(dlog); la.add(dlog());
logserver = run_logserver("smplus",la); logserver = run_logserver("smplus",la);
if( logserver == 0 ) if( logserver == 0 )
...@@ -235,15 +230,15 @@ int main( int argc, const char **argv ) ...@@ -235,15 +230,15 @@ int main( int argc, const char **argv )
} }
catch(Exception& ex) catch(Exception& ex)
{ {
ulog.crit() << "(smemory-plus): " << ex << endl; dcrit << "(smemory-plus): " << ex << endl;
} }
catch( CORBA::SystemException& ex ) catch( CORBA::SystemException& ex )
{ {
ulog.crit() << "(smemory-plus): " << ex.NP_minorString() << endl; dcrit << "(smemory-plus): " << ex.NP_minorString() << endl;
} }
catch(...) catch(...)
{ {
ulog.crit() << "(smemory-plus): catch(...)" << endl; dcrit << "(smemory-plus): catch(...)" << endl;
} }
on_sigchild(SIGTERM); on_sigchild(SIGTERM);
......
...@@ -508,20 +508,20 @@ void UNetExchange::sysCommand( const UniSetTypes::SystemMessage *sm ) ...@@ -508,20 +508,20 @@ void UNetExchange::sysCommand( const UniSetTypes::SystemMessage *sm )
case SystemMessage::LogRotate: case SystemMessage::LogRotate:
{ {
// переоткрываем логи // переоткрываем логи
ulog << myname << "(sysCommand): logRotate" << std::endl; ulogany << myname << "(sysCommand): logRotate" << std::endl;
string fname(ulog.getLogFile()); string fname(ulog()->getLogFile());
if( !fname.empty() ) if( !fname.empty() )
{ {
ulog.logFile(fname,true); ulog()->logFile(fname,true);
ulog << myname << "(sysCommand): ***************** ulog LOG ROTATE *****************" << std::endl; ulogany << myname << "(sysCommand): ***************** ulog LOG ROTATE *****************" << std::endl;
} }
dlog << myname << "(sysCommand): logRotate" << std::endl; dlogany << myname << "(sysCommand): logRotate" << std::endl;
fname = dlog.getLogFile(); fname = dlog()->getLogFile();
if( !fname.empty() ) if( !fname.empty() )
{ {
dlog.logFile(fname,true); dlog()->logFile(fname,true);
dlog << myname << "(sysCommand): ***************** dlog LOG ROTATE *****************" << std::endl; dlogany << myname << "(sysCommand): ***************** dlog LOG ROTATE *****************" << std::endl;
} }
} }
break; break;
......
...@@ -32,7 +32,7 @@ int main(int argc, char* argv[] ) ...@@ -32,7 +32,7 @@ int main(int argc, char* argv[] )
try try
{ {
auto conf = uniset_init(argc,argv); auto conf = uniset_init(argc,argv);
conf->initDebug(dlog,"dlog"); conf->initDebug(dlog(),"dlog");
bool apart = findArgParam("--apart",argc,argv) != -1; bool apart = findArgParam("--apart",argc,argv) != -1;
......
...@@ -32,9 +32,9 @@ int main( int argc, const char** argv ) ...@@ -32,9 +32,9 @@ int main( int argc, const char** argv )
std::ostringstream logname; std::ostringstream logname;
string dir(conf->getLogDir()); string dir(conf->getLogDir());
logname << dir << logfilename; logname << dir << logfilename;
ulog.logFile( logname.str() ); ulog()->logFile( logname.str() );
UniSetExtensions::dlog.logFile( logname.str() ); UniSetExtensions::dlog()->logFile( logname.str() );
conf->initDebug(UniSetExtensions::dlog,"dlog"); conf->initDebug(UniSetExtensions::dlog(),"dlog");
ObjectId shmID = DefaultObjectId; ObjectId shmID = DefaultObjectId;
string sID = conf->getArgParam("--smemory-id"); string sID = conf->getArgParam("--smemory-id");
...@@ -62,10 +62,10 @@ int main( int argc, const char** argv ) ...@@ -62,10 +62,10 @@ int main( int argc, const char** argv )
SystemMessage sm(SystemMessage::StartUp); SystemMessage sm(SystemMessage::StartUp);
act->broadcast( sm.transport_msg() ); act->broadcast( sm.transport_msg() );
ulog << "\n\n\n"; ulogany << "\n\n\n";
ulog << "(main): -------------- UDPRecevier START -------------------------\n\n"; ulogany << "(main): -------------- UDPRecevier START -------------------------\n\n";
dlog << "\n\n\n"; dlogany << "\n\n\n";
dlog << "(main): -------------- UDPReceiver START -------------------------\n\n"; dlogany << "(main): -------------- UDPReceiver START -------------------------\n\n";
act->run(false); act->run(false);
on_sigchild(SIGTERM); on_sigchild(SIGTERM);
......
...@@ -125,7 +125,7 @@ void UniExchange::execute() ...@@ -125,7 +125,7 @@ void UniExchange::execute()
err << myname << "(execute): Не дождались готовности SharedMemory к работе в течение " err << myname << "(execute): Не дождались готовности SharedMemory к работе в течение "
<< smReadyTimeout << " мсек"; << smReadyTimeout << " мсек";
ulog.crit() << err.str() << endl; ucrit << err.str() << endl;
throw SystemError(err.str()); throw SystemError(err.str());
} }
......
...@@ -21,11 +21,11 @@ int main(int argc, const char **argv) ...@@ -21,11 +21,11 @@ int main(int argc, const char **argv)
{ {
auto conf = uniset_init(argc, argv); auto conf = uniset_init(argc, argv);
conf->initDebug(dlog,"dlog"); conf->initDebug(dlog(),"dlog");
string logfilename = conf->getArgParam("--logfile", "smemory.log"); string logfilename = conf->getArgParam("--logfile", "smemory.log");
string logname( conf->getLogDir() + logfilename ); string logname( conf->getLogDir() + logfilename );
ulog.logFile( logname ); ulog()->logFile( logname );
dlog.logFile( logname ); dlog()->logFile( logname );
ObjectId shmID = DefaultObjectId; ObjectId shmID = DefaultObjectId;
string sID = conf->getArgParam("--smemory-id"); string sID = conf->getArgParam("--smemory-id");
...@@ -56,15 +56,15 @@ int main(int argc, const char **argv) ...@@ -56,15 +56,15 @@ int main(int argc, const char **argv)
} }
catch(SystemError& err) catch(SystemError& err)
{ {
dlog.crit() << "(uninetwork): " << err << endl; dcrit << "(uninetwork): " << err << endl;
} }
catch(Exception& ex) catch(Exception& ex)
{ {
dlog.crit() << "(uninetwork): " << ex << endl; dcrit << "(uninetwork): " << ex << endl;
} }
catch(...) catch(...)
{ {
dlog.crit() << "(uninetwork): catch(...)" << endl; dcrit << "(uninetwork): catch(...)" << endl;
} }
on_sigchild(SIGTERM); on_sigchild(SIGTERM);
......
...@@ -25,27 +25,27 @@ namespace UniSetExtensions ...@@ -25,27 +25,27 @@ namespace UniSetExtensions
/*! Загрузка калибровочной диаграммы */ /*! Загрузка калибровочной диаграммы */
Calibration* buildCalibrationDiagram( const std::string& dname ); Calibration* buildCalibrationDiagram( const std::string& dname );
void on_sigchild( int sig ); void on_sigchild( int sig );
extern DebugStream dlog; std::shared_ptr<DebugStream> dlog();
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
// "синтаксический сахар"..для логов // "синтаксический сахар"..для логов
#define dinfo if( UniSetExtensions::dlog.debugging(Debug::INFO) ) UniSetExtensions::dlog[Debug::INFO] #define dinfo if( UniSetExtensions::dlog()->debugging(Debug::INFO) ) UniSetExtensions::dlog()->info()
#define dwarn if( UniSetExtensions::dlog.debugging(Debug::WARN) ) UniSetExtensions::dlog[Debug::WARN] #define dwarn if( UniSetExtensions::dlog()->debugging(Debug::WARN) ) UniSetExtensions::dlog()->warn()
#define dcrit if( UniSetExtensions::dlog.debugging(Debug::CRIT) ) UniSetExtensions::dlog[Debug::CRIT] #define dcrit if( UniSetExtensions::dlog()->debugging(Debug::CRIT) ) UniSetExtensions::dlog()->crit()
#define dlog1 if( UniSetExtensions::dlog.debugging(Debug::LEVEL1) ) UniSetExtensions::dlog[Debug::LEVEL1] #define dlog1 if( UniSetExtensions::dlog()->debugging(Debug::LEVEL1) ) UniSetExtensions::dlog()->level1()
#define dlog2 if( UniSetExtensions::dlog.debugging(Debug::LEVEL2) ) UniSetExtensions::dlog[Debug::LEVEL2] #define dlog2 if( UniSetExtensions::dlog()->debugging(Debug::LEVEL2) ) UniSetExtensions::dlog()->level1()
#define dlog3 if( UniSetExtensions::dlog.debugging(Debug::LEVEL3) ) UniSetExtensions::dlog[Debug::LEVEL3] #define dlog3 if( UniSetExtensions::dlog()->debugging(Debug::LEVEL3) ) UniSetExtensions::dlog()->level3()
#define dlog4 if( UniSetExtensions::dlog.debugging(Debug::LEVEL4) ) UniSetExtensions::dlog[Debug::LEVEL4] #define dlog4 if( UniSetExtensions::dlog()->debugging(Debug::LEVEL4) ) UniSetExtensions::dlog()->level4()
#define dlog5 if( UniSetExtensions::dlog.debugging(Debug::LEVEL5) ) UniSetExtensions::dlog[Debug::LEVEL5] #define dlog5 if( UniSetExtensions::dlog()->debugging(Debug::LEVEL5) ) UniSetExtensions::dlog()->level5()
#define dlog6 if( UniSetExtensions::dlog.debugging(Debug::LEVEL6) ) UniSetExtensions::dlog[Debug::LEVEL6] #define dlog6 if( UniSetExtensions::dlog()->debugging(Debug::LEVEL6) ) UniSetExtensions::dlog()->level6()
#define dlog7 if( UniSetExtensions::dlog.debugging(Debug::LEVEL7) ) UniSetExtensions::dlog[Debug::LEVEL7] #define dlog7 if( UniSetExtensions::dlog()->debugging(Debug::LEVEL7) ) UniSetExtensions::dlog()->level7()
#define dlog8 if( UniSetExtensions::dlog.debugging(Debug::LEVEL8) ) UniSetExtensions::dlog[Debug::LEVEL8] #define dlog8 if( UniSetExtensions::dlog()->debugging(Debug::LEVEL8) ) UniSetExtensions::dlog()->level8()
#define dlog9 if( UniSetExtensions::dlog.debugging(Debug::LEVEL9) ) UniSetExtensions::dlog[Debug::LEVEL9] #define dlog9 if( UniSetExtensions::dlog()->debugging(Debug::LEVEL9) ) UniSetExtensions::dlog()->level9()
#define dlogsys if( UniSetExtensions::dlog.debugging(Debug::SYSTEM) ) UniSetExtensions::dlog[Debug::SYSTEM] #define dlogsys if( UniSetExtensions::dlog()->debugging(Debug::SYSTEM) ) UniSetExtensions::dlog()->system()
#define dlogrep if( UniSetExtensions::dlog.debugging(Debug::REPOSITORY) ) UniSetExtensions::dlog[Debug::REPOSITORY] #define dlogrep if( UniSetExtensions::dlog()->debugging(Debug::REPOSITORY) ) UniSetExtensions::dlog()->repository()
#define dlogany UniSetExtensions::dlog()->any()
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
#endif // Extensions_H_ #endif // Extensions_H_
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
...@@ -157,7 +157,7 @@ struct IOBase ...@@ -157,7 +157,7 @@ struct IOBase
*/ */
static bool initItem( IOBase* b, UniXML::iterator& it, const std::shared_ptr<SMInterface>& shm, static bool initItem( IOBase* b, UniXML::iterator& it, const std::shared_ptr<SMInterface>& shm,
const std::string& prefix, bool init_prefix_only, const std::string& prefix, bool init_prefix_only,
DebugStream* dlog=0, std::string myname="", std::shared_ptr<DebugStream> dlog=nullptr, std::string myname="",
int def_filtersize=0, float def_filterT=0.0, int def_filtersize=0, float def_filterT=0.0,
float def_lsparam=0.2, float def_iir_coeff_prev=0.5, float def_lsparam=0.2, float def_iir_coeff_prev=0.5,
float def_iir_coeff_new=0.5 ); float def_iir_coeff_new=0.5 );
......
...@@ -9,7 +9,15 @@ using namespace std; ...@@ -9,7 +9,15 @@ using namespace std;
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
namespace UniSetExtensions namespace UniSetExtensions
{ {
DebugStream dlog; static std::shared_ptr<DebugStream> _dlog;
std::shared_ptr<DebugStream> dlog()
{
if( _dlog )
return _dlog;
_dlog = make_shared<DebugStream>();
return _dlog;
}
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
static UniSetTypes::ObjectId shmID = DefaultObjectId; static UniSetTypes::ObjectId shmID = DefaultObjectId;
......
...@@ -477,7 +477,7 @@ int IOBase::initIntProp( UniXML::iterator& it, const std::string& prop, const st ...@@ -477,7 +477,7 @@ int IOBase::initIntProp( UniXML::iterator& it, const std::string& prop, const st
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
bool IOBase::initItem( IOBase* b, UniXML::iterator& it, const std::shared_ptr<SMInterface>& shm, const std::string& prefix, bool IOBase::initItem( IOBase* b, UniXML::iterator& it, const std::shared_ptr<SMInterface>& shm, const std::string& prefix,
bool init_prefix_only, bool init_prefix_only,
DebugStream* dlog, std::string myname, std::shared_ptr<DebugStream> dlog, std::string myname,
int def_filtersize, float def_filterT, float def_lsparam, int def_filtersize, float def_filterT, float def_lsparam,
float def_iir_coeff_prev, float def_iir_coeff_new ) float def_iir_coeff_prev, float def_iir_coeff_new )
{ {
......
...@@ -142,6 +142,8 @@ namespace UniSetTypes ...@@ -142,6 +142,8 @@ namespace UniSetTypes
int getArgPInt(const std::string& name, const std::string& strdefval, int defval); int getArgPInt(const std::string& name, const std::string& strdefval, int defval);
xmlNode* initDebug( DebugStream& deb, const std::string& nodename ); xmlNode* initDebug( DebugStream& deb, const std::string& nodename );
xmlNode* initDebug( std::shared_ptr<DebugStream> deb, const std::string& nodename );
xmlNode* initDebug( DebugStream* deb, const std::string& nodename );
UniSetTypes::ListOfNode::const_iterator listNodesBegin() UniSetTypes::ListOfNode::const_iterator listNodesBegin()
{ {
...@@ -235,7 +237,7 @@ namespace UniSetTypes ...@@ -235,7 +237,7 @@ namespace UniSetTypes
std::shared_ptr<Configuration> uniset_conf(); std::shared_ptr<Configuration> uniset_conf();
/*! Глобальный объект для вывода логов */ /*! Глобальный объект для вывода логов */
extern DebugStream ulog; std::shared_ptr<DebugStream> ulog();
/*! инициализация "глобальной" конфигурации */ /*! инициализация "глобальной" конфигурации */
std::shared_ptr<Configuration> uniset_init( int argc, const char* const* argv, const std::string& xmlfile="configure.xml" ); std::shared_ptr<Configuration> uniset_init( int argc, const char* const* argv, const std::string& xmlfile="configure.xml" );
...@@ -243,19 +245,20 @@ namespace UniSetTypes ...@@ -243,19 +245,20 @@ namespace UniSetTypes
} // end of UniSetTypes namespace } // end of UniSetTypes namespace
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
// "синтаксический сахар"..для логов // "синтаксический сахар"..для логов
#define uinfo if( UniSetTypes::ulog.debugging(Debug::INFO) ) UniSetTypes::ulog[Debug::INFO] #define uinfo if( UniSetTypes::ulog()->debugging(Debug::INFO) ) UniSetTypes::ulog()->info()
#define uwarn if( UniSetTypes::ulog.debugging(Debug::WARN) ) UniSetTypes::ulog[Debug::WARN] #define uwarn if( UniSetTypes::ulog()->debugging(Debug::WARN) ) UniSetTypes::ulog()->warn()
#define ucrit if( UniSetTypes::ulog.debugging(Debug::CRIT) ) UniSetTypes::ulog[Debug::CRIT] #define ucrit if( UniSetTypes::ulog()->debugging(Debug::CRIT) ) UniSetTypes::ulog()->crit()
#define ulog1 if( UniSetTypes::ulog.debugging(Debug::LEVEL1) ) UniSetTypes::ulog[Debug::LEVEL1] #define ulog1 if( UniSetTypes::ulog()->debugging(Debug::LEVEL1) ) UniSetTypes::ulog()->level1()
#define ulog2 if( UniSetTypes::ulog.debugging(Debug::LEVEL2) ) UniSetTypes::ulog[Debug::LEVEL2] #define ulog2 if( UniSetTypes::ulog()->debugging(Debug::LEVEL2) ) UniSetTypes::ulog()->level2()
#define ulog3 if( UniSetTypes::ulog.debugging(Debug::LEVEL3) ) UniSetTypes::ulog[Debug::LEVEL3] #define ulog3 if( UniSetTypes::ulog()->debugging(Debug::LEVEL3) ) UniSetTypes::ulog()->level3()
#define ulog4 if( UniSetTypes::ulog.debugging(Debug::LEVEL4) ) UniSetTypes::ulog[Debug::LEVEL4] #define ulog4 if( UniSetTypes::ulog()->debugging(Debug::LEVEL4) ) UniSetTypes::ulog()->level4()
#define ulog5 if( UniSetTypes::ulog.debugging(Debug::LEVEL5) ) UniSetTypes::ulog[Debug::LEVEL5] #define ulog5 if( UniSetTypes::ulog()->debugging(Debug::LEVEL5) ) UniSetTypes::ulog()->level5()
#define ulog6 if( UniSetTypes::ulog.debugging(Debug::LEVEL6) ) UniSetTypes::ulog[Debug::LEVEL6] #define ulog6 if( UniSetTypes::ulog()->debugging(Debug::LEVEL6) ) UniSetTypes::ulog()->level6()
#define ulog7 if( UniSetTypes::ulog.debugging(Debug::LEVEL7) ) UniSetTypes::ulog[Debug::LEVEL7] #define ulog7 if( UniSetTypes::ulog()->debugging(Debug::LEVEL7) ) UniSetTypes::ulog()->level7()
#define ulog8 if( UniSetTypes::ulog.debugging(Debug::LEVEL8) ) UniSetTypes::ulog[Debug::LEVEL8] #define ulog8 if( UniSetTypes::ulog()->debugging(Debug::LEVEL8) ) UniSetTypes::ulog()->level8()
#define ulog9 if( UniSetTypes::ulog.debugging(Debug::LEVEL9) ) UniSetTypes::ulog[Debug::LEVEL9] #define ulog9 if( UniSetTypes::ulog()->debugging(Debug::LEVEL9) ) UniSetTypes::ulog()->level9()
#define ulogsys if( UniSetTypes::ulog.debugging(Debug::SYSTEM) ) UniSetTypes::ulog[Debug::SYSTEM] #define ulogsys if( UniSetTypes::ulog()->debugging(Debug::SYSTEM) ) UniSetTypes::ulog()->system()
#define ulogrep if( UniSetTypes::ulog.debugging(Debug::REPOSITORY) ) UniSetTypes::ulog[Debug::REPOSITORY] #define ulogrep if( UniSetTypes::ulog()->debugging(Debug::REPOSITORY) ) UniSetTypes::ulog()->repository()
#define ulogany UniSetTypes::ulog()->any()
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
#endif // Configuration_H_ #endif // Configuration_H_
...@@ -19,12 +19,7 @@ class LogAgregator: ...@@ -19,12 +19,7 @@ class LogAgregator:
virtual void logFile( const std::string& f ); virtual void logFile( const std::string& f );
// функция не рекомендуется к использованию и сделана для void add( std::shared_ptr<DebugStream> log );
// совместимости со старым кодом или для глобальных DebugStream
// Рекомендуется, всё-таки использовать add( std::shared_ptr<DebugStream>.. );
void add( DebugStream& log );
void add( std::shared_ptr<DebugStream>& log );
std::shared_ptr<DebugStream> create( const std::string& logname ); std::shared_ptr<DebugStream> create( const std::string& logname );
// Управление "подчинёнными" логами // Управление "подчинёнными" логами
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#define ModbusClient_H_ #define ModbusClient_H_
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
#include <string> #include <string>
#include <memory>
#include "Mutex.h" #include "Mutex.h"
#include "Debug.h" #include "Debug.h"
#include "Configuration.h" #include "Configuration.h"
...@@ -144,7 +145,7 @@ class ModbusClient ...@@ -144,7 +145,7 @@ class ModbusClient
inline void setSleepPause( timeout_t usec ){ sleepPause_usec = usec; } inline void setSleepPause( timeout_t usec ){ sleepPause_usec = usec; }
void initLog( UniSetTypes::Configuration* conf, const std::string& name, const std::string& logfile="" ); void initLog( UniSetTypes::Configuration* conf, const std::string& name, const std::string& logfile="" );
void setLog( DebugStream& dlog ); void setLog( std::shared_ptr<DebugStream> dlog );
inline void setCRCNoCheckit( bool set ){ crcNoCheckit = set; } inline void setCRCNoCheckit( bool set ){ crcNoCheckit = set; }
...@@ -194,7 +195,7 @@ class ModbusClient ...@@ -194,7 +195,7 @@ class ModbusClient
bool crcNoCheckit; bool crcNoCheckit;
UniSetTypes::uniset_rwmutex sendMutex; UniSetTypes::uniset_rwmutex sendMutex;
DebugStream dlog; std::shared_ptr<DebugStream> dlog;
void printProcessingTime(); void printProcessingTime();
PassiveTimer tmProcessing; PassiveTimer tmProcessing;
......
...@@ -18,7 +18,7 @@ class ModbusServer ...@@ -18,7 +18,7 @@ class ModbusServer
virtual ~ModbusServer(); virtual ~ModbusServer();
void initLog( UniSetTypes::Configuration* conf, const std::string& name, const std::string& logfile="" ); void initLog( UniSetTypes::Configuration* conf, const std::string& name, const std::string& logfile="" );
void setLog( DebugStream& dlog ); void setLog( std::shared_ptr<DebugStream> dlog );
/*! обработать очередное сообщение /*! обработать очередное сообщение
...@@ -59,7 +59,7 @@ class ModbusServer ...@@ -59,7 +59,7 @@ class ModbusServer
*/ */
static ModbusRTU::mbErrCode replySetDateTime( ModbusRTU::SetDateTimeMessage& query, static ModbusRTU::mbErrCode replySetDateTime( ModbusRTU::SetDateTimeMessage& query,
ModbusRTU::SetDateTimeRetMessage& reply, ModbusRTU::SetDateTimeRetMessage& reply,
DebugStream* dlog=0 ); std::shared_ptr<DebugStream> dlog=nullptr );
/*! Вспомогательная функция реализующая обработку передачи файла /*! Вспомогательная функция реализующая обработку передачи файла
...@@ -70,7 +70,7 @@ class ModbusServer ...@@ -70,7 +70,7 @@ class ModbusServer
static ModbusRTU::mbErrCode replyFileTransfer( const std::string& fname, static ModbusRTU::mbErrCode replyFileTransfer( const std::string& fname,
ModbusRTU::FileTransferMessage& query, ModbusRTU::FileTransferMessage& query,
ModbusRTU::FileTransferRetMessage& reply, ModbusRTU::FileTransferRetMessage& reply,
DebugStream* dlog=0 ); std::shared_ptr<DebugStream> dlog=nullptr );
virtual void cleanupChannel(){} virtual void cleanupChannel(){}
virtual void terminate(){} virtual void terminate(){}
...@@ -233,7 +233,7 @@ class ModbusServer ...@@ -233,7 +233,7 @@ class ModbusServer
void printProcessingTime(); void printProcessingTime();
PassiveTimer tmProcessing; PassiveTimer tmProcessing;
DebugStream dlog; std::shared_ptr<DebugStream> dlog;
private: private:
......
...@@ -127,7 +127,7 @@ mbErrCode ModbusRTUMaster::sendData( unsigned char* buf, int len ) ...@@ -127,7 +127,7 @@ mbErrCode ModbusRTUMaster::sendData( unsigned char* buf, int len )
} }
catch( Exception& ex ) // SystemError catch( Exception& ex ) // SystemError
{ {
dlog.crit() << "(send): " << ex << endl; dlog->crit() << "(send): " << ex << endl;
return erHardwareError; return erHardwareError;
} }
......
...@@ -67,8 +67,8 @@ mbErrCode ModbusRTUSlave::receive( ModbusRTU::ModbusAddr addr, timeout_t timeout ...@@ -67,8 +67,8 @@ mbErrCode ModbusRTUSlave::receive( ModbusRTU::ModbusAddr addr, timeout_t timeout
uniset_mutex_lock lck(recvMutex,timeout); uniset_mutex_lock lck(recvMutex,timeout);
if( !lck.lock_ok() ) if( !lck.lock_ok() )
{ {
if( dlog.debugging(Debug::CRIT) ) if( dlog->is_crit() )
dlog.crit() << "(ModbusRTUSlave::receive): Don`t lock " << recvMutex << endl; dlog->crit() << "(ModbusRTUSlave::receive): Don`t lock " << recvMutex << endl;
return erTimeOut; return erTimeOut;
} }
...@@ -89,7 +89,7 @@ mbErrCode ModbusRTUSlave::receive( ModbusRTU::ModbusAddr addr, timeout_t timeout ...@@ -89,7 +89,7 @@ mbErrCode ModbusRTUSlave::receive( ModbusRTU::ModbusAddr addr, timeout_t timeout
printProcessingTime(); printProcessingTime();
} }
// dlog.warn() << "(receive): " << mbErr2Str(res) << endl; // dlog->warn() << "(receive): " << mbErr2Str(res) << endl;
// cerr << "**** (receive): " << mbErr2Str(res) << endl; // cerr << "**** (receive): " << mbErr2Str(res) << endl;
usleep(10000); usleep(10000);
return res; return res;
...@@ -151,7 +151,8 @@ mbErrCode ModbusRTUSlave::sendData( unsigned char* buf, int len ) ...@@ -151,7 +151,8 @@ mbErrCode ModbusRTUSlave::sendData( unsigned char* buf, int len )
} }
catch( Exception& ex ) // SystemError catch( Exception& ex ) // SystemError
{ {
dlog.crit() << "(send): " << ex << endl; if( dlog->is_crit() )
dlog->crit() << "(send): " << ex << endl;
return erHardwareError; return erHardwareError;
} }
...@@ -164,4 +165,4 @@ void ModbusRTUSlave::terminate() ...@@ -164,4 +165,4 @@ void ModbusRTUSlave::terminate()
{ {
} }
catch(...){} catch(...){}
} }
\ No newline at end of file
...@@ -121,8 +121,8 @@ bool ModbusTCPServer::waitQuery( ModbusRTU::ModbusAddr mbaddr, timeout_t msec ) ...@@ -121,8 +121,8 @@ bool ModbusTCPServer::waitQuery( ModbusRTU::ModbusAddr mbaddr, timeout_t msec )
} }
catch( ost::Exception& e ) catch( ost::Exception& e )
{ {
if( dlog.debugging(Debug::WARN) ) if( dlog->is_warn() )
dlog[Debug::WARN] << "(ModbusTCPServer): " << e.what() << endl; dlog->warn() << "(ModbusTCPServer): " << e.what() << endl;
} }
return false; return false;
...@@ -289,11 +289,11 @@ mbErrCode ModbusTCPServer::tcp_processing( ost::TCPStream& tcp, ModbusTCP::MBAPH ...@@ -289,11 +289,11 @@ mbErrCode ModbusTCPServer::tcp_processing( ost::TCPStream& tcp, ModbusTCP::MBAPH
mhead.swapdata(); mhead.swapdata();
if( dlog.is_info() ) if( dlog->is_info() )
{ {
dlog.info() << "(ModbusTCPServer::tcp_processing): recv tcp header(" << len << "): "; dlog->info() << "(ModbusTCPServer::tcp_processing): recv tcp header(" << len << "): ";
mbPrintMessage( dlog, (ModbusByte*)(&mhead), sizeof(mhead)); mbPrintMessage( *(dlog.get()), (ModbusByte*)(&mhead), sizeof(mhead));
dlog(Debug::INFO) << endl; (*(dlog.get()))(Debug::INFO) << endl;
} }
// check header // check header
...@@ -304,8 +304,8 @@ mbErrCode ModbusTCPServer::tcp_processing( ost::TCPStream& tcp, ModbusTCP::MBAPH ...@@ -304,8 +304,8 @@ mbErrCode ModbusTCPServer::tcp_processing( ost::TCPStream& tcp, ModbusTCP::MBAPH
if( len<mhead.len ) if( len<mhead.len )
{ {
if( dlog.is_info() ) if( dlog->is_info() )
dlog.info() << "(ModbusTCPServer::tcp_processing): len(" << (int)len dlog->info() << "(ModbusTCPServer::tcp_processing): len(" << (int)len
<< ") < mhead.len(" << (int)mhead.len << ")" << endl; << ") < mhead.len(" << (int)mhead.len << ")" << endl;
return erInvalidFormat; return erInvalidFormat;
...@@ -331,11 +331,11 @@ mbErrCode ModbusTCPServer::pre_send_request( ModbusMessage& request ) ...@@ -331,11 +331,11 @@ mbErrCode ModbusTCPServer::pre_send_request( ModbusMessage& request )
curQueryHeader.len -= szCRC; curQueryHeader.len -= szCRC;
curQueryHeader.swapdata(); curQueryHeader.swapdata();
if( dlog.is_info() ) if( dlog->is_info() )
{ {
dlog.info() << "(ModbusTCPServer::pre_send_request): send tcp header: "; dlog->info() << "(ModbusTCPServer::pre_send_request): send tcp header: ";
mbPrintMessage( dlog, (ModbusByte*)(&curQueryHeader), sizeof(curQueryHeader)); mbPrintMessage( *(dlog.get()), (ModbusByte*)(&curQueryHeader), sizeof(curQueryHeader));
dlog(Debug::INFO) << endl; (*(dlog.get()))(Debug::INFO) << endl;
} }
tcp << curQueryHeader; tcp << curQueryHeader;
...@@ -359,8 +359,8 @@ void ModbusTCPServer::terminate() ...@@ -359,8 +359,8 @@ void ModbusTCPServer::terminate()
{ {
cancelled = true; cancelled = true;
if( dlog.is_info() ) if( dlog->is_info() )
dlog.info() << "(ModbusTCPServer): terminate..." << endl; dlog->info() << "(ModbusTCPServer): terminate..." << endl;
if( tcp && tcp.isConnected() ) if( tcp && tcp.isConnected() )
tcp.disconnect(); tcp.disconnect();
......
...@@ -57,8 +57,8 @@ void ModbusTCPSession::run() ...@@ -57,8 +57,8 @@ void ModbusTCPSession::run()
// cerr << "**************** CREATE SESS FOR " << string( inet_ntoa(a) ) << endl; // cerr << "**************** CREATE SESS FOR " << string( inet_ntoa(a) ) << endl;
} }
if( dlog.debugging(Debug::INFO) ) if( dlog->is_info() )
dlog[Debug::INFO] << peername << "(run): run thread of sessions.." << endl; dlog->info() << peername << "(run): run thread of sessions.." << endl;
ModbusRTU::mbErrCode res = erTimeOut; ModbusRTU::mbErrCode res = erTimeOut;
cancelled = false; cancelled = false;
...@@ -79,13 +79,13 @@ void ModbusTCPSession::run() ...@@ -79,13 +79,13 @@ void ModbusTCPSession::run()
} }
} }
if( dlog.debugging(Debug::INFO) ) if( dlog->is_info() )
dlog[Debug::INFO] << peername << "(run): stop thread of sessions..disconnect.." << endl; dlog->info() << peername << "(run): stop thread of sessions..disconnect.." << endl;
disconnect(); disconnect();
if( dlog.debugging(Debug::INFO) ) if( dlog->is_info() )
dlog[Debug::INFO] << peername << "(run): thread stopping..." << endl; dlog->info() << peername << "(run): thread stopping..." << endl;
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
ModbusRTU::mbErrCode ModbusTCPSession::receive( ModbusRTU::ModbusAddr addr, timeout_t msec ) ModbusRTU::mbErrCode ModbusTCPSession::receive( ModbusRTU::ModbusAddr addr, timeout_t msec )
...@@ -203,11 +203,11 @@ mbErrCode ModbusTCPSession::tcp_processing( ost::TCPStream& tcp, ModbusTCP::MBAP ...@@ -203,11 +203,11 @@ mbErrCode ModbusTCPSession::tcp_processing( ost::TCPStream& tcp, ModbusTCP::MBAP
mhead.swapdata(); mhead.swapdata();
if( dlog.debugging(Debug::INFO) ) if( dlog->is_info() )
{ {
dlog[Debug::INFO] << peername << "(tcp_processing): recv tcp header(" << len << "): "; dlog->info() << peername << "(tcp_processing): recv tcp header(" << len << "): ";
mbPrintMessage( dlog, (ModbusByte*)(&mhead), sizeof(mhead)); mbPrintMessage( *(dlog.get()), (ModbusByte*)(&mhead), sizeof(mhead));
dlog(Debug::INFO) << endl; (*(dlog.get()))(Debug::INFO) << endl;
} }
// check header // check header
...@@ -218,8 +218,8 @@ mbErrCode ModbusTCPSession::tcp_processing( ost::TCPStream& tcp, ModbusTCP::MBAP ...@@ -218,8 +218,8 @@ mbErrCode ModbusTCPSession::tcp_processing( ost::TCPStream& tcp, ModbusTCP::MBAP
if( len<mhead.len ) if( len<mhead.len )
{ {
if( dlog.debugging(Debug::INFO) ) if( dlog->is_info() )
dlog[Debug::INFO] << peername << "(tcp_processing): len(" << (int)len dlog->info() << peername << "(tcp_processing): len(" << (int)len
<< ") < mhead.len(" << (int)mhead.len << ")" << endl; << ") < mhead.len(" << (int)mhead.len << ")" << endl;
return erInvalidFormat; return erInvalidFormat;
...@@ -245,11 +245,11 @@ mbErrCode ModbusTCPSession::pre_send_request( ModbusMessage& request ) ...@@ -245,11 +245,11 @@ mbErrCode ModbusTCPSession::pre_send_request( ModbusMessage& request )
curQueryHeader.len -= szCRC; curQueryHeader.len -= szCRC;
curQueryHeader.swapdata(); curQueryHeader.swapdata();
if( dlog.debugging(Debug::INFO) ) if( dlog->is_info() )
{ {
dlog[Debug::INFO] << peername << "(pre_send_request): send tcp header: "; dlog->info() << peername << "(pre_send_request): send tcp header: ";
mbPrintMessage( dlog, (ModbusByte*)(&curQueryHeader), sizeof(curQueryHeader)); mbPrintMessage( *(dlog.get()), (ModbusByte*)(&curQueryHeader), sizeof(curQueryHeader));
dlog(Debug::INFO) << endl; (*(dlog.get()))(Debug::INFO) << endl;
} }
*tcp() << curQueryHeader; *tcp() << curQueryHeader;
...@@ -274,8 +274,8 @@ void ModbusTCPSession::terminate() ...@@ -274,8 +274,8 @@ void ModbusTCPSession::terminate()
{ {
ModbusServer::terminate(); ModbusServer::terminate();
if( dlog.debugging(Debug::INFO) ) if( dlog->is_info() )
dlog[Debug::INFO] << peername << "(terminate)..." << endl; dlog->info() << peername << "(terminate)..." << endl;
cancelled = true; cancelled = true;
......
...@@ -45,15 +45,7 @@ std::shared_ptr<DebugStream> LogAgregator::create( const std::string& logname ) ...@@ -45,15 +45,7 @@ std::shared_ptr<DebugStream> LogAgregator::create( const std::string& logname )
return l; return l;
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
void LogAgregator::add( DebugStream& log ) void LogAgregator::add( std::shared_ptr<DebugStream> l )
{
// очень не красиво создавать shared-указатель по объекту
// вместо maske_shared..
auto l = std::shared_ptr<DebugStream>(&log);
add(l);
}
// -------------------------------------------------------------------------
void LogAgregator::add( std::shared_ptr<DebugStream>& l )
{ {
auto i = lmap.find(l->getLogName()); auto i = lmap.find(l->getLogName());
if( i != lmap.end() ) if( i != lmap.end() )
......
...@@ -118,10 +118,11 @@ void PassiveObject::processingMessage( UniSetTypes::VoidMessage *msg ) ...@@ -118,10 +118,11 @@ void PassiveObject::processingMessage( UniSetTypes::VoidMessage *msg )
} }
catch( omniORB::fatalException& fe ) catch( omniORB::fatalException& fe )
{ {
if( ulog.is_crit() ) auto ul = ulog();
if( ul && ul->is_crit() )
{ {
ulog.crit() << myname << "(processingMessage): Caught omniORB::fatalException:" << endl; ul->crit() << myname << "(processingMessage): Caught omniORB::fatalException:" << endl;
ulog.crit() << myname << "(processingMessage): file: " << fe.file() ul->crit() << myname << "(processingMessage): file: " << fe.file()
<< " line: " << fe.line() << " line: " << fe.line()
<< " mesg: " << fe.errmsg() << endl; << " mesg: " << fe.errmsg() << endl;
} }
......
...@@ -516,12 +516,16 @@ void UniSetActivator::sysCommand( const UniSetTypes::SystemMessage *sm ) ...@@ -516,12 +516,16 @@ void UniSetActivator::sysCommand( const UniSetTypes::SystemMessage *sm )
case SystemMessage::LogRotate: case SystemMessage::LogRotate:
{ {
ulogsys << myname << "(sysCommand): logRotate" << endl; ulogsys << myname << "(sysCommand): logRotate" << endl;
auto ul = ulog();
if( !ul )
break;
// переоткрываем логи // переоткрываем логи
string fname = ulog.getLogFile(); string fname = ul->getLogFile();
if( !fname.empty() ) if( fname.empty() )
{ {
ulog.logFile(fname.c_str(),true); ul->logFile(fname.c_str(),true);
ulog << myname << "(sysCommand): ***************** ulog LOG ROTATE *****************" << endl; ulogany << myname << "(sysCommand): ***************** ulog LOG ROTATE *****************" << endl;
} }
} }
break; break;
......
...@@ -857,10 +857,10 @@ void UniSetObject::processingMessage( UniSetTypes::VoidMessage *msg ) ...@@ -857,10 +857,10 @@ void UniSetObject::processingMessage( UniSetTypes::VoidMessage *msg )
} }
catch( omniORB::fatalException& fe ) catch( omniORB::fatalException& fe )
{ {
if( ulog.is_crit() ) if( ulog()->is_crit() )
{ {
ulog.crit() << myname << "(processingMessage): Caught omniORB::fatalException:" << endl; ulog()->crit() << myname << "(processingMessage): Caught omniORB::fatalException:" << endl;
ulog.crit() << myname << "(processingMessage): file: " << fe.file() ulog()->crit() << myname << "(processingMessage): file: " << fe.file()
<< " line: " << fe.line() << " line: " << fe.line()
<< " mesg: " << fe.errmsg() << endl; << " mesg: " << fe.errmsg() << endl;
} }
......
...@@ -74,9 +74,17 @@ ostream& UniSetTypes::Configuration::help(ostream& os) ...@@ -74,9 +74,17 @@ ostream& UniSetTypes::Configuration::help(ostream& os)
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
namespace UniSetTypes namespace UniSetTypes
{ {
DebugStream ulog;
static shared_ptr<Configuration> uconf; static shared_ptr<Configuration> uconf;
static std::shared_ptr<DebugStream> _ulog;
std::shared_ptr<DebugStream> ulog()
{
if( _ulog )
return _ulog;
_ulog = make_shared<DebugStream>();
return _ulog;
}
std::shared_ptr<Configuration> uniset_conf() std::shared_ptr<Configuration> uniset_conf()
{ {
...@@ -216,7 +224,7 @@ void Configuration::initConfiguration( int argc, const char* const* argv ) ...@@ -216,7 +224,7 @@ void Configuration::initConfiguration( int argc, const char* const* argv )
} }
catch(...) catch(...)
{ {
ulog << "(Configuration): FAILED open configuration from " << fileConfName << endl; ulogany << "(Configuration): FAILED open configuration from " << fileConfName << endl;
throw; throw;
} }
...@@ -257,7 +265,7 @@ void Configuration::initConfiguration( int argc, const char* const* argv ) ...@@ -257,7 +265,7 @@ void Configuration::initConfiguration( int argc, const char* const* argv )
} }
// Настраиваем отладочные логи // Настраиваем отладочные логи
initDebug(ulog,"UniSetDebug"); initDebug(ulog(),"UniSetDebug");
// default init... // default init...
transientIOR = false; transientIOR = false;
...@@ -720,25 +728,42 @@ string Configuration::getPropByNodeName(const string& nodename, const string& pr ...@@ -720,25 +728,42 @@ string Configuration::getPropByNodeName(const string& nodename, const string& pr
return getProp(node,prop); return getProp(node,prop);
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
xmlNode* Configuration::initDebug( std::shared_ptr<DebugStream> deb, const string& _debname )
{
if( !deb )
return NULL;
return initDebug( deb.get(), _debname );
}
// -------------------------------------------------------------------------
xmlNode* Configuration::initDebug( DebugStream& deb, const string& _debname ) xmlNode* Configuration::initDebug( DebugStream& deb, const string& _debname )
{ {
return initDebug(&deb, _debname);
}
// -------------------------------------------------------------------------
xmlNode* Configuration::initDebug( DebugStream* deb, const string& _debname )
{
if( !deb )
return NULL;
if( _debname.empty() ) if( _debname.empty() )
{ {
deb << "(Configuration)(initDebug): INIT DEBUG FAILED!!!" << endl; deb->any() << "(Configuration)(initDebug): INIT DEBUG FAILED!!!" << endl;
return 0; return 0;
} }
string debname(_debname); string debname(_debname);
xmlNode* dnode = getNode(_debname); xmlNode* dnode = getNode(_debname);
if( dnode == NULL ) if( dnode == NULL )
deb << "(Configuration)(initDebug): WARNING! Not found conf. section for log '" << _debname << "'" << endl; deb->any() << "(Configuration)(initDebug): WARNING! Not found conf. section for log '" << _debname << "'" << endl;
else else
{ {
if( !getProp(dnode,"name").empty() ) if( !getProp(dnode,"name").empty() )
{ {
debname = getProp(dnode,"name"); debname = getProp(dnode,"name");
deb.setLogName(debname); deb->setLogName(debname);
} }
} }
...@@ -747,7 +772,7 @@ xmlNode* Configuration::initDebug( DebugStream& deb, const string& _debname ) ...@@ -747,7 +772,7 @@ xmlNode* Configuration::initDebug( DebugStream& deb, const string& _debname )
{ {
if( no_deb == _argv[i] ) if( no_deb == _argv[i] )
{ {
deb.addLevel(Debug::NONE); deb->addLevel(Debug::NONE);
return dnode; return dnode;
} }
} }
...@@ -757,13 +782,13 @@ xmlNode* Configuration::initDebug( DebugStream& deb, const string& _debname ) ...@@ -757,13 +782,13 @@ xmlNode* Configuration::initDebug( DebugStream& deb, const string& _debname )
{ {
string conf_debug_levels(getProp(dnode,"levels")); string conf_debug_levels(getProp(dnode,"levels"));
if( !conf_debug_levels.empty() ) if( !conf_debug_levels.empty() )
deb.addLevel( Debug::value(conf_debug_levels) ); deb->addLevel( Debug::value(conf_debug_levels) );
else else
deb.addLevel(Debug::NONE); deb->addLevel(Debug::NONE);
string debug_file(getProp(dnode,"file")); string debug_file(getProp(dnode,"file"));
if( !debug_file.empty() ) if( !debug_file.empty() )
deb.logFile(debug_file); deb->logFile(debug_file);
} }
// теперь смотрим командную строку // теперь смотрим командную строку
...@@ -776,15 +801,15 @@ xmlNode* Configuration::initDebug( DebugStream& deb, const string& _debname ) ...@@ -776,15 +801,15 @@ xmlNode* Configuration::initDebug( DebugStream& deb, const string& _debname )
{ {
if( log_in == _argv[i] ) // "--debug-log_in_file" if( log_in == _argv[i] ) // "--debug-log_in_file"
{ {
deb.logFile(_argv[i+1]); deb->logFile(_argv[i+1]);
} }
else if( add_level == _argv[i] ) // "--debug-add-levels" else if( add_level == _argv[i] ) // "--debug-add-levels"
{ {
deb.addLevel(Debug::value(_argv[i+1])); deb->addLevel(Debug::value(_argv[i+1]));
} }
else if( del_level == _argv[i] ) // "--debug-del-levels" else if( del_level == _argv[i] ) // "--debug-del-levels"
{ {
deb.delLevel(Debug::value(_argv[i+1])); deb->delLevel(Debug::value(_argv[i+1]));
} }
} }
...@@ -1031,8 +1056,9 @@ std::shared_ptr<Configuration> uniset_init( int argc, const char* const* argv, c ...@@ -1031,8 +1056,9 @@ std::shared_ptr<Configuration> uniset_init( int argc, const char* const* argv, c
atexit( UniSetActivator::normalexit ); atexit( UniSetActivator::normalexit );
set_terminate( UniSetActivator::normalterminate ); // ловушка для неизвестных исключений set_terminate( UniSetActivator::normalterminate ); // ловушка для неизвестных исключений
ulog()->setLogName("ulog");
string confile = UniSetTypes::getArgParam( "--confile", argc, argv, xmlfile ); string confile = UniSetTypes::getArgParam( "--confile", argc, argv, xmlfile );
ulog.setLogName("ulog");
UniSetTypes::uconf = make_shared<Configuration>(argc, argv, confile); UniSetTypes::uconf = make_shared<Configuration>(argc, argv, confile);
return UniSetTypes::uconf; return UniSetTypes::uconf;
} }
......
...@@ -87,7 +87,7 @@ TEST_CASE( "Configuration", "[Configuration]" ) ...@@ -87,7 +87,7 @@ TEST_CASE( "Configuration", "[Configuration]" )
{ {
int t_argc = 0; int t_argc = 0;
char t_argv[]={""}; char t_argv[]={""};
ulog.level(Debug::NONE); ulog()->level(Debug::NONE);
REQUIRE_THROWS_AS( Configuration(t_argc,(const char* const*)(t_argv),"tests_no_objectsmap.xml"), UniSetTypes::SystemError ); REQUIRE_THROWS_AS( Configuration(t_argc,(const char* const*)(t_argv),"tests_no_objectsmap.xml"), UniSetTypes::SystemError );
} }
...@@ -95,7 +95,7 @@ TEST_CASE( "Configuration", "[Configuration]" ) ...@@ -95,7 +95,7 @@ TEST_CASE( "Configuration", "[Configuration]" )
{ {
int t_argc = 0; int t_argc = 0;
char t_argv[]={""}; char t_argv[]={""};
ulog.level(Debug::NONE); ulog()->level(Debug::NONE);
REQUIRE_THROWS_AS( Configuration(t_argc,(const char* const*)(t_argv),"tests_no_uniset_section.xml"), UniSetTypes::SystemError ); REQUIRE_THROWS_AS( Configuration(t_argc,(const char* const*)(t_argv),"tests_no_uniset_section.xml"), UniSetTypes::SystemError );
} }
......
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