Class DeprecationLogger

java.lang.Object
org.elasticsearch.common.logging.DeprecationLogger

public class DeprecationLogger
extends java.lang.Object
A logger that logs deprecation notices. Logger should be initialized with a parent logger which name will be used for deprecation logger. For instance DeprecationLogger.getLogger("org.elasticsearch.test.SomeClass") will result in a deprecation logger with name org.elasticsearch.deprecation.test.SomeClass. This allows to use a deprecation logger defined in log4j2.properties.

Logs are emitted at the custom DEPRECATION level, and routed wherever they need to go using log4j. For example, to disk using a rolling file appender, or added as a response header using HeaderWarningAppender.

Deprecation messages include a key, which is used for rate-limiting purposes. The log4j configuration uses RateLimitingFilter to prevent the same message being logged repeatedly in a short span of time. This key is combined with the X-Opaque-Id request header value, if supplied, which allows for per-client message limiting.

  • Field Summary

    Fields
    Modifier and Type Field Description
    static org.apache.logging.log4j.Level DEPRECATION
    Deprecation messages are logged at this level.
  • Method Summary

    Modifier and Type Method Description
    DeprecationLogger deprecate​(DeprecationCategory category, java.lang.String key, java.lang.String msg, java.lang.Object... params)
    Logs a message at the DEPRECATION level.
    static DeprecationLogger getLogger​(java.lang.Class<?> aClass)
    Creates a new deprecation logger for the supplied class.
    static DeprecationLogger getLogger​(java.lang.String name)
    Creates a new deprecation logger based on the parent logger.

    Methods inherited from class java.lang.Object

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

    • DEPRECATION

      public static org.apache.logging.log4j.Level DEPRECATION
      Deprecation messages are logged at this level.
  • Method Details

    • getLogger

      public static DeprecationLogger getLogger​(java.lang.Class<?> aClass)
      Creates a new deprecation logger for the supplied class. Internally, it delegates to getLogger(String), passing the full class name.
    • getLogger

      public static DeprecationLogger getLogger​(java.lang.String name)
      Creates a new deprecation logger based on the parent logger. Automatically prefixes the logger name with "deprecation", if it starts with "org.elasticsearch.", it replaces "org.elasticsearch" with "org.elasticsearch.deprecation" to maintain the "org.elasticsearch" namespace.
    • deprecate

      public DeprecationLogger deprecate​(DeprecationCategory category, java.lang.String key, java.lang.String msg, java.lang.Object... params)
      Logs a message at the DEPRECATION level. The message is also sent to the header warning logger, so that it can be returned to the client.