|
||||||||||
PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES |
See:
Description
Class Summary | |
---|---|
MessageBundleLiteral |
Annotation Types Summary | |
---|---|
Category | Specifies a string category for the injected logger. |
Locale | Specifies a Locale for a typed logger. |
MessageBundle | Signify that a MessageBundle should be injected. |
Suffix | A suffix to use on the specified category (or fully qualified name of the injection point type if no category is specified). |
TypedCategory | Specifies a typed category for the injected logger. |
Provides injectable typed loggers and injectable typed message bundles suitable for internationalization and localization which can use any logging backend.
Seam Solder integrates JBoss Logging 3 as it's logging framework of choice. JBoss Logging 3 is a modern logging framework offering:
A number of the features of JBoss Logging 3 are still under development - at the moment only runtime generation of typed is supported, and these loggers only support the default message placed on the typed logger, and will not look up a localized message.
To use a typed logger, first create the logger definition:
@MessageLogger interface TrainSpotterLog { // Define log call with message, using printf-style interpolation of parameters @LogMessage @Message("Spotted %s diesel trains") void dieselTrainsSpotted(int number); }
You can then inject the typed logger with no further configuration:
// Use the train spotter log, with the log category "trains" @Inject @Category("trains") TrainSpotterLog log;
and use it:
log.dieselTrainsSpotted(7);
JBoss Logging will use the default locale unless overridden:
// Use the train spotter log, with the log category "trains", and select the UK locale @Inject @Category("trains") @Locale("en_GB") TrainSpotterLog log;
You can also log exceptions:
@MessageLogger interface TrainSpotterLog { // Define log call with message, using printf-style interpolation of parameters // The exception parameter will be logged as an exception @LogMessage @Message("Failed to spot train %s") void missedTrain(String trainNumber, @Cause Exception exception); }
You can then log a message with exception:
log.missedTrain("RH1", cause);
You can also inject a "plain old" Logger:
@Inject Logger log;
Typed loggers also provide internationalization support, simply add the @MessageBundle annotation to the logger interface (not currently supported).
Sometimes you need to access the message directly (for example to localize an exception message). Seam Solder let's you inject a typed message bundle. First, declare the message bundle:
@MessageBundle interface TrainMessages { // Define a message using printf-style interpolation of parameters @Message("No trains spotted due to %s") String noTrainsSpotted(String cause); }
Inject it:
@Inject @MessageBundle TrainMessages messages;
And use it:
throw new BadDayException(messages.noTrainsSpotted("leaves on the line"));
Category
,
Suffix
,
Locale
,
MessageBundle
|
||||||||||
PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES |