Enable logging for functions

Set the logging level for an instance of a StackState function

This page describes StackState version 4.1.

The StackState 4.1 version range is End of Life (EOL) and no longer supported. We encourage customers still running the 4.1 version range to upgrade to a more recent release.

Go to the documentation for the latest StackState release.

Overview

For debugging purposes, it may be helpful to enable logging for a StackState function. You can add logging statements to functions and then use the StackState CLI to set the logging level for individual instances of a check function, event handler function, propagation function or view state configuration function. Log messages will be added to the StackState log file stackstate.log. It is not currently possible to enable logging for other function types.

Set the logging level for a function instance

To enable logging for an instance of a function, use its ID to set a logging level in the StackState CLI. Note that the function itself will have an ID and each instance of the function relating to a component or view in StackState will have a separate ID.

The logging level should be set using the ID for an instance of a function, not the ID of the function itself.

  1. Find the ID for the instance of the function that you want to enable logging for:

  2. Use the StackState CLI to set the logging level for the ID, for example:

    sts serverlog setlevel <id> DEBUG
  3. Monitor the stackstate.log using the function instance ID.

    tail -f stackstate.log | grep <id>

Add logging statements to a function

Logging statements can be added to StackState functions and monitored in the stackstate.log file. This is useful for debug purposes.

  1. Add a log statement in the function's code. For example:

    • log.info("message")

    • log.info(variable.toString())

  2. Set a logging level to enable logging for an instance of the function.

Find the ID for a function instance

Retrieve the ID for a specific instance of a function:

StackState CLI

Event handler IDs

The ID for an event handler can be found using the StackState CLI. This is the ID for an instance of an event handler function.

  • To list all event handlers, run the StackState CLI command below.

  • Use the id from the command output to enable logging for a specific event handler.

sts graph list EventHandler

View health state configuration IDs

The ID for a view health state configuration can be found using the StackState CLI. This is the ID for a view's instance of a view health state configuration function.

  • Run the two StackState CLI commands below:

    1. To return the IDs of all StackState views.

    2. To retrieve the JSON for a specific view ID.

  • Use the viewHealthStateConfiguration ID from the retrieved view JSON to enable logging for this instance of the view health state configuration function. In the example below, this would be 39710412772194.

# get IDs of all views
sts graph list QueryView

# get the ID of the specified view's "viewHealthStateConfiguration"
sts graph show-node <VIEW_ID>

StackState UI

Check and propagation IDs

The ID for a check or propagation on a specific component can be found in in the StackState UI. These are the IDs for the component's instance of a check function or propagation function.

  1. Click on a component to open the component details on the right of the screen.

  2. Click on ... and select Show JSON.

  3. Find the section for "checks" or "propagation".

  4. Find the check or propagation that you want to enable logging for and copy the value from the field id.

  • Use the ID to enable logging for the component's check or propagation functions.

See also

Last updated