Class ConfigureLoggingSetupTask

  • All Implemented Interfaces:
    ServerSetupTask

    public class ConfigureLoggingSetupTask
    extends Object
    implements ServerSetupTask
    A setup task for configuring loggers for tests.

    You can define the log levels and logger names in two ways. The first is to pass a map of known logger levels with associated logger names to the constructor. The other is via a system property.

    To set the levels and logger names via a system property, use a key of wildfly.logging.level.${level} where level is one of the following:

    1. all
    2. trace
    3. debug
    4. info
    5. warn
    6. error
    7. off
    The value for each property is a comma delimited set of logger names.

    Example:

           -Dwildfly.logging.level.debug=org.wildfly.security,org.jboss.resteasy
       

    When using the constructor, the map should consist of a known log level as the key and loggers to be associated with that level as the value of the map. Example:

         
              public class WildFlyLoggingSetupTask extends ConfigurationLoggingSetupTask {
                  public WildFlyLoggingSetupTask() {
                      super(Map.of("DEBUG", Set.of("org.wildfly.core", "org.wildfly"}));
                  }
              
         )
     
    Note that when using the map constructor, you can still use the system property and the maps will be merged.

    Author:
    James R. Perkins
    • Constructor Detail

      • ConfigureLoggingSetupTask

        public ConfigureLoggingSetupTask()
        Creates a new setup task which configures the console-handler=CONSOLE handler to allow all log levels. Then configures, either by modifying or adding, the loggers represented by the values from the system properties.
      • ConfigureLoggingSetupTask

        public ConfigureLoggingSetupTask​(String handlerType,
                                         String handlerName)
        Creates a new setup task which configures the handler to allow all log levels. Then configures, either by modifying or adding, the loggers represented by system properties.
        Parameters:
        handlerType - the handler type which should be modified to ensure it allows all log levels, if null console-handler will be used
        handlerName - the name of the handler which should be modified to ensure it allows all log levels, if null console-handler will be used
      • ConfigureLoggingSetupTask

        public ConfigureLoggingSetupTask​(Map<String,​Set<String>> logLevels)
        Creates a new setup task which configures the console-handler=CONSOLE handler to allow all log levels. Then configures, either by modifying or adding, the loggers represented by the values of the map passed in. The key of the map is the level desired for each logger.

        The map consists of levels as the key and a set of logger names as the value for each level.

        Parameters:
        logLevels - the map of levels and loggers
      • ConfigureLoggingSetupTask

        public ConfigureLoggingSetupTask​(String handlerType,
                                         String handlerName,
                                         Map<String,​Set<String>> logLevels)
        Creates a new setup task which configures the handler to allow all log levels. Then configures, either by modifying or adding, the loggers represented by the values of the map passed in. The key of the map is the level desired for each logger.

        If the handlerType is null the value will be console-handler. If the handlerName is null the value used will be CONSOLE.

        The map consists of levels as the key and a set of logger names as the value for each level.

        Parameters:
        handlerType - the handler type which should be modified to ensure it allows all log levels, if null console-handler will be used
        handlerName - the name of the handler which should be modified to ensure it allows all log levels, if null console-handler will be used
        logLevels - the map of levels and loggers
    • Method Detail

      • setup

        public void setup​(ManagementClient client,
                          String containerId)
                   throws Exception
        Description copied from interface: ServerSetupTask
        Execute any necessary setup work that needs to happen before the first deployment to the given container.

        Note on exception handling: If an implementation of this method throws any exception, the implementation can assume the following:

        1. Any subsequent ServerSetupTasks associated with test class will not be executed.
        2. The deployment event that triggered the call to this method will be skipped.
        3. The tearDown method of the instance that threw the exception will not be invoked. Therefore, implementations that throw AssumptionViolatedException, or any other exception, should do so before altering any system state.
        4. The tearDown method for any previously executed ServerSetupTasks associated with test class will be invoked.

        If any other exception is thrown, the ServerSetupTask.tearDown(ManagementClient, String) will be executed, including this implementations tearDown(), re-throwing the original exception. The original exception will have any other exceptions thrown in the tearDown() methods add as suppressed messages.

        Specified by:
        setup in interface ServerSetupTask
        Parameters:
        client - management client to use to interact with the container
        containerId - id of the container to which the deployment will be deployed
        Throws:
        Exception - if a failure occurs
      • tearDown

        public void tearDown​(ManagementClient managementClient,
                             String containerId)
                      throws Exception
        Description copied from interface: ServerSetupTask
        Execute any tear down work that needs to happen after the last deployment associated with the given container has been undeployed.
        Specified by:
        tearDown in interface ServerSetupTask
        Parameters:
        managementClient - management client to use to interact with the container
        containerId - id of the container to which the deployment will be deployed
        Throws:
        Exception - if a failure occurs