Skip to content

Commit

Permalink
Tested and enabled remote logging, fixed bugs in ring stack. (#268)
Browse files Browse the repository at this point in the history
* Tested and enabled remote logging, fixed bugs in ring stack.
* Fixed reading configuration for queue size.
* Fixed tests and segmentation fault issue.
  • Loading branch information
aregtech authored Nov 29, 2023
1 parent d0aeb26 commit 531c168
Show file tree
Hide file tree
Showing 65 changed files with 1,634 additions and 939 deletions.
50 changes: 6 additions & 44 deletions examples/04_trace/config/areg.init
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
# Meaning of Layout format:
# The Layout Format is relevant only when logs the messages in the plain text file.
# The Layout Format specification fields are following:
%a -- outputs the ID of a logging object set by the logger.
%b -- outputs the module name of the logging object.
# %c -- output tick-count value since process start
# %d -- output day and time data
# %e -- output module (process) ID
Expand Down Expand Up @@ -111,57 +113,17 @@ log::*::enable = true # Global logging ena
log::*::enable::remote = false # Remote logging enable / disable flag
log::*::enable::file = true # File logging enable / disable flag
log::*::enable::debug = false # Debug output console logging enable / disable flag
log::*::enable::db = false # Database logging enable / disable flag
log::*::file::location = ./logs/%appname%_%time%.log # Log file location and masks
log::*::file::append = false # Append logs at the end of file
log::*::remote::stack = 100 # Queue stack size in remote logging, 0 means no queuing
log::*::remote::queue = 100 # Queue stack size in remote logging, 0 means no queuing
log::*::remote::service = logger # The service name of the remote logging

# ---------------------------------------------------------------------------
# Database logging settings (not supported at the moment!!!)
# ---------------------------------------------------------------------------
log::*::db::location = # Database location
log::*::db::append = true # Append logs
log::*::db::driver = # Database driver
log::*::db::address = 127.0.0.1 # Database connection IP-address
log::*::db::port = 1234 # Database connection IP-port
log::*::db::username = areg # Database connection user name
log::*::db::password = areg # Database connection password
log::*::db::name = # Database name

# ---------------------------------------------------------------------------
# Log message layout in the file
# ---------------------------------------------------------------------------
log::*::layout::enter = %d: [ %t %x.%z: Enter -->]%n # Enter scope layout
log::*::layout::message = %d: [ %t %p >>> ] %m%n # Log message layout
log::*::layout::exit = %d: [ %t %x.%z: Exit <-- ]%n # Exit scope layout

# ###########################################################################
# Remote services
# ###########################################################################

# ---------------------------------------------------------------------------
# List of remote services
# ---------------------------------------------------------------------------
service::*::list = router | logger # The list of available remote services

# ---------------------------------------------------------------------------
# Message router settings
# ---------------------------------------------------------------------------
router::*::service = mcrouter # The name of the router service (process name)
router::*::connect = tcpip # The list of supported communication protocols
router::*::enable::tcpip = true # Communication protocol enable / disable flag
router::*::address::tcpip = 127.0.0.1 # Protocol specific connection IP-address
router::*::port::tcpip = 8181 # Protocol specific connection port number

# ---------------------------------------------------------------------------
# Remote logger settings
# ---------------------------------------------------------------------------
logger::*::service = logger # The name of the router service (process name)
logger::*::connect = tcpip # The list of supported communication protocols
logger::*::enable::tcpip = true # Communication protocol enable / disable flag
logger::*::address::tcpip = 127.0.0.1 # Protocol specific connection IP-address
logger::*::port::tcpip = 8282 # Protocol specific connection port number
log::*::layout::enter = %d: [ %t %x.%z: Enter -->]%n # Enter scope layout
log::*::layout::message = %d: [ %t %p >>> ] %m%n # Log message layout
log::*::layout::exit = %d: [ %t %x.%z: Exit <-- ]%n # Exit scope layout

# #######################################
# Application(s) Scopes
Expand Down
4 changes: 2 additions & 2 deletions examples/10_locsvc/locservice/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ int main()
std::cout << "A Demo to demonstrate simple request, response and broadcast ..." << std::endl;

// force to start logging with default settings
TRACER_CONFIGURE_AND_START( nullptr );
Application::initApplication( true, true, false, true, true, nullptr );
Application::initApplication( true, true, false, true, false, nullptr );
TRACER_CONFIGURE_AND_START(nullptr);

do
{
Expand Down
2 changes: 2 additions & 0 deletions framework/areg.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@
<ClCompile Include="areg\trace\private\LoggerBase.cpp" />
<ClCompile Include="areg\component\private\WatchdogManager.cpp" />
<ClCompile Include="areg\persist\private\ConfigManager.cpp" />
<ClCompile Include="areg\persist\private\IEConfigurationListener.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="areg\base\DateTime.hpp" />
Expand Down Expand Up @@ -400,6 +401,7 @@
<ClInclude Include="areg\trace\private\LoggerBase.hpp" />
<ClInclude Include="areg\trace\private\NELogging.hpp" />
<ClInclude Include="areg\persist\PropertyKey.hpp" />
<ClInclude Include="areg\persist\IEConfigurationListener.hpp" />
<ClInclude Include="system\posix\GEPosix.h" />
<ClInclude Include="system\windows\GEWindows.h" />
<ClInclude Include="system\GEPlatform.h" />
Expand Down
6 changes: 6 additions & 0 deletions framework/areg.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,9 @@
<ClCompile Include="areg\ipc\private\NEConnection.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="areg\persist\private\IEConfigurationListener.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="system\windows\GEWindows.h">
Expand Down Expand Up @@ -1112,6 +1115,9 @@
<ClInclude Include="areg\ipc\private\NEConnection.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="areg\persist\IEConfigurationListener.hpp">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="areg\resources\areg_post_build.bat">
Expand Down
23 changes: 19 additions & 4 deletions framework/areg/appbase/Application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
#include "areg/component/NERegistry.hpp"
#include "areg/persist/ConfigManager.hpp"

/************************************************************************
* Dependencies.
************************************************************************/
class IEConfigurationListener;

//////////////////////////////////////////////////////////////////////////
// Dependencies
//////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -86,6 +91,9 @@ class AREG_API Application
* \param startTimer If true, application starts timer manager. If Service Managers, Timer Manager automatically starts.
* \param startWatchdog If true, application starts watchdog manager, so that it can track the component threads.
* \param configFile If nullptr or empty, configures Tracing from specified file. Default location is './config/areg.init' (NEApplication::DEFAULT_CONFIG_FILE)
* \param listener A pointer to the configuration listener. If the pointer is valid, the listener is notified before and after loading configuration,
* as well as if loading configuration fails and the default configuration is set.
* By default, the pointer to listener is null, so that no notification is triggered.
* \see release, loadModel
*
* \example Initialize Application
Expand All @@ -109,7 +117,8 @@ class AREG_API Application
, bool startRouting = true
, bool startTimer = true
, bool startWatchdog = false
, const char * configFile = NEApplication::DEFAULT_CONFIG_FILE.data() );
, const char * configFile = NEApplication::DEFAULT_CONFIG_FILE.data()
, IEConfigurationListener * listener = nullptr);

/**
* \brief Call to stop all components, unload models, stop services and release resources.
Expand Down Expand Up @@ -361,10 +370,12 @@ class AREG_API Application
* \brief Loads the configuration from the given file.
* \param fileName The relative or absolute path to the file to read configurations.
* If nullptr, loads configuration from default file './config/areg.init' (NEApplication::DEFAULT_CONFIG_FILE).
* \param listener The pointer to the configuration listener. If valid, the notifications are triggered before and after
* reading configuration from file. If listener is null or loading configuration failed, no notification is triggered.
* \return Returns true if succeeded to load configuration.
* If fails, loads default configuration and returns false.
**/
static bool loadConfiguration(const char * fileName = nullptr);
static bool loadConfiguration(const char * fileName = nullptr, IEConfigurationListener * listener = nullptr);

/**
* \brief Saves current configuration in the given file.
Expand All @@ -374,17 +385,21 @@ class AREG_API Application
* If nullptr, saves configuration in the same file that was read.
* If default configuration was loaded, saves all configuration in the
* default file './config/areg.init' (NEApplication::DEFAULT_CONFIG_FILE).
* \param listener The pointer to the configuration listener. If valid, the notifications are triggered before and after
* saving configuration to file. If listener is null or saving configuration failed, no notification is triggered.
* \return Returns true if succeeded to save configuration.
* Otherwise, returns false.
**/
static bool saveConfiguration(const char * fileName = nullptr);
static bool saveConfiguration(const char * fileName = nullptr, IEConfigurationListener * listener = nullptr);

/**
* \brief Loads default configuration properties defined in NEApplication::DefaultReadonlyProperties
* and in the NEApplication::DefaultLogScopesConfig. This will discard the previous configuration
* if the application was already configured.
* \param listener The pointer to the configuration listener. If valid, the notifications are triggered if default
* configuration is set. If listener is null, no notification is triggered.
**/
static void setupDefaultConfiguration(void);
static void setupDefaultConfiguration(IEConfigurationListener * listener = nullptr);

/**
* \brief Returns true if the application is already configured.
Expand Down
6 changes: 3 additions & 3 deletions framework/areg/appbase/NEApplication.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ namespace NEApplication
* \brief NEApplication::DEFAULT_LOG_QUEUE_SIZE
* The default size to queue logs in the stack, used for remote logging.
**/
constexpr uint32_t DEFAULT_LOG_QUEUE_SIZE { 30 };
constexpr uint32_t DEFAULT_LOG_QUEUE_SIZE { 100 };

/**
* \brief NEApplication::DEFAULT_LOG_FILE
Expand Down Expand Up @@ -227,13 +227,13 @@ namespace NEApplication
, { {"log" , "*" , "version" , "" }, NETrace::LOG_VERSION } //!< The logging version.
, { {"log" , "*" , "target" , "" }, "remote | file | debug | db" } //!< The logging types.
, { {"log" , "*" , "enable" , "" }, "true" } //!< The logging enabled / disabled status.
, { {"log" , "*" , "enable" , "remote" }, "false" } //!< The logging in remote log collector enabled / disabled flag.
, { {"log" , "*" , "enable" , "remote" }, "true" } //!< The logging in remote log collector enabled / disabled flag.
, { {"log" , "*" , "enable" , "file" }, "true" } //!< The logging in file enabled / disabled flag.
, { {"log" , "*" , "enable" , "output" }, "false" } //!< The logging in output console enabled / disabled flag.
, { {"log" , "*" , "enable" , "db" }, "false" } //!< The logging in database enabled / disabled flag.
, { {"log" , "*" , "file" , "location"}, DEFAULT_LOG_FILE } //!< The log file location and file name mask.
, { {"log" , "*" , "file" , "append" }, "false" } //!< The flag to append logs into the file.
, { {"log" , "*" , "remote" , "size" }, "100" } //!< The queue size of remote logging.
, { {"log" , "*" , "remote" , "queue" }, "100" } //!< The queue size of remote logging.
, { {"log" , "*" , "remote" , "service" }, "logger" } //!< The service name of the remote logging.
, { {"log" , "*" , "layout" , "enter" }, DEFAULT_LAYOUT_SCOPE_EXIT } //!< The layout of enter scope message.
, { {"log" , "*" , "layout" , "message" }, DEFAULT_LAYOUT_LOG_MESSAGE } //!< The layout of log message.
Expand Down
21 changes: 11 additions & 10 deletions framework/areg/appbase/private/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ void Application::initApplication( bool startTracing /*= true */
, bool startRouting /*= true */
, bool startTimer /*= true */
, bool startWatchdog /*= true */
, const char * configFile /*= NEApplication::DEFAULT_CONFIG_FILE */)
, const char * configFile /*= NEApplication::DEFAULT_CONFIG_FILE */
, IEConfigurationListener* listener /*= nullptr*/)
{
OUTPUT_DBG("Going to initialize application");
Application::_setAppState(Application::eAppState::AppStateInitializing);
Expand All @@ -61,7 +62,7 @@ void Application::initApplication( bool startTracing /*= true */
Application::setWorkingDirectory( nullptr );
startTimer = startTimer == false ? startServicing : startTimer;

Application::loadConfiguration(NEString::isEmpty(configFile) ? NEApplication::DEFAULT_CONFIG_FILE.data() : configFile);
Application::loadConfiguration(NEString::isEmpty(configFile) ? NEApplication::DEFAULT_CONFIG_FILE.data() : configFile, listener);

if (startTracing)
{
Expand Down Expand Up @@ -405,38 +406,38 @@ ConfigManager& Application::getConfigManager(void)
return Application::getInstance().mConfigManager;
}

bool Application::loadConfiguration(const char* fileName)
bool Application::loadConfiguration(const char* fileName /*= nullptr*/, IEConfigurationListener * listener /*= nullptr*/)
{
Application& theApp = Application::getInstance();
bool result{ true };
if (theApp.mConfigManager.readConfig(fileName == nullptr ? NEApplication::DEFAULT_CONFIG_FILE : fileName) == false)
if (theApp.mConfigManager.readConfig(fileName == nullptr ? NEApplication::DEFAULT_CONFIG_FILE : fileName, listener) == false)
{
result = false;
Application::setupDefaultConfiguration();
Application::setupDefaultConfiguration(listener);
}

return result;
}

bool Application::saveConfiguration(const char* fileName)
bool Application::saveConfiguration(const char* fileName /*= nullptr*/, IEConfigurationListener * listener /*= nullptr*/)
{
Application& theApp = Application::getInstance();
return theApp.mConfigManager.saveConfig(fileName);
}

void Application::setupDefaultConfiguration(void)
void Application::setupDefaultConfiguration(IEConfigurationListener * listener /*= nullptr*/)
{
Application& theApp = Application::getInstance();
const String& module = Process::getInstance().getAppName();

const uint32_t countReadonly{ MACRO_ARRAYLEN(NEApplication::DefaultReadonlyProperties) };
ConfigManager::ListProperties defReadonly(countReadonly);
NEPersistence::ListProperties defReadonly(countReadonly);
for (const auto & entry : NEApplication::DefaultReadonlyProperties)
{
defReadonly.add(Property(entry.configKey.section, entry.configKey.module, entry.configKey.property, entry.configKey.position, entry.configValue, String::EmptyString));
}

ConfigManager::ListProperties defWritable;
NEPersistence::ListProperties defWritable;
for (const auto& entry : NEApplication::DefaultLogScopesConfig)
{
if (module == entry.configKey.module)
Expand All @@ -445,7 +446,7 @@ void Application::setupDefaultConfiguration(void)
}
}

theApp.mConfigManager.setConfiguration(defReadonly, defWritable);
theApp.mConfigManager.setConfiguration(defReadonly, defWritable, listener);
}

bool Application::isConfigured(void)
Expand Down
17 changes: 15 additions & 2 deletions framework/areg/base/SharedBuffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,35 @@ class AREG_API SharedBuffer : public BufferStreamBase // This is data streaming
explicit SharedBuffer(unsigned int blockSize = NEMemory::BLOCK_SIZE);

/**
* \brief Constructor to reserve space for byte buffer object
* \brief Reserves the space in the byte buffer to write data and sets block size.
* \param reserveSize Size in bytes to reserve
* \param blockSize The size of minimum block size to increase on resize.
* It is aligned to NEMemory::BLOCK_SIZE (minimum size)
**/
SharedBuffer( unsigned int reserveSize, unsigned int blockSize );

/**
* \brief Initialization constructor, writes given data into byte buffer
* \brief Reserves space and writes given data into byte buffer.
* \param buffer The data to initialize byte buffer
* \param size The length in bytes of data
* \param blockSize The size of minimum block size to increase on resize.
* It is aligned to NEMemory::BLOCK_SIZE (minimum size)
**/
SharedBuffer( const unsigned char * buffer, unsigned int size, unsigned int blockSize = NEMemory::BLOCK_SIZE );

/**
* \brief Reserves requested space in bytes and writes given data into byte buffer.
* The reserved space should at least the size of the buffer to write.
* If the requested space to reserve is smaller than the size of the buffer,
* it will be increased to the size of the buffer.
* \brief reserveSize Number of bytes to reserve in the shared buffer.
* \param buffer The data to initialize byte buffer
* \param size The length in bytes of data
* \param blockSize The size of minimum block size to increase on resize.
* It is aligned to NEMemory::BLOCK_SIZE (minimum size)
**/
SharedBuffer(unsigned int reserveSize, const unsigned char* buffer, unsigned int size, unsigned int blockSize = NEMemory::BLOCK_SIZE);

/**
* \brief Initialization constructor, writes given null-terminated string into byte buffer.
* It will write including EOS character ('\0').
Expand Down
Loading

0 comments on commit 531c168

Please sign in to comment.