Skip to content

Commit

Permalink
Logging: mode state added to handle activate, deactivate and hibernat…
Browse files Browse the repository at this point in the history
…e state
  • Loading branch information
HaseenaSainul committed Jul 1, 2024
1 parent 535a37d commit a4c3a90
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 52 deletions.
6 changes: 3 additions & 3 deletions Source/Thunder/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -1074,7 +1074,7 @@ POP_WARNING()
_accessor.PortNumber(_portNumber);
hostaddress = _accessor.HostAddress();
_configLock.Unlock();
SYSLOG(Logging::Startup, ("Invalid config information could not resolve to a proper IP"));
SYSLOG(Logging::Activate, ("Invalid config information could not resolve to a proper IP"));
} else {
_accessor.PortNumber(_portNumber);
hostaddress= _accessor.HostAddress();
Expand All @@ -1089,8 +1089,8 @@ POP_WARNING()
}


SYSLOG(Logging::Startup, (_T("Accessor: %s"), _URL.c_str()));
SYSLOG(Logging::Startup, (_T("Interface IP: %s"), hostaddress.c_str()));
SYSLOG(Logging::Activate, (_T("Accessor: %s"), _URL.c_str()));
SYSLOG(Logging::Activate, (_T("Interface IP: %s"), hostaddress.c_str()));

}

Expand Down
4 changes: 2 additions & 2 deletions Source/Thunder/Controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ namespace Plugin {
Core::NodeId node (config.Probe.Node.Value().c_str());

if (node.IsValid() == false) {
SYSLOG(Logging::Startup, (_T("Probing requested but invalid IP address [%s]"), config.Probe.Node.Value().c_str()));
SYSLOG(Logging::Activate, (_T("Probing requested but invalid IP address [%s]"), config.Probe.Node.Value().c_str()));
}
else {
_probe = new Probe(node, _service, config.Probe.TTL.Value(), service->Model());
Expand All @@ -98,7 +98,7 @@ namespace Plugin {

if (current >= PluginHost::ISubSystem::END_LIST) {
Core::EnumerateType<PluginHost::ISubSystem::subsystem> name(current);
SYSLOG(Logging::Startup, (Core::Format(_T("Subsystem [%s] can not be used as a control value in controller config!!!"), name.Data())));
SYSLOG(Logging::Activate, (Core::Format(_T("Subsystem [%s] can not be used as a control value in controller config!!!"), name.Data())));
}
else {
_externalSubsystems.emplace_back(current);
Expand Down
24 changes: 12 additions & 12 deletions Source/Thunder/PluginServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,14 +365,14 @@ namespace PluginHost {
const string className(PluginHost::Service::Configuration().ClassName.Value());

if (_handler == nullptr) {
SYSLOG(Logging::Startup, (_T("Loading of plugin [%s]:[%s], failed. Error [%s]"), className.c_str(), callSign.c_str(), ErrorMessage().c_str()));
SYSLOG(Logging::Activate, (_T("Loading of plugin [%s]:[%s], failed. Error [%s]"), className.c_str(), callSign.c_str(), ErrorMessage().c_str()));
result = Core::ERROR_UNAVAILABLE;

Unlock();

// See if the preconditions have been met..
} else if (_precondition.IsMet() == false) {
SYSLOG(Logging::Startup, (_T("Activation of plugin [%s]:[%s], postponed, preconditions have not been met, yet."), className.c_str(), callSign.c_str()));
SYSLOG(Logging::Activate, (_T("Activation of plugin [%s]:[%s], postponed, preconditions have not been met, yet."), className.c_str(), callSign.c_str()));
result = Core::ERROR_PENDING_CONDITIONS;
_reason = why;
State(PRECONDITION);
Expand Down Expand Up @@ -422,7 +422,7 @@ namespace PluginHost {
if (HasError() == true) {
result = Core::ERROR_GENERAL;

SYSLOG(Logging::Startup, (_T("Activation of plugin [%s]:[%s], failed. Error [%s]"), className.c_str(), callSign.c_str(), ErrorMessage().c_str()));
SYSLOG(Logging::Activate, (_T("Activation of plugin [%s]:[%s], failed. Error [%s]"), className.c_str(), callSign.c_str(), ErrorMessage().c_str()));

_reason = reason::INITIALIZATION_FAILED;
_administrator.Deinitialized(callSign, this);
Expand Down Expand Up @@ -459,7 +459,7 @@ namespace PluginHost {
}
}

SYSLOG(Logging::Startup, (_T("Activated plugin [%s]:[%s]"), className.c_str(), callSign.c_str()));
SYSLOG(Logging::Activate, (_T("Activated plugin [%s]:[%s]"), className.c_str(), callSign.c_str()));
Lock();
State(ACTIVATED);
_administrator.Activated(callSign, this);
Expand Down Expand Up @@ -605,7 +605,7 @@ namespace PluginHost {
}

if (currentState != IShell::state::ACTIVATION) {
SYSLOG(Logging::Shutdown, (_T("Deactivated plugin [%s]:[%s]"), className.c_str(), callSign.c_str()));
SYSLOG(Logging::Deactivate, (_T("Deactivated plugin [%s]:[%s]"), className.c_str(), callSign.c_str()));

#ifdef THUNDER_RESTFULL_API
Notify(EMPTY_STRING, string(_T("{\"state\":\"deactivated\",\"reason\":\"")) + textReason.Data() + _T("\"}"));
Expand Down Expand Up @@ -689,7 +689,7 @@ namespace PluginHost {

_reason = why;

SYSLOG(Logging::Shutdown, (_T("Unavailable plugin [%s]:[%s]"), className.c_str(), callSign.c_str()));
SYSLOG(Logging::Deactivate, (_T("Unavailable plugin [%s]:[%s]"), className.c_str(), callSign.c_str()));

TRACE(Activity, (Core::Format(_T("Unavailable plugin [%s]:[%s]"), className.c_str(), callSign.c_str())));

Expand Down Expand Up @@ -741,7 +741,7 @@ namespace PluginHost {
result = HibernateProcess(timeout, parentPID, _administrator.Configuration().HibernateLocator().c_str(), _T(""), &_hibernateStorage);
Lock();
if (State() != IShell::HIBERNATED) {
SYSLOG(Logging::Startup, (_T("Hibernation aborted of plugin [%s] process [%u]"), Callsign().c_str(), parentPID));
SYSLOG(Logging::Hibernate, (_T("Hibernation aborted of plugin [%s] process [%u]"), Callsign().c_str(), parentPID));
result = Core::ERROR_ABORTED;
}
Unlock();
Expand All @@ -763,16 +763,16 @@ namespace PluginHost {
#endif
if (result == Core::ERROR_NONE) {
if (State() == IShell::state::HIBERNATED) {
SYSLOG(Logging::Startup, ("Hibernated plugin [%s]:[%s]", ClassName().c_str(), Callsign().c_str()));
SYSLOG(Logging::Hibernate, ("Hibernated plugin [%s]:[%s]", ClassName().c_str(), Callsign().c_str()));
} else {
// wakeup occured right after hibernation finished
SYSLOG(Logging::Startup, ("Hibernation aborted of plugin [%s]:[%s]", ClassName().c_str(), Callsign().c_str()));
SYSLOG(Logging::Hibernate, ("Hibernation aborted of plugin [%s]:[%s]", ClassName().c_str(), Callsign().c_str()));
result = Core::ERROR_ABORTED;
}
}
else if (State() == IShell::state::HIBERNATED) {
State(IShell::ACTIVATED);
SYSLOG(Logging::Startup, (_T("Hibernation error [%d] of [%s]:[%s]"), result, ClassName().c_str(), Callsign().c_str()));
SYSLOG(Logging::Hibernate, (_T("Hibernation error [%d] of [%s]:[%s]"), result, ClassName().c_str(), Callsign().c_str()));
}
}
}
Expand Down Expand Up @@ -813,7 +813,7 @@ namespace PluginHost {
#endif
if (result == Core::ERROR_NONE) {
State(ACTIVATED);
SYSLOG(Logging::Startup, (_T("Activated plugin from hibernation [%s]:[%s]"), ClassName().c_str(), Callsign().c_str()));
SYSLOG(Logging::Activate, (_T("Activated plugin from hibernation [%s]:[%s]"), ClassName().c_str(), Callsign().c_str()));
}
local->Release();
}
Expand All @@ -839,7 +839,7 @@ namespace PluginHost {
TRACE(Activity, (_T("Hibernation of plugin [%s] child process [%u]"), Callsign().c_str(), *iter));
Lock();
if (State() != IShell::HIBERNATED) {
SYSLOG(Logging::Startup, (_T("Hibernation aborted of plugin [%s] child process [%u]"), Callsign().c_str(), *iter));
SYSLOG(Logging::Hibernate, (_T("Hibernation aborted of plugin [%s] child process [%u]"), Callsign().c_str(), *iter));
result = Core::ERROR_ABORTED;
Unlock();
break;
Expand Down
66 changes: 33 additions & 33 deletions Source/Thunder/SystemInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -342,11 +342,11 @@ namespace PluginHost {

switch (type) {
case PLATFORM: {
SYSLOG(Logging::Startup, (_T("EVENT: Platform")));
SYSLOG(Logging::Activate, (_T("EVENT: Platform")));
break;
}
case NETWORK: {
SYSLOG(Logging::Startup, (_T("EVENT: Network")));
SYSLOG(Logging::Activate, (_T("EVENT: Network")));
break;
}
case IDENTIFIER: {
Expand Down Expand Up @@ -385,10 +385,10 @@ namespace PluginHost {
_adminLock.Unlock();
}

SYSLOG(Logging::Startup, (_T("EVENT: Identifier: %s"), _identifier->Identifier().c_str()));
SYSLOG(Logging::Startup, (_T("EVENT: Architecture: %s"), _identifier->Architecture().c_str()));
SYSLOG(Logging::Startup, (_T("EVENT: Chipset: %s"), _identifier->Chipset().c_str()));
SYSLOG(Logging::Startup, (_T("EVENT: FirmwareVersion: %s"), _identifier->FirmwareVersion().c_str()));
SYSLOG(Logging::Activate, (_T("EVENT: Identifier: %s"), _identifier->Identifier().c_str()));
SYSLOG(Logging::Activate, (_T("EVENT: Architecture: %s"), _identifier->Architecture().c_str()));
SYSLOG(Logging::Activate, (_T("EVENT: Chipset: %s"), _identifier->Chipset().c_str()));
SYSLOG(Logging::Activate, (_T("EVENT: FirmwareVersion: %s"), _identifier->FirmwareVersion().c_str()));
break;
}
case INTERNET: {
Expand Down Expand Up @@ -422,7 +422,7 @@ namespace PluginHost {
_adminLock.Unlock();
}

SYSLOG(Logging::Startup, (_T("EVENT: Internet [%s]"), _internet->PublicIPAddress().c_str()));
SYSLOG(Logging::Activate, (_T("EVENT: Internet [%s]"), _internet->PublicIPAddress().c_str()));
break;
}
case LOCATION: {
Expand All @@ -444,7 +444,7 @@ namespace PluginHost {
_location = location;
_adminLock.Unlock();

SYSLOG(Logging::Startup, (_T("EVENT: TimeZone: %s, Country: %s, Region: %s, City: %s"), _location->TimeZone().c_str(), _location->Country().c_str(), _location->Region().c_str(), _location->City().c_str()));
SYSLOG(Logging::Activate, (_T("EVENT: TimeZone: %s, Country: %s, Region: %s, City: %s"), _location->TimeZone().c_str(), _location->Country().c_str(), _location->Region().c_str(), _location->City().c_str()));

break;
}
Expand Down Expand Up @@ -479,7 +479,7 @@ namespace PluginHost {
_adminLock.Unlock();
}

SYSLOG(Logging::Startup, (_T("EVENT: Time: %s"), Core::Time(_time->TimeSync()).ToRFC1123(false).c_str()));
SYSLOG(Logging::Activate, (_T("EVENT: Time: %s"), Core::Time(_time->TimeSync()).ToRFC1123(false).c_str()));
break;
}
case PROVISIONING: {
Expand Down Expand Up @@ -511,42 +511,42 @@ namespace PluginHost {
}

/* No information to set yet */
SYSLOG(Logging::Startup, (_T("EVENT: Provisioning")));
SYSLOG(Logging::Activate, (_T("EVENT: Provisioning")));
break;
}
case DECRYPTION: {
/* No information to set yet */
SYSLOG(Logging::Startup, (_T("EVENT: Decryption")));
SYSLOG(Logging::Activate, (_T("EVENT: Decryption")));
break;
}
case GRAPHICS: {
/* No information to set yet */
SYSLOG(Logging::Startup, (_T("EVENT: Graphics")));
SYSLOG(Logging::Activate, (_T("EVENT: Graphics")));
break;
}
case WEBSOURCE: {
/* No information to set yet */
SYSLOG(Logging::Startup, (_T("EVENT: WebSource")));
SYSLOG(Logging::Activate, (_T("EVENT: WebSource")));
break;
}
case STREAMING: {
/* No information to set yet */
SYSLOG(Logging::Startup, (_T("EVENT: Streaming")));
SYSLOG(Logging::Activate, (_T("EVENT: Streaming")));
break;
}
case BLUETOOTH: {
/* No information to set yet */
SYSLOG(Logging::Startup, (_T("EVENT: Bluetooth")));
SYSLOG(Logging::Activate, (_T("EVENT: Bluetooth")));
break;
}
case CRYPTOGRAPHY: {
/* No information to set yet */
SYSLOG(Logging::Startup, (_T("EVENT: Cryptography")));
SYSLOG(Logging::Activate, (_T("EVENT: Cryptography")));
break;
}
case INSTALLATION: {
/* No information to set yet */
SYSLOG(Logging::Startup, (_T("EVENT: Installation")));
SYSLOG(Logging::Activate, (_T("EVENT: Installation")));
break;
}
case SECURITY: {
Expand Down Expand Up @@ -580,7 +580,7 @@ namespace PluginHost {
_adminLock.Unlock();
}

SYSLOG(Logging::Startup, (_T("EVENT: Security")));
SYSLOG(Logging::Activate, (_T("EVENT: Security")));
break;
}
default: {
Expand Down Expand Up @@ -617,63 +617,63 @@ namespace PluginHost {

switch (type) {
case PLATFORM: {
SYSLOG(Logging::Shutdown, (_T("EVENT: Platform")));
SYSLOG(Logging::Deactivate, (_T("EVENT: Platform")));
break;
}
case NETWORK: {
SYSLOG(Logging::Shutdown, (_T("EVENT: Network")));
SYSLOG(Logging::Deactivate, (_T("EVENT: Network")));
break;
}
case IDENTIFIER: {
SYSLOG(Logging::Shutdown, (_T("EVENT: Identifier")));
SYSLOG(Logging::Deactivate, (_T("EVENT: Identifier")));
break;
}
case INTERNET: {
SYSLOG(Logging::Shutdown, (_T("EVENT: Internet")));
SYSLOG(Logging::Deactivate, (_T("EVENT: Internet")));
break;
}
case TIME: {
SYSLOG(Logging::Shutdown, (_T("EVENT: Time")));
SYSLOG(Logging::Deactivate, (_T("EVENT: Time")));
break;
}
case LOCATION: {
SYSLOG(Logging::Shutdown, (_T("EVENT: Location")));
SYSLOG(Logging::Deactivate, (_T("EVENT: Location")));
break;
}
case PROVISIONING: {
SYSLOG(Logging::Shutdown, (_T("EVENT: Provisioning")));
SYSLOG(Logging::Deactivate, (_T("EVENT: Provisioning")));
break;
}
case DECRYPTION: {
SYSLOG(Logging::Shutdown, (_T("EVENT: Decryption")));
SYSLOG(Logging::Deactivate, (_T("EVENT: Decryption")));
break;
}
case GRAPHICS: {
SYSLOG(Logging::Shutdown, (_T("EVENT: Graphics")));
SYSLOG(Logging::Deactivate, (_T("EVENT: Graphics")));
break;
}
case CRYPTOGRAPHY: {
SYSLOG(Logging::Shutdown, (_T("EVENT: Cryptography")));
SYSLOG(Logging::Deactivate, (_T("EVENT: Cryptography")));
break;
}
case INSTALLATION: {
SYSLOG(Logging::Shutdown, (_T("EVENT: Installation")));
SYSLOG(Logging::Deactivate, (_T("EVENT: Installation")));
break;
}
case BLUETOOTH: {
SYSLOG(Logging::Shutdown, (_T("EVENT: Bluetooth")));
SYSLOG(Logging::Deactivate, (_T("EVENT: Bluetooth")));
break;
}
case WEBSOURCE: {
SYSLOG(Logging::Shutdown, (_T("EVENT: WebSource")));
SYSLOG(Logging::Deactivate, (_T("EVENT: WebSource")));
break;
}
case STREAMING: {
SYSLOG(Logging::Shutdown, (_T("EVENT: Streaming")));
SYSLOG(Logging::Deactivate, (_T("EVENT: Streaming")));
break;
}
case SECURITY: {
SYSLOG(Logging::Shutdown, (_T("EVENT: Security")));
SYSLOG(Logging::Deactivate, (_T("EVENT: Security")));
break;
}
default: {
Expand Down
3 changes: 3 additions & 0 deletions Source/messaging/Logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ namespace Logging {
SYSLOG_ANNOUNCE(Crash);
SYSLOG_ANNOUNCE(Startup);
SYSLOG_ANNOUNCE(Shutdown);
SYSLOG_ANNOUNCE(Activate);
SYSLOG_ANNOUNCE(Deactivate);
SYSLOG_ANNOUNCE(Hibernate);
SYSLOG_ANNOUNCE(Fatal);
SYSLOG_ANNOUNCE(Error);
SYSLOG_ANNOUNCE(ParsingError);
Expand Down
3 changes: 3 additions & 0 deletions Source/messaging/LoggingCategories.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ namespace Logging {
// ...but logging controls have to be visible outside of the Messaging lib
DEFINE_LOGGING_CATEGORY(Startup)
DEFINE_LOGGING_CATEGORY(Shutdown)
DEFINE_LOGGING_CATEGORY(Hibernate)
DEFINE_LOGGING_CATEGORY(Activate)
DEFINE_LOGGING_CATEGORY(Deactivate)
DEFINE_LOGGING_CATEGORY(Notification)
DEFINE_LOGGING_CATEGORY(Error)
DEFINE_LOGGING_CATEGORY(ParsingError)
Expand Down
2 changes: 1 addition & 1 deletion Tests/unit/core/test_message_unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,4 +581,4 @@ namespace Core {

} // Core
} // Tests
} // Thunder
} // Thunder
5 changes: 4 additions & 1 deletion docs/plugin/messaging.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ private:
Logging, on the other hand, is the process of recording events that occur during the execution of an application. These events could be error messages, warnings, or informational messages that provide details about the application’s behavior. Logging is typically used for debugging and troubleshooting purposes. The primary goal of logging is to provide a historical record of events that can be used to analyze and diagnose problems. This means that in theory, we want to save the logs for later use.

```c++
SYSLOG(Logging::Startup, (_T("Failure in setting Key:Value:[%s]:[%s]\n"), index.Current().Key.Value().c_str(), index.Current().Value.Value().c_str()));
SYSLOG(Logging::Activate, (_T("Failure in setting Key:Value:[%s]:[%s]\n"), index.Current().Key.Value().c_str(), index.Current().Value.Value().c_str()));
```
This relates to the main difference between the `TRACE` and `SYSLOG` macros in Thunder, which is that `SYSLOG` is present in any build, and `TRACE` is dropped in production, the same way as, for example, an `ASSERT` macro. It concludes the main distinction between these two message categories in Thunder: tracing should be used when we want to indicate a vital information during the development, and we should use logging to record any important data that could be useful in the future.
Expand Down Expand Up @@ -531,6 +531,9 @@ Similarly, logging includes several categories, such as:
- Startup
- Shutdown
- Activate
- Deactivate
- Hibernate
- Notification
- Error
- ParsingError
Expand Down

0 comments on commit a4c3a90

Please sign in to comment.