Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions framework/areg/logging/LogScope.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
**/
Expand All @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down
14 changes: 7 additions & 7 deletions framework/areg/logging/NELogging.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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<uint32_t>(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)
{
}

Expand Down
27 changes: 17 additions & 10 deletions framework/areg/logging/private/LogScope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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<unsigned int>(NELogging::eLogPriority::PrioInvalid) )
, mScopeName ( )
, mIsRegistered (false)
{
}

LogScope::LogScope(const IEInStream& /*stream*/ )
: mScopeName ()
, mScopeId ( 0 )
: mScopeId ( 0 )
, mScopePrio ( static_cast<unsigned int>(NELogging::eLogPriority::PrioInvalid) )
, mScopeName ( )
, mIsRegistered (false)
{
}

Expand Down
9 changes: 1 addition & 8 deletions framework/aregextend/db/private/LogSqliteDatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t>(scope.scopeId)
, static_cast<uint64_t>(cookie)
, static_cast<uint32_t>(scope.scopePrio)
, scope.scopeName.getString()
, static_cast<uint64_t>(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)
Expand Down
3 changes: 1 addition & 2 deletions framework/areglogger/client/LogObserverBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ITEM_ID, NEService::sServiceConnectedInstance>& 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.
Expand Down
2 changes: 1 addition & 1 deletion framework/areglogger/client/private/LoggerClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
43 changes: 24 additions & 19 deletions framework/areglogger/client/private/ObserverMessageProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<NEString::CharCount>(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);
}

Expand Down Expand Up @@ -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<NEString::CharCount>(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);
}

Expand Down Expand Up @@ -197,8 +196,8 @@ void ObserverMessageProcessor::notifyLogMessage(const RemoteMessage& msgReceived
msgLog.msgScopeId = static_cast<unsigned int>(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)
{
Expand Down Expand Up @@ -227,18 +226,31 @@ void ObserverMessageProcessor::_clientsConnected(const RemoteMessage& msgReceive
FuncInstancesConnect callback{ nullptr };
sLogInstance* listInstances{ nullptr };
int size{ static_cast<int>(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<uint32_t>(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)
Expand All @@ -257,20 +269,13 @@ void ObserverMessageProcessor::_clientsConnected(const RemoteMessage& msgReceive
inst.liBitness = static_cast<uint32_t>(client.ciBitness);
inst.liCookie = client.ciCookie;
inst.liTimestamp = client.ciTimestamp;
NEString::copyString(inst.liName
, static_cast<NEString::CharCount>(LENGTH_NAME)
, client.ciInstance.c_str()
, static_cast<NEString::CharCount>(client.ciInstance.length()));
NEString::copyString(inst.liLocation
, static_cast<NEString::CharCount>(LENGTH_LOCATION)
, client.ciLocation.c_str()
, static_cast<NEString::CharCount>(client.ciLocation.length()));
NEMemory::memCopy(inst.liName , LENGTH_NAME , client.ciInstance.c_str(), static_cast<int>(client.ciInstance.length()) + 1);
NEMemory::memCopy(inst.liLocation, LENGTH_LOCATION, client.ciLocation.c_str(), static_cast<int>(client.ciLocation.length()) + 1);
}
}

mLoggerClient.mLogDatabase.commit(true);
}

} while (false);

if (LogObserverBase::_theLogObserver != nullptr)
Expand Down
Loading