Class DefaultTargetLengthAbbreviator

java.lang.Object
net.logstash.logback.abbreviator.DefaultTargetLengthAbbreviator
All Implemented Interfaces:
Abbreviator, LifeCycle

public class DefaultTargetLengthAbbreviator extends Object implements Abbreviator, LifeCycle
Abbreviates class names in a way similar to the Logback layout feature (see https://logback.qos.ch/manual/layouts.html#logger).

The algorithm will shorten the full class name and attempt to reduce its size to a maximum of length characters. It does so by reducing the package elements to their first letter and gradually expand them starting from the right until the maximum size is reached. Setting the length to zero constitutes an exception and returns the "simple" class name without package.

The next table provides examples of the abbreviation algorithm in action.

 LENGTH   CLASSNAME                 SHORTENED
 -------------------------------------------------------------
 0        org.company.package.Bar   Bar
 5        org.company.package.Bar   o.c.p.Bar
 15       org.company.package.Bar   o.c.package.Bar
 21       org.company.package.Bar   o.company.package.Bar
 24       org.company.package.Bar   org.company.package.Bar
 
Author:
brenuart
  • Constructor Details

    • DefaultTargetLengthAbbreviator

      public DefaultTargetLengthAbbreviator()
  • Method Details

    • isStarted

      public boolean isStarted()
      Specified by:
      isStarted in interface LifeCycle
    • start

      public void start()
      Specified by:
      start in interface LifeCycle
    • stop

      public void stop()
      Specified by:
      stop in interface LifeCycle
    • abbreviate

      public String abbreviate(String in)
      Specified by:
      abbreviate in interface Abbreviator
    • setTargetLength

      public void setTargetLength(int targetLength)
    • getTargetLength

      public int getTargetLength()
    • assertStarted

      protected void assertStarted()