[jboss-dev-forums] [JBoss AS7 Development] - Logging for JBoss Application Server 7 Subsystems

James Perkins do-not-reply at jboss.com
Mon Nov 7 11:54:58 EST 2011


James Perkins [http://community.jboss.org/people/jamezp] modified the document:

"Logging for JBoss Application Server 7 Subsystems"

To view the document, visit: http://community.jboss.org/docs/DOC-17334

--------------------------------------------------------------
h3. *General Rules:*
* All exceptions and messages require a translation method in the @MessageBundle.
* All info and higher messages being logged require a translation method in the @MessageLogger.
* Messages in both the @MessageBundle and @MessageLogger should have an id***.  Note though there are cases, specifically some methods in the @MessageBundle, that do not need id's. These typically include messages that are not being used in exceptions.
* All logged messages should use a static logger from the @MessageLogger interface. This includes debug and trace messages.

*** A list of id's can be found here  http://community.jboss.org/docs/DOC-16810 http://community.jboss.org/wiki/LoggingIds

h3. Passing the cause:
Both @MessageLogger's and @MessageBundle's can except a java.lang.Throwable type as a parameter to either log the exception or intialize the exception return types cause. This is done by annotating the parameter with @Cause.
StartException unableToStart(@Cause Throwable cause);


h3. Creating Exception Return Types:
Most @MessageBundle's methods will be returing exceptions. Some exceptions require a special constructor to be used or require a property/field to be set on the exception. JBoss Logging has 3 separate annotations for these requirements.

@Param - Is used for exception constructor.
SAXParseException invalidAttribute(@Param Locator locator, String attributeName, String tagName);


@Field({name=fieldName}) - Is used to set an instance variable.
XAException invalidTransaction(@Field Integer errorCode);


@Propert({name=propertyName}) - Is used to set a property via it's setter method.
Exception createException(@Property StackTrace[] stackTrace);

h3. 
h3. *Examples:*
*
*
*Before:*
@Override
public void start(StartContext context) throws StartException {
    try {
        final JBossThreadFactory threadFactory = new JBossThreadFactory(new ThreadGroup("ServerDeploymentRepository-temp-threads"), Boolean.FALSE, null, "%G - %t", null, null, AccessController.getContext());
        tempFileProvider = TempFileProvider.create("temp", Executors.newScheduledThreadPool(2, threadFactory));
    } catch (IOException e) {
        throw new StartException("Failed to create temp file provider");
    }
    log.debugf("%s started", ServerDeploymentRepository.class.getSimpleName());
}


*Methods added to DeploymentRepositoryMessages:*
/**
 * Creates an exception indicating a failure to create a temp file provider.
 *
 * @return a {@link StartException} for the error.
 */
@Message(id = 14900, value = "Failed to create temp file provider")
StartException failedCreatingTempProvider();


*After:*
@Override
public void start(StartContext context) throws StartException {
    try {
        final JBossThreadFactory threadFactory = new JBossThreadFactory(new ThreadGroup("ServerDeploymentRepository-temp-threads"), Boolean.FALSE, null, "%G - %t", null, null, AccessController.getContext());
        tempFileProvider = TempFileProvider.create("temp", Executors.newScheduledThreadPool(2, threadFactory));
    } catch (IOException e) {
        throw MESSAGES.failedCreatingTempProvider();
    }
    ROOT_LOGGER.debugf("%s started", ServerDeploymentRepository.class.getSimpleName());
}
--------------------------------------------------------------

Comment by going to Community
[http://community.jboss.org/docs/DOC-17334]

Create a new document in JBoss AS7 Development at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=102&containerType=14&container=2225]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-dev-forums/attachments/20111107/50bf3168/attachment.html 


More information about the jboss-dev-forums mailing list