Top Description Inners Fields Constructors Methods
ch.qos.logback.classic.pattern

public abstract Class NamedConverter

extends ClassicConverter
Class Inheritance
Known Direct Subclasses
ch.qos.logback.classic.pattern.ClassOfCallerConverter, ch.qos.logback.classic.pattern.LoggerConverter
Imports
java.util.LinkedHashMap, .Map, ch.qos.logback.classic.spi.ILoggingEvent, ch.qos.logback.core.util.OptionHelper

In case abbreviation service is requested, NamedConverter will convert fully qualified class names to their abbreviated from. NamedConverter instances will store abbreviated names in an internal LRU cache. The cache will double in size if he cache miss rate is consistently above 30%. Assuming a high miss rate, the doubling until a maximum size of 2048 is attained. If at this point the cache miss rate is still too high, NamedConverter will revert to non cached behavior. The general assumption here is that a large majority of logger names are concentrated within a group of approximately 1000 logger names.
Author
Ceki Gulcu

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv class
private class

Field Summary

Modifier and TypeField and Description
private Abbreviator
private final NamedConverter.NameCache
private static final double
CACHE_MISSRATE_TRIGGER

When the cache miss rate is above 30%, the cache is deemed inefficient.

private volatile boolean
private volatile int
private static final String
private static final int
private static final double
private static final int
MAX_ALLOWED_REMOVAL_THRESHOLD

We don't let the cache map size to go over MAX_ALLOWED_REMOVAL_THRESHOLD elements

private static final int
MIN_SAMPLE_SIZE

We should have a sample size of minimal length before computing the cache miss rate.

private static final double
private volatile int

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public String
convert(ILoggingEvent event)

Implements abstract ch.qos.logback.core.pattern.Converter.convert.

The convert method is responsible for extracting data from the event and storing it for later use by the write method.
private void
public int
public double
protected abstract String

Returns:

name, must not be null.
getFullyQualifiedName
(final ILoggingEvent
The LoggingEvent to process, cannot not be null.
event
)

Gets fully qualified name from event.

public void
start()

Overrides ch.qos.logback.core.pattern.DynamicConverter.start.

Implements ch.qos.logback.core.spi.LifeCycle.start.

Components that depend on options passed during configuration can override this method in order to make appropriate use of those options.
private synchronized String
viaCache(String fqn)

This method is synchronized.

Field Detail

abbreviatorback to summary
private Abbreviator abbreviator
cacheback to summary
private final NamedConverter.NameCache cache
CACHE_MISSRATE_TRIGGERback to summary
private static final double CACHE_MISSRATE_TRIGGER

When the cache miss rate is above 30%, the cache is deemed inefficient.

cacheEnabledback to summary
private volatile boolean cacheEnabled
cacheMissesback to summary
private volatile int cacheMisses
DISABLE_CACHE_SYSTEM_PROPERTYback to summary
private static final String DISABLE_CACHE_SYSTEM_PROPERTY
INITIAL_CACHE_SIZEback to summary
private static final int INITIAL_CACHE_SIZE
LOAD_FACTORback to summary
private static final double LOAD_FACTOR
MAX_ALLOWED_REMOVAL_THRESHOLDback to summary
private static final int MAX_ALLOWED_REMOVAL_THRESHOLD

We don't let the cache map size to go over MAX_ALLOWED_REMOVAL_THRESHOLD elements

MIN_SAMPLE_SIZEback to summary
private static final int MIN_SAMPLE_SIZE

We should have a sample size of minimal length before computing the cache miss rate.

NEGATIVEback to summary
private static final double NEGATIVE
totalCallsback to summary
private volatile int totalCalls

Constructor Detail

NamedConverterback to summary
public NamedConverter()

Method Detail

convertback to summary
public String convert(ILoggingEvent event)

Implements abstract ch.qos.logback.core.pattern.Converter.convert.

Doc from ch.qos.logback.core.pattern.Converter.convert.

The convert method is responsible for extracting data from the event and storing it for later use by the write method.

disableCacheback to summary
private void disableCache()
getCacheMissesback to summary
public int getCacheMisses()
getCacheMissRateback to summary
public double getCacheMissRate()
getFullyQualifiedNameback to summary
protected abstract String getFullyQualifiedName(final ILoggingEvent event)

Gets fully qualified name from event.

Parameters
event:ILoggingEvent

The LoggingEvent to process, cannot not be null.

Returns:String

name, must not be null.

startback to summary
public void start()

Overrides ch.qos.logback.core.pattern.DynamicConverter.start.

Implements ch.qos.logback.core.spi.LifeCycle.start.

Doc from ch.qos.logback.core.pattern.DynamicConverter.start.

Components that depend on options passed during configuration can override this method in order to make appropriate use of those options. For simpler components, the trivial implementation found in this abstract class will be sufficient.

viaCacheback to summary
private synchronized String viaCache(String fqn)

This method is synchronized. It is the only place where the cache, a subclass of LinkedHashMap, is modified. The cache can be cleared via a call to disableCache(). However, the call to disableCache() is made indirectly from within viaCache(String).

ch.qos.logback.classic.pattern back to summary

pack-priv Class NamedConverter.CacheMissCalculator

extends Object
Class Inheritance
  • java.lang.Object
  • ch.qos.logback.classic.pattern.NamedConverter.CacheMissCalculator

Field Summary

Modifier and TypeField and Description
pack-priv int
pack-priv int

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv double
pack-priv void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cacheMissesMilestoneback to summary
pack-priv int cacheMissesMilestone
totalsMilestoneback to summary
pack-priv int totalsMilestone

Constructor Detail

CacheMissCalculatorback to summary
pack-priv CacheMissCalculator()

Method Detail

getCacheMissRateback to summary
pack-priv double getCacheMissRate()
updateMilestonesback to summary
pack-priv void updateMilestones()
ch.qos.logback.classic.pattern back to summary

private Class NamedConverter.NameCache

extends LinkedHashMap<String, String>
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv NamedConverter.CacheMissCalculator
pack-priv int
private static final long

Constructor Summary

AccessConstructor and Description
pack-priv
NameCache(int initialCapacity)

Method Summary

Modifier and TypeMethod and Description
protected boolean
removeEldestEntry(Map.Entry<String, String>
The least recently inserted entry in the map, or if this is an access-ordered map, the least recently accessed entry. This is the entry that will be removed if this method returns true. If the map was empty prior to the put or putAll invocation resulting in this invocation, this will be the entry that was just inserted; in other words, if the map contains a single entry, the eldest entry is also the newest.
entry
)

Overrides java.util.LinkedHashMap.removeEldestEntry.

In the JDK tested, this method is called for every map insertion.
private boolean
Inherited from java.util.LinkedHashMap:
clearcontainsValueentrySetforEachgetgetOrDefaultkeySetnewLinkedHashMapputFirstputLastreplaceAllreversedsequencedEntrySetsequencedKeySetsequencedValuesvalues

Field Detail

cacheMissCalculatorback to summary
pack-priv NamedConverter.CacheMissCalculator cacheMissCalculator
removalThresholdback to summary
pack-priv int removalThreshold
serialVersionUIDback to summary
private static final long serialVersionUID

Hides java.util.LinkedHashMap.serialVersionUID.

Constructor Detail

NameCacheback to summary
pack-priv NameCache(int initialCapacity)

Method Detail

removeEldestEntryback to summary
protected boolean removeEldestEntry(Map.Entry<String, String> entry)

Overrides java.util.LinkedHashMap.removeEldestEntry.

In the JDK tested, this method is called for every map insertion.

Parameters
entry:Map.Entry<String, String>

Doc from java.util.LinkedHashMap.removeEldestEntry.

The least recently inserted entry in the map, or if this is an access-ordered map, the least recently accessed entry. This is the entry that will be removed if this method returns true. If the map was empty prior to the put or putAll invocation resulting in this invocation, this will be the entry that was just inserted; in other words, if the map contains a single entry, the eldest entry is also the newest.

Returns:boolean

Doc from java.util.LinkedHashMap.removeEldestEntry.

true if the eldest entry should be removed from the map; false if it should be retained.

Annotations
@Override
shouldDoubleRemovalThresholdback to summary
private boolean shouldDoubleRemovalThreshold()