Package net.shibboleth.shared.service.impl

# Class LogbackLoggingService

java.lang.Object
net.shibboleth.shared.component.AbstractInitializableComponent
net.shibboleth.shared.component.AbstractIdentifiedInitializableComponent
net.shibboleth.shared.component.AbstractIdentifiableInitializableComponent
net.shibboleth.shared.service.AbstractReloadableService<Object>
net.shibboleth.shared.service.impl.LogbackLoggingService

All Implemented Interfaces:
  `Component`, `DestructableComponent`, `IdentifiableComponent`, `IdentifiedComponent`, `InitializableComponent`, `UnmodifiableComponent`, `LoggingService`, `ReloadableService<Object>`, `Aware`, `ApplicationContextAware`

public class LogbackLoggingService extends AbstractReloadableService<Object> implements LoggingService, ApplicationContextAware
Simple `LoggingService` that watches for logback configuration file changes and reloads the file when a change occurs.

Since:
  9.0.0

## Nested Class Summary

## Nested classes/interfaces inherited from class net.shibboleth.shared.service.AbstractReloadableService

`AbstractReloadableService.ServiceReloadTask`

## Field Summary

Fields
Modifier and Type
Field
Description
`private ApplicationContext`
`applicationContext`
Spring application context.
`private Resource`
`configurationResource`
Logging configuration resource.
`private Resource`
`fallbackConfiguration`
URL to the fallback logback configuration found in the classpath.
`private String`
`homePropertyName`
Optional name of a property to populate into the `LoggerContext`.
`private ch.qos.logback.classic.LoggerContext`
`loggerContext`
Logback logger context.
`private ch.qos.logback.core.status.StatusManager`
`statusManager`
Logger used to log messages without relying on the logging system to be full initialized.

## Constructor Summary

Constructors
Constructor
Description
`LogbackLoggingService()`

## Method Summary

Modifier and Type
Method
Description
`protected void`
`doInitialize()`
This method checks to ensure that the component ID is not null.
`protected void`
`doReload()`
Performs the actual reload.
`ServiceableComponent<Object>`
`getServiceableComponent()`
Get the serviceable component that this service supports.
`protected void`
`loadHomeProperty()`
Add the "home" property from the Spring application context to the logger context.
`protected void`
`loadLoggingConfiguration()`
Reads and loads in a new logging configuration.
`protected void`
`loadLoggingConfiguration(InputStream loggingConfig)`
Loads a logging configuration in to the active logger context.
`void`
`setApplicationContext(ApplicationContext context)`
`void`
`setFallbackConfiguration(Resource fallback)`
Set a resource to use as a fallback configuration if the primary is unavailable.
`void`
`setHomePropertyName(String name)`
Set name of a property to load into `LoggerContext`.
`void`
`setLoggingConfiguration(Resource configuration)`
Sets the logging configuration.
`protected boolean`
`shouldReload()`
Called by the `AbstractReloadableService<T>.ServiceReloadTask` to determine if the service should be reloaded.

### Methods inherited from class net.shibboleth.shared.service.AbstractReloadableService

`doDestroy, getLastReloadAttemptInstant, getLastSuccessfulReloadInstant, getLogPrefix, getReloadCheckDelay, getReloadFailureCause, getReloadTaskTimer, isFailFast, reload, setFailFast, setReloadCheckDelay, setReloadTaskTimer`

### Methods inherited from class net.shibboleth.shared.component.AbstractIdentifiableInitializableComponent

`setId`

### Methods inherited from class net.shibboleth.shared.component.AbstractIdentifiedInitializableComponent

`ensureId, getId, ifDestroyedThrowDestroyedComponentException, ifInitializedThrowUnmodifiabledComponentException, ifNotInitializedThrowUninitializedComponentException`

### Methods inherited from class net.shibboleth.shared.component.AbstractInitializableComponent

`checkComponentActive, checkSetterPreconditions, destroy, initialize, isDestroyed, isInitialized`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface net.shibboleth.shared.component.IdentifiedComponent

`getId`

### Methods inherited from interface net.shibboleth.shared.component.InitializableComponent

`initialize, isInitialized`

### Methods inherited from interface net.shibboleth.shared.service.ReloadableService

`getLastReloadAttemptInstant, getLastSuccessfulReloadInstant, getReloadFailureCause, reload`

## Field Details

### loggerContext

@NonnullAfterInit private ch.qos.logback.classic.LoggerContext loggerContext
Logback logger context.

### statusManager

@NonnullAfterInit private ch.qos.logback.core.status.StatusManager statusManager
Logger used to log messages without relying on the logging system to be full initialized.

### fallbackConfiguration

@NonnullAfterInit private Resource fallbackConfiguration
URL to the fallback logback configuration found in the classpath.

### configurationResource

@NonnullAfterInit private Resource configurationResource
Logging configuration resource.

### homePropertyName

@Nullable @NotEmpty private String homePropertyName
Optional name of a property to populate into the `LoggerContext`.

### applicationContext

@Nullable private ApplicationContext applicationContext
Spring application context.

## Constructor Details

### LogbackLoggingService

public LogbackLoggingService()

## Method Details

### setLoggingConfiguration

public void setLoggingConfiguration(@Nonnull Resource configuration)
Sets the logging configuration.

Specified by:
  `setLoggingConfiguration` in interface `LoggingService`
Parameters:
  `configuration` - logging configuration

### setFallbackConfiguration

public void setFallbackConfiguration(@Nonnull Resource fallback)
Set a resource to use as a fallback configuration if the primary is unavailable.

Parameters:
  `fallback` - fallback configuration resouurce

### setHomePropertyName

public void setHomePropertyName(@Nullable @NotEmpty String name)
Set name of a property to load into `LoggerContext`.

Parameters:
  `name` - property name

### setApplicationContext

public void setApplicationContext(@Nonnull ApplicationContext context)

Specified by:
  `setApplicationContext` in interface `ApplicationContextAware`

### getServiceableComponent

@Nonnull public ServiceableComponent<Object> getServiceableComponent()
Get the serviceable component that this service supports. If the component hasn't been successfully loaded yet or if this service does not support a ServiceableComponent, a `ServiceException` is raised.

On a non-null value, the returned component will be pinned and MUST be closed. This can be done by exploiting the fact that a ServiceableComponent implements `AutoCloseable`

. This service does not support a ServiceableComponent, so return null.

Specified by:
  `getServiceableComponent` in interface `ReloadableService<Object>`
Returns:
  the component, if appropriate.

### doInitialize

protected void doInitialize() throws ComponentInitializationException
This method checks to ensure that the component ID is not null. Performs the initialization of the component. This method is executed within the lock on the object being initialized. The default implementation of this method is a no-op.

Overrides:
  `doInitialize` in class `AbstractReloadableService<Object>`
Throws:
  `ComponentInitializationException` - thrown if there is a problem initializing the component

### shouldReload

protected boolean shouldReload()
Called by the `AbstractReloadableService<T>.ServiceReloadTask` to determine if the service should be reloaded.

No lock is held when this method is called, so any locking needed should be handled internally.

Specified by:
  `shouldReload` in class `AbstractReloadableService<Object>`
Returns:
  true iff the service should be reloaded

### doReload

protected void doReload()
Performs the actual reload.

No lock is held when this method is called, so any locking needed should be handled internally.

Overrides:
  `doReload` in class `AbstractReloadableService<Object>`

### loadLoggingConfiguration

protected void loadLoggingConfiguration()
Reads and loads in a new logging configuration.

Throws:
  `ServiceException` - thrown if there is a problem loading the logging configuration

### loadLoggingConfiguration

protected void loadLoggingConfiguration(@Nonnull InputStream loggingConfig)
Loads a logging configuration in to the active logger context. Error messages are printed out to the status manager.

Parameters:
  `loggingConfig` - logging configuration file
Throws:
  `ServiceException` - thrown is there is a problem loading the logging configuration

### loadHomeProperty

protected void loadHomeProperty()
Add the "home" property from the Spring application context to the logger context.

This is principally to allow a defaulted value of this property to be referenced within the logging configuration itself as a location.