Class Log4j2LevelAdjuster

java.lang.Object
org.springframework.integration.test.rule.Log4j2LevelAdjuster
All Implemented Interfaces:
org.junit.rules.MethodRule

public final class Log4j2LevelAdjuster extends Object implements org.junit.rules.MethodRule
A JUnit method Rule that changes the Log4J 2 logger level for a set of classes or packages while a test method is running. Useful for performance or scalability tests where we don't want to generate a large log in a tight inner loop, or enabling debug logging for a test case.
Since:
5.0.1
Author:
Artem Bilan, Gary Russell
  • Method Summary

    Modifier and Type
    Method
    Description
    org.junit.runners.model.Statement
    apply(org.junit.runners.model.Statement base, org.junit.runners.model.FrameworkMethod method, Object target)
     
    categories(boolean merge, String... categories)
    Specify the categories for logging level adjusting configured before.
    categories(String... categoriesToAdjust)
    Specify the categories for logging level adjusting configured before.
    classes(boolean merge, Class<?>... classesToAdjust)
    Specify the classes for logging level adjusting configured before.
    classes(Class<?>... clazzes)
    Specify the classes for logging level adjusting configured before.
    The factory to produce Log4j2LevelAdjuster instances for Level.DEBUG logging with the org.springframework.integration as default category.
    forLevel(org.apache.logging.log4j.Level level)
    The factory to produce Log4j2LevelAdjuster instances for arbitrary logging Level with the org.springframework.integration as default category.
    The factory to produce Log4j2LevelAdjuster instances for Level.INFO logging with the org.springframework.integration as default category.
    The factory to produce Log4j2LevelAdjuster instances for Level.TRACE logging with the org.springframework.integration as default category.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • apply

      public org.junit.runners.model.Statement apply(org.junit.runners.model.Statement base, org.junit.runners.model.FrameworkMethod method, Object target)
      Specified by:
      apply in interface org.junit.rules.MethodRule
    • classes

      public Log4j2LevelAdjuster classes(Class<?>... clazzes)
      Specify the classes for logging level adjusting configured before. A new copy Log4j2LevelAdjuster instance is produced by this method. The provided classes parameter overrides existing value in the classes.
      Parameters:
      clazzes - the classes to use for logging level adjusting
      Returns:
      a Log4j2LevelAdjuster copy with the provided classes
    • classes

      public Log4j2LevelAdjuster classes(boolean merge, Class<?>... classesToAdjust)
      Specify the classes for logging level adjusting configured before. A new copy Log4j2LevelAdjuster instance is produced by this method. The provided classes parameter can be merged with existing value in the classes.
      Parameters:
      merge - to merge or not with previously configured classes
      classesToAdjust - the classes to use for logging level adjusting
      Returns:
      a Log4j2LevelAdjuster copy with the provided classes
      Since:
      5.0.2
    • categories

      public Log4j2LevelAdjuster categories(String... categoriesToAdjust)
      Specify the categories for logging level adjusting configured before. A new copy Log4j2LevelAdjuster instance is produced by this method. The provided categories parameter overrides existing value in the categories.
      Parameters:
      categoriesToAdjust - the categories to use for logging level adjusting
      Returns:
      a Log4j2LevelAdjuster copy with the provided categories
    • categories

      public Log4j2LevelAdjuster categories(boolean merge, String... categories)
      Specify the categories for logging level adjusting configured before. A new copy Log4j2LevelAdjuster instance is produced by this method. The provided categories parameter can be merged with existing value in the categories.
      Parameters:
      merge - to merge or not with previously configured categories
      categories - the categories to use for logging level adjusting
      Returns:
      a Log4j2LevelAdjuster copy with the provided categories
      Since:
      5.0.2
    • trace

      public static Log4j2LevelAdjuster trace()
      The factory to produce Log4j2LevelAdjuster instances for Level.TRACE logging with the org.springframework.integration as default category.
      Returns:
      the Log4j2LevelAdjuster instance
    • debug

      public static Log4j2LevelAdjuster debug()
      The factory to produce Log4j2LevelAdjuster instances for Level.DEBUG logging with the org.springframework.integration as default category.
      Returns:
      the Log4j2LevelAdjuster instance
    • info

      public static Log4j2LevelAdjuster info()
      The factory to produce Log4j2LevelAdjuster instances for Level.INFO logging with the org.springframework.integration as default category.
      Returns:
      the Log4j2LevelAdjuster instance
    • forLevel

      public static Log4j2LevelAdjuster forLevel(org.apache.logging.log4j.Level level)
      The factory to produce Log4j2LevelAdjuster instances for arbitrary logging Level with the org.springframework.integration as default category.
      Parameters:
      level - the Level to use for logging
      Returns:
      the Log4j2LevelAdjuster instance