diff --git a/framework/areg/logging/LogScope.hpp b/framework/areg/logging/LogScope.hpp index a12abcae4..e6fbbb2c8 100644 --- a/framework/areg/logging/LogScope.hpp +++ b/framework/areg/logging/LogScope.hpp @@ -154,10 +154,6 @@ class AREG_API LogScope // Member variables ////////////////////////////////////////////////////////////////////////////// private: - /** - * \brief The name of log scope. It cannot be changed - **/ - const String mScopeName; /** * \brief The ID of log scope. It cannot be changed **/ @@ -166,6 +162,14 @@ class AREG_API LogScope * \brief The log message priority of the scope. **/ unsigned int mScopePrio; + /** + * \brief The name of log scope. It cannot be changed + **/ + const String mScopeName; + /** + * \brief The log scope is active or not. + **/ + const bool mIsRegistered; ////////////////////////////////////////////////////////////////////////////// // Hidden methods @@ -209,9 +213,9 @@ namespace std inline IEOutStream & operator << ( IEOutStream & stream, const LogScope & output ) { - stream << output.mScopeName; stream << output.mScopeId; stream << output.mScopePrio; + stream << output.mScopeName; return stream; } diff --git a/framework/areg/logging/NELogging.hpp b/framework/areg/logging/NELogging.hpp index 6e7480131..3ab54e334 100644 --- a/framework/areg/logging/NELogging.hpp +++ b/framework/areg/logging/NELogging.hpp @@ -80,9 +80,9 @@ namespace NELogging **/ inline sScopeInfo(const char* name, uint32_t id, uint32_t prio); - String scopeName; //!< The name of the scope or scope group. uint32_t scopeId; //!< The scope ID, can be 0 (NELogging::LOG_SCOPE_ID_NONE). For scope group should be 0. uint32_t scopePrio; //!< The scope priority. + String scopeName; //!< The name of the scope or scope group. }; //!< The list of scope update structure. @@ -620,7 +620,7 @@ inline IEOutStream& operator << (IEOutStream& stream, const NELogging::sLogMessa **/ inline const IEInStream& operator >> (const IEInStream& stream, NELogging::sScopeInfo & input) { - stream >> input.scopeName >> input.scopeId >> input.scopePrio; + stream >> input.scopeId >> input.scopePrio >> input.scopeName; return stream; } @@ -631,7 +631,7 @@ inline const IEInStream& operator >> (const IEInStream& stream, NELogging::sScop **/ inline IEOutStream& operator << (IEOutStream& stream, const NELogging::sScopeInfo & output) { - stream << output.scopeName << output.scopeId << output.scopePrio; + stream << output.scopeId << output.scopePrio << output.scopeName; return stream; } @@ -678,16 +678,16 @@ inline const char* NELogging::getString(NELogging::eLogPriority prio) } inline NELogging::sScopeInfo::sScopeInfo(void) - : scopeName ( String::EmptyString ) - , scopeId ( 0u ) + : scopeId ( 0u ) , scopePrio ( static_cast(NELogging::eLogPriority::PrioInvalid) ) + , scopeName (String::EmptyString) { } inline NELogging::sScopeInfo::sScopeInfo(const char* name, uint32_t id, uint32_t prio) - : scopeName (name) - , scopeId (id) + : scopeId (id) , scopePrio (prio) + , scopeName (name) { } diff --git a/framework/areg/logging/private/LogScope.cpp b/framework/areg/logging/private/LogScope.cpp index fe936618e..72ee1ea89 100644 --- a/framework/areg/logging/private/LogScope.cpp +++ b/framework/areg/logging/private/LogScope.cpp @@ -30,23 +30,28 @@ #if AREG_LOGS LogScope::LogScope( const char * scopeName, NELogging::eLogPriority priority /*= NELogging::PrioNotset*/ ) - : mScopeName ( scopeName != nullptr ? scopeName : "" ) - , mScopeId ( NELogging::makeScopeId(mScopeName.getString()) ) + : mScopeId ( NELogging::makeScopeId(scopeName) ) , mScopePrio ( priority ) + , mScopeName ( scopeName != nullptr ? scopeName : "" ) + , mIsRegistered ( true ) { LogManager::registerLogScope( self() ); } LogScope::LogScope(const IEInStream & stream) - : mScopeName (stream) - , mScopeId (stream.read32Bits()) - , mScopePrio (stream.read32Bits()) + : mScopeId ( stream.read32Bits() ) + , mScopePrio ( stream.read32Bits() ) + , mScopeName ( stream ) + , mIsRegistered ( false ) { } LogScope::~LogScope( void ) { - LogManager::unregisterLogScope( self() ); + if (mIsRegistered) + { + LogManager::unregisterLogScope(self()); + } } void LogScope::setPriority(const char* newPrio) @@ -62,16 +67,18 @@ void LogScope::setPriority(const String& newPrio) #else // AREG_LOGS LogScope::LogScope(const char* /*scopeName*/, NELogging::eLogPriority /*priority*/ /*= NELogging::PrioNotset*/) - : mScopeName () - , mScopeId ( 0 ) + : mScopeId ( 0 ) , mScopePrio ( static_cast(NELogging::eLogPriority::PrioInvalid) ) + , mScopeName ( ) + , mIsRegistered (false) { } LogScope::LogScope(const IEInStream& /*stream*/ ) - : mScopeName () - , mScopeId ( 0 ) + : mScopeId ( 0 ) , mScopePrio ( static_cast(NELogging::eLogPriority::PrioInvalid) ) + , mScopeName ( ) + , mIsRegistered (false) { } diff --git a/framework/aregextend/db/private/LogSqliteDatabase.cpp b/framework/aregextend/db/private/LogSqliteDatabase.cpp index 6ae2a687a..aa50eae88 100644 --- a/framework/aregextend/db/private/LogSqliteDatabase.cpp +++ b/framework/aregextend/db/private/LogSqliteDatabase.cpp @@ -677,14 +677,7 @@ bool LogSqliteDatabase::logInstanceDisconnected(const ITEM_ID& cookie, const Dat bool LogSqliteDatabase::logScopeActivate(const NELogging::sScopeInfo & scope, const ITEM_ID& cookie, const DateTime& timestamp) { - char sql[SQL_LEN]; - String::formatString( sql, SQL_LEN, _fmtScopes.data() - , static_cast(scope.scopeId) - , static_cast(cookie) - , static_cast(scope.scopePrio) - , scope.scopeName.getString() - , static_cast(timestamp.getTime())); - return mDatabase.execute(sql); + return logScopeActivate(scope.scopeName, scope.scopeId, scope.scopePrio, cookie, timestamp); } uint32_t LogSqliteDatabase::logScopesActivate(const NELogging::ScopeNames& scopes, const ITEM_ID& cookie, const DateTime& timestamp) diff --git a/framework/areglogger/client/LogObserverBase.hpp b/framework/areglogger/client/LogObserverBase.hpp index 73e55dc74..e1ffdd253 100644 --- a/framework/areglogger/client/LogObserverBase.hpp +++ b/framework/areglogger/client/LogObserverBase.hpp @@ -453,9 +453,8 @@ class LOGGER_API LogObserverBase /** * \brief The callback of the event triggered when connection with the log collector service is lost. - * \param instances The list of disconnected instances. **/ - virtual void onLogServiceDisconnected(const std::map& instances) = 0; + virtual void onLogServiceDisconnected(void) = 0; /** * \brief The callback of the event triggered when receive the list of the scopes registered in an application. diff --git a/framework/areglogger/client/private/LoggerClient.cpp b/framework/areglogger/client/private/LoggerClient.cpp index b191efc9f..19bb720e3 100644 --- a/framework/areglogger/client/private/LoggerClient.cpp +++ b/framework/areglogger/client/private/LoggerClient.cpp @@ -477,7 +477,7 @@ void LoggerClient::disconnectServiceHost(void) FuncInstancesDisconnect callback{ mCallbacks != nullptr ? mCallbacks->evtInstDisconnected : nullptr }; if (LogObserverBase::_theLogObserver != nullptr) { - LogObserverBase::_theLogObserver->onLogServiceDisconnected(mInstances.getData()); + LogObserverBase::_theLogObserver->onLogServiceDisconnected(); } else if (callback != nullptr) { diff --git a/framework/areglogger/client/private/ObserverMessageProcessor.cpp b/framework/areglogger/client/private/ObserverMessageProcessor.cpp index 8b5aa2a9e..4f0bd009c 100644 --- a/framework/areglogger/client/private/ObserverMessageProcessor.cpp +++ b/framework/areglogger/client/private/ObserverMessageProcessor.cpp @@ -87,8 +87,7 @@ void ObserverMessageProcessor::notifyLogRegisterScopes(const RemoteMessage& msgR sLogScope& entry{ scopes[i] }; entry.lsId = scope.getScopeId(); entry.lsPrio = scope.getPriority(); - NEString::copyString(entry.lsName, static_cast(LENGTH_SCOPE), scope.getScopeName().getString(), scope.getScopeName().getLength()); - + NEMemory::memCopy(entry.lsName, LENGTH_SCOPE, scope.getScopeName().getString(), scope.getScopeName().getLength() + 1); mLoggerClient.mLogDatabase.logScopeActivate(scope.getScopeName(), scope.getScopeId(), scope.getPriority(), cookie, now); } @@ -138,7 +137,7 @@ void ObserverMessageProcessor::notifyLogUpdateScopes(const RemoteMessage& msgRec sLogScope& entry{ scopes[i] }; entry.lsId = scope.getScopeId(); entry.lsPrio = scope.getPriority(); - NEString::copyString(entry.lsName, static_cast(LENGTH_SCOPE), scope.getScopeName().getString(), scope.getScopeName().getLength()); + NEMemory::memCopy(entry.lsName, LENGTH_SCOPE, scope.getScopeName().getString(), scope.getScopeName().getLength() + 1); mLoggerClient.mLogDatabase.logScopeActivate(scope.getScopeName(), scope.getScopeId(), scope.getPriority(), cookie, now); } @@ -197,8 +196,8 @@ void ObserverMessageProcessor::notifyLogMessage(const RemoteMessage& msgReceived msgLog.msgScopeId = static_cast(msgRemote->logScopeId); NEMemory::memCopy(msgLog.msgLogText, LENGTH_MESSAGE , msgRemote->logMessage , msgRemote->logMessageLen + 1); - NEMemory::memCopy(msgLog.msgThread, LENGTH_NAME , msgRemote->logThread , msgRemote->logThreadLen + 1); - NEMemory::memCopy(msgLog.msgModule, LENGTH_NAME , msgRemote->logModule , msgRemote->logModuleLen + 1); + NEMemory::memCopy(msgLog.msgThread, LENGTH_NAME , msgRemote->logThread , msgRemote->logThreadLen + 1); + NEMemory::memCopy(msgLog.msgModule, LENGTH_NAME , msgRemote->logModule , msgRemote->logModuleLen + 1); } else if (mLoggerClient.mCallbacks->evtLogMessageEx != nullptr) { @@ -227,18 +226,31 @@ void ObserverMessageProcessor::_clientsConnected(const RemoteMessage& msgReceive FuncInstancesConnect callback{ nullptr }; sLogInstance* listInstances{ nullptr }; int size{ static_cast(listConnected.getSize()) }; + if (size == 0) + return; do { Lock lock(mLoggerClient.mLock); - if (LogObserverBase::_theLogObserver == nullptr) + DateTime now(DateTime::getNow()); + + if (LogObserverBase::_theLogObserver != nullptr) { - callback = mLoggerClient.mCallbacks != nullptr ? mLoggerClient.mCallbacks->evtInstConnected : nullptr; - } + for (int i = 0; i < size; ++i) + { + const NEService::sServiceConnectedInstance& client{ listConnected[static_cast(i)] }; + auto added = mLoggerClient.mInstances.addIfUnique(client.ciCookie, client, false); + if (added.second) + { + mLoggerClient.mLogDatabase.logInstanceConnected(client, now); + } + } - if (size > 0) + mLoggerClient.mLogDatabase.commit(true); + } + else { - DateTime now(DateTime::getNow()); + callback = mLoggerClient.mCallbacks != nullptr ? mLoggerClient.mCallbacks->evtInstConnected : nullptr; listInstances = new sLogInstance[size]; for (int i = 0; i < size; ++i) @@ -257,20 +269,13 @@ void ObserverMessageProcessor::_clientsConnected(const RemoteMessage& msgReceive inst.liBitness = static_cast(client.ciBitness); inst.liCookie = client.ciCookie; inst.liTimestamp = client.ciTimestamp; - NEString::copyString(inst.liName - , static_cast(LENGTH_NAME) - , client.ciInstance.c_str() - , static_cast(client.ciInstance.length())); - NEString::copyString(inst.liLocation - , static_cast(LENGTH_LOCATION) - , client.ciLocation.c_str() - , static_cast(client.ciLocation.length())); + NEMemory::memCopy(inst.liName , LENGTH_NAME , client.ciInstance.c_str(), static_cast(client.ciInstance.length()) + 1); + NEMemory::memCopy(inst.liLocation, LENGTH_LOCATION, client.ciLocation.c_str(), static_cast(client.ciLocation.length()) + 1); } } mLoggerClient.mLogDatabase.commit(true); } - } while (false); if (LogObserverBase::_theLogObserver != nullptr)