Skip to content

Conversation

@anniegsmith
Copy link

In Gravity there are messages you can utilize to log what is happening in your code through spdlog.
These loggers are split into a GravityLogger and an ApplicationLogger. The GravityLogger is used for internal Gravity components, such as a GravityNode, or the Service Directory log messages. The ApplicationLogger is used for spdlog messages sent within an individual application.
These log messages can be recorded in their own file, the console, or (for the application logger) sent over the network where a subscriber can subscribe to the data product ID (gravity::constants::GRAVITY_LOGGER_DPID) and receive the log message.
Each log message has a level of severity it is associated with that increases as shown:

  • trace
  • debug
  • info
  • error
  • warn
  • critical
  • off

You can configure the minimum severity level you want to log in the .INI file initially.
These levels can also be configured dynamically, through a publisher using the data product ID (gravity::constants::SPD_LOG_CONFIG_DPID) and GravitySpdLogConfigPB. The componentID is the component that you want to change the logging levels of. If this is left blank, it will change the level of all components.

In this example:

  • Function: logAllAppLevels() logs an application message "App" at each logging level.
  • Function: sendConfigMessage(GravityNode &gn,std::string compID, GravitySpdLogConfigPB_LoggerType lt, GravitySpdLogConfigPB_LoggerLevel ll) uses a GravityNode to set the data and publish the data product.
  • All logging begins completely off (through the .INI file).
  • The GravityNode is initialized as "SimpleGravityComponentID" and gravity::constants::SPD_LOG_CONFIG_DPID is registered. An ApplicationLogSubscriber is set up to receive messages from the ApplicationNetworkLogger.
  • The console will notify that the GravityLogger level is being changed and the File and Console logger are both set to trace. Log messages should begin to appear on the console in the file SimpleGravityComponentID.log. No Application messages should appear on either.
  • The GravityLogger is then set to off and GravityLogger's logs end.
  • A message is sent attempting to change an ID that does not exist, this does nothing.
  • A message on the console notifies that the ApplicationLogger levels are changing. The console level is set to info, the file level is set to warn, and the network level is set to critical. These messages will appear in the file SimpleGravityComponentID.log and on the console according to the level set. The ApplicationLogSubscriber will receive the critical message "App", check to ensure the level and message are correct, and output to the console that the correct data has been received, before ending.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants