Monitor Configuration
Monitor events are routed to a destination.  A destination has one or more appenders that act as sinks for monitor events. It is possible to create a custom appender (detailed below) or use one of the provided appenders such as the file or console appenders. An application (or service) can send events to a custom destination or use the default runtime destination. Sending events to a custom destination allows traffic for a particular application, subsystem or service to be segmented from other events. Â
For complete details, see Monitor Reference.
Runtime Specific Behavior
The Fabric3 monitor framework uses different implementations depending on the host environment. For WebLogic, Maven and Ant, the native host logging framework is used. For example, on WebLogic, monitor proxies will forward events to WebLogic's logging infrastructure. Configuration is therefore specific to each host environment. Â The Fabric3 Standalone and Tomcat runtimes use the native Fabric3 monitoring implementation, which is described in the rest of this section.
Configuring the Runtime Destination
The default runtime destination is where Fabric3 runtime events (and application events if not specified) are sent. The default destination can be configured in systemConfig.xml , for example, to record events to a log file instead of outputting to the console. This is done by adding appender entires under the monitor element in systemConfig.xml:
<monitor> <appenders> <appender.file file="fabric3.log"/> <appender.console/>Â </appenders> </monitor>
The above example configures both a console and file appender. The file attribute is the location of the output file, which is relative to the runtime /data directory (subdirectories are supported).
Timestamp Formatting
Timestamp formatting can be configured using the pattern attribute of the monitor element:
<monitor pattern="%d:%m:%Y %H:%i:%s.%F"> ... </monitor>
The following formatting directives are supported:
- %a - Abbreviated weekday name ("Sun", "Mon", "Tue")
- %b - Abbreviated month name ("Jan", "Feb", "Mar")
- %c - The Month number
- %d - The day of month in padded two digit form (01..31)
- %e - The day of month in trimmed form (1..31)
- %f - Milliseconds in trimmed form (0..999)
- %F - Milliseconds in padded three digit form (000..999)
- %H - The hour in 24-hour form (00-23)
- %h - The hour in 12-hour form (01-12)
- %i - Minutes
- %j - Day of year (001..366)
- %k - The hour in trimmed 24-hour form (0..23)
- %l - The hour in trimmed 12-hour form (1..12)
- %M - The full month name
- %m - The month number
- %p - AM or PM
- %S - The seconds in trimmed form
- %s - The seconds in padded two digit form
- %W - The full weekday name("Sunday".."Saturday")
- %w - The day of week (1 - Sunday .. 7 - Saturday)
- %Y - The four digit year
- %y - The two digit year
Configuring the File Appender
A file appender can be configured for a destination to write events to disk. As shown previously, the appender entry takes a file attribute that specifies the file to write relative to the <runtime>/data/log directory (the default is fabric3.log). In addition, the file appender can be configured to roll based on size using the roll.type, max.backups and roll.size (in bytes) attributes:
 <monitor> <appenders> <appender.file file="fabric3.log" roll.type="size" roll.size="104857600" max.backups="10"/> </appenders> </monitor>
Configuring Custom Destinations
As mentioned previously, it is possible to setup custom destinations to segment event traffic. This is done by including a monitor entry in a composite file. The following example is taken from the monitor sample application:
<composite .... xmlns:f3="urn:fabric3.org"> Â Â <f3:monitor name="ApplicationDestination"> <appenders> <appender.file file="application.log"/> </appenders> </f3:monitor> </composite>
Application code can then reference the destination by specifying its name in the @Monitor annotation:
public class SomeComponent ... { @Monitor("ApplicationDestination")Â protected ServiceMonitor monitor; public void process() { ... monitor.message("This is a message"); } }