Skip to content

Commit 3174831

Browse files
authored
Merge pull request #538 from aregtech/feature/536-log-database-to-extract-messages
536 log database to extract messages
2 parents feafa8f + 6ff6af5 commit 3174831

File tree

11 files changed

+1069
-290
lines changed

11 files changed

+1069
-290
lines changed

framework/areg/base/GETypes.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@
5858

5959
#include <stddef.h>
6060

61-
//! The type defining ID. It is 64-bit in 64-bit systems.
62-
typedef unsigned long id_type;
63-
6461
//! The digital value type of the pointer.
6562
#ifdef BIT64
6663

64+
//! The type defining ID. It is 64-bit in 64-bit systems.
65+
typedef uint64_t id_type;
66+
6767
#ifdef _UINTPTR_T_DEFINED
6868
typedef uintptr_t ptr_type;
6969
#else // !_UINTPTR_T_DEFINED
@@ -72,6 +72,9 @@ typedef unsigned long id_type;
7272

7373
#else // defined(BIT32)
7474

75+
//! The type defining ID. It is 64-bit in 64-bit systems.
76+
typedef uint32_t id_type;
77+
7578
#ifdef _UINTPTR_T_DEFINED
7679
typedef uintptr_t ptr_type;
7780
#else // !_UINTPTR_T_DEFINED

framework/areg/logging/IELogDatabaseEngine.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class AREG_API IELogDatabaseEngine : public IEDatabaseEngine
5757
* \brief Returns true if the database and the log tables are initialized,
5858
* and ready to log messages.
5959
**/
60-
virtual bool tablesInitialized(void) const = 0;
60+
virtual bool areTablesInitialized(void) const = 0;
6161

6262
/**
6363
* \brief Called when logging message should be saved in the database.

framework/areg/logging/NELogging.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,9 @@ namespace NELogging
310310
**/
311311
sLogMessage & operator = (const sLogMessage & src);
312312

313-
NELogging::eLogDataType logDataType; //!< The type of log message data.
314-
NELogging::eLogMessageType logMsgType; //!< The type of the logging message.
315-
NELogging::eLogPriority logMessagePrio; //!< The log message priority
313+
NELogging::eLogDataType logDataType; //!< The type of log message data.
314+
NELogging::eLogMessageType logMsgType; //!< The type of the logging message.
315+
NELogging::eLogPriority logMessagePrio; //!< The log message priority
316316
ITEM_ID logSource; //!< The ID of the source that generated logging message.
317317
ITEM_ID logTarget; //!< The ID of the target to send logging message, valid only in case of TCP/IP logging.
318318
ITEM_ID logCookie; //!< The cookie set by the networking service, i.e. the log collector. Valid only in case of TCP/IP logging.

framework/aregextend/db/LogSqliteDatabase.hpp

Lines changed: 87 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,16 @@
1818
* Include files.
1919
************************************************************************/
2020
#include "areg/base/GEGlobal.h"
21+
22+
#include "aregextend/db/SqliteDatabase.hpp"
23+
#include "aregextend/db/SqliteStatement.hpp"
24+
#include "areg/component/NEService.hpp"
25+
#include "areg/logging/NELogging.hpp"
2126
#include "areg/logging/IELogDatabaseEngine.hpp"
2227
#include "areg/base/String.hpp"
2328

24-
#if 0
2529
#include <vector>
2630

27-
enum eLogItemType
28-
{
29-
ItemUnknown = 0 //!< Unknown log item type
30-
, ItemInstance //!< Log instance item
31-
, ItemThread //!< Log thread item
32-
, ItemScope //!< Log scope item
33-
, ItemPriority //!< Log priority item
34-
};
35-
36-
struct sLogItem
37-
{
38-
ITEM_ID itemId { 0 }; //<! The ID of the log item
39-
String itemName{ }; //!< The name of the log item
40-
};
41-
42-
struct sLogItemList
43-
{
44-
eLogItemType itemType{ ItemUnknown }; //!< The type of the log item
45-
std::vector<sLogItem> itemList{ }; //!< The list of log items
46-
};
47-
#endif
4831
//////////////////////////////////////////////////////////////////////////
4932
// LogSqliteDatabase class declaration
5033
//////////////////////////////////////////////////////////////////////////
@@ -150,7 +133,7 @@ class LogSqliteDatabase : public IELogDatabaseEngine
150133
* \brief Returns true if the database and the log tables are initialized,
151134
* and ready to log messages.
152135
**/
153-
virtual bool tablesInitialized(void) const override;
136+
virtual bool areTablesInitialized(void) const override;
154137

155138
/**
156139
* \brief Called when logging message should be saved in the database.
@@ -231,30 +214,89 @@ class LogSqliteDatabase : public IELogDatabaseEngine
231214
//////////////////////////////////////////////////////////////////////////
232215
// Attributes and operations
233216
//////////////////////////////////////////////////////////////////////////
234-
#if 0
235-
std::vector<String> getLogInstanceNames(void) const;
236217

237-
std::vector<ITEM_ID> getLogInstances(void) const;
218+
/**
219+
* \brief Call to query and get list of names of connected instances from log database.
220+
**/
221+
std::vector<String> getLogInstanceNames(void);
222+
void getLogInstanceNames(std::vector<String>& names);
238223

239-
std::vector<String> getLogThreadNames(void) const;
224+
/**
225+
* \brief Call to query and get list of IDs of connected instances from log database.
226+
**/
227+
std::vector<ITEM_ID> getLogInstances(void);
228+
void getLogInstances(std::vector<ITEM_ID>& ids);
240229

241-
std::vector<ITEM_ID> getLogThreads(void) const;
230+
/**
231+
* \brief Call to query and get list of names of threads of the connected instances from log database.
232+
**/
233+
std::vector<String> getLogThreadNames(void);
234+
void getLogThreadNames(std::vector<String>& names);
242235

243-
std::vector<String> getLogScopeNames(void) const;
236+
/**
237+
* \brief Call to query and get list of IDs of threads of the connected instances from log database.
238+
**/
239+
std::vector<ITEM_ID> getLogThreads(void);
240+
void getLogThreads(std::vector<ITEM_ID>& ids);
244241

245-
std::vector<ITEM_ID> getLogScopes(void) const;
242+
/**
243+
* \brief Call to get the list of log priorities.
244+
**/
245+
std::vector<String> getPriorityNames(void);
246+
void getPriorityNames(std::vector<String>& names);
246247

247-
std::vector<String> getPriorityNames(void) const;
248+
/**
249+
* \brief Call to query and get information of connected instances from log database.
250+
* This query will receive list of all registered instances.
251+
**/
252+
std::vector< NEService::sServiceConnectedInstance> getLogInstanceInfos(void);
253+
void getLogInstanceInfos(std::vector< NEService::sServiceConnectedInstance>& infos);
248254

249-
std::vector<NELogging::sScopeInfo> getLogInstScopes(ITEM_ID instId) const;
255+
/**
256+
* \brief Call to query and get information of log scopes of specified instance from log database.
257+
* This query will receive list of all registered scopes.
258+
* \param instID The ID of the instance.
259+
**/
260+
std::vector<NELogging::sScopeInfo> getLogInstScopes(ITEM_ID instId);
261+
void getLogInstScopes(std::vector<NELogging::sScopeInfo>& scopes, ITEM_ID instId);
250262

251-
std::vector<SharedBuffer> getLodMessages(void) const;
263+
/**
264+
* \brief Call to get all log messages from log database.
265+
**/
266+
std::vector<SharedBuffer> getLogMessages(void);
267+
void getLogMessages(std::vector<SharedBuffer>& messages);
252268

253-
std::vector<SharedBuffer> getLodInstMessages(ITEM_ID instId) const;
269+
/**
270+
* \brief Call to get log messages of the specified instance from log database.
271+
* If `instId` is `NEService::COOKIE_ANY` it receives the list of all instances
272+
* similar to the call to `getLogMessages()`.
273+
* \param instId The ID of the instance to get log messages.
274+
* If `NEService::COOKIE_ANY` it receives log messages of all instances.
275+
**/
276+
std::vector<SharedBuffer> getLogInstMessages(ITEM_ID instId = NEService::COOKIE_ANY);
277+
void getLogInstMessages(std::vector<SharedBuffer>& messages, ITEM_ID instId = NEService::COOKIE_ANY);
254278

255-
std::vector<SharedBuffer> getLodScopeMessages(ITEM_ID instId, uint32_t scopeId) const;
279+
/**
280+
* \brief Call to get log messages of the specified scope from log database.
281+
* If `scopeId` is `0` it receives the list of all scopes
282+
* similar to the call to `getLogMessages()`.
283+
* \param scopeId The ID of the scope to get log messages.
284+
* If `0` it receives log messages of all scopes.
285+
**/
286+
std::vector<SharedBuffer> getLogScopeMessages(uint32_t scopeId = 0);
287+
void getLogScopeMessages(std::vector<SharedBuffer>& messages, uint32_t scopeId = 0);
256288

257-
#endif
289+
/**
290+
* \brief Call to get log messages of the specified instance and log scope ID from log database.
291+
* If `instId` is `NEService::COOKIE_ANY` and `scopeId` is `0`, it receives the list of all logs
292+
* similar to the call to `getLogMessages()`.
293+
* \param instId The ID of the instance to get log messages.
294+
* If `NEService::COOKIE_ANY` it receives log messages of all instances.
295+
* \param scopeId The ID of the scope to get log messages.
296+
* If `0` it receives log messages of all scopes.
297+
**/
298+
std::vector<SharedBuffer> getLogMessages(ITEM_ID instId, uint32_t scopeId);
299+
void getLogMessages(std::vector<SharedBuffer>& messages, ITEM_ID instId, uint32_t scopeId);
258300

259301
//////////////////////////////////////////////////////////////////////////
260302
// Hidden methods
@@ -267,11 +309,6 @@ class LogSqliteDatabase : public IELogDatabaseEngine
267309
**/
268310
inline bool _open(const String& dbPath);
269311

270-
/**
271-
* \brief Closes previously opened database and releases resources.
272-
**/
273-
inline void _close(void);
274-
275312
/**
276313
* \brief In the opened database file, creates the tables required to save logs.
277314
**/
@@ -287,29 +324,26 @@ class LogSqliteDatabase : public IELogDatabaseEngine
287324
**/
288325
inline void _initialize(void);
289326

290-
/**
291-
* \brief Executes the SQL script. The database should be already opened and initialized.
292-
**/
293-
inline bool _execute(const char * sql);
327+
inline void _copyLogMessage(SqliteStatement& stmt, SharedBuffer & buf);
294328

295329
//////////////////////////////////////////////////////////////////////////
296330
// Member variables.
297331
//////////////////////////////////////////////////////////////////////////
298332
protected:
299333
//!< The path to the SQLite database file.
300-
String mDbPath;
334+
SqliteDatabase mDatabase;
301335

302-
//!< The initial path to the SQLIte database file. The path may contain mask like timestamp.
303-
String mDbInitPath;
336+
//!< The statement to log messages in the database.
337+
SqliteStatement mStmtLogs;
304338

305-
//!< The SQLite database object.
306-
void * mDbObject;
339+
//!< The initial path to the SQLIte database file. The path may contain mask like timestamp.
340+
String mDbInitPath;
307341

308342
//!< Flag, indicating whether the database and data tables are initialized or not.
309-
bool mIsInitialized;
343+
bool mIsInitialized;
310344

311345
//!< Flag, indicating whether the database logging is enabled or not.
312-
bool mDbLogEnabled;
346+
bool mDbLogEnabled;
313347

314348
//////////////////////////////////////////////////////////////////////////
315349
// Forbidden calls.
@@ -334,7 +368,7 @@ inline void LogSqliteDatabase::setDatabaseLoggingEnabled(bool enable)
334368

335369
inline const String& LogSqliteDatabase::getDatabasePath(void) const
336370
{
337-
return mDbPath;
371+
return mDatabase.getPath();
338372
}
339373

340374
inline const String& LogSqliteDatabase::getInitialDatabasePath(void) const

0 commit comments

Comments
 (0)