Applications deployed on Fabric3 can take advantage of an injection-based monitoring and logging framework. The monitoring framework offers a number of benefits:
- Strongly-typed monitoring interfaces and events
- Event-based monitoring
- Robust log capture via SLF4J
- Dynamic event level adjustment
Using Monitoring
To use the monitoring framework in application code, do the following: defining a monitor interface and injecting the monitor in a component.
Define a monitoring interface.
The monitoring interface is used for sending monitoring events. The interface defines expected events and monitoring levels using methods on the interface:
import org.fabric3.api.annotation.monitor.Severe; import org.fabric3.api.annotation.monitor.Debug; public inteface ComponentMonitor @Severe void error(String message, Throwable t); @Debug ("Received request {0}") void receivedRequest(String id); }
The above interface defines an error event and a debug event. The debug event also specifies a formatted message that will be logged if the event is received. The following monitoring levels are supported:
- Severe - Critical errors that affect continue runtime operation
- Warning - Error conditions that do not affect continued runtime operation or a potential runtime configuration issue
- Info - Informational event
- Debug - An event useful for diagnosing a problem
- Trace - A low level event useful for diagnosing a problem
By default, info and above are enabled at runtime.
Injecting the Monitor
A monitor is injected in a component using the org.fabric3.api.annotation.monitor.Monitor annotation.