Este contenido no está disponible en el idioma seleccionado.

5.6. Logging


Before Seam, even the simplest log message required verbose code:
private static final Log log = LogFactory.getLog(CreateOrderAction.class);
 
public Order createOrder(User user, Product product, int quantity) { 
  if ( log.isDebugEnabled() ) { 
    log.debug("Creating new order for user: " + user.username() + 
              " product: " + product.name() + " quantity: " + quantity);
  } 
  return new Order(user, product, quantity); 
}
Copy to Clipboard Toggle word wrap
Seam provides a logging API that simplifies this code significantly:
@Logger private Log log; 

public Order createOrder(User user, Product product, int quantity) { 
  log.debug("Creating new order for user: #0 product: #1 quantity: #2", 
             user.username(), product.name(), quantity); 
          
  return new Order(user, product, quantity); 
}
Copy to Clipboard Toggle word wrap
Except for entity bean components (which require the log variable to be static), this will work regardless of whether the log variable is declared static.
String concatenation occurs inside the debug() method, so the verbose if ( log.isDebugEnabled() ) guard is unnecessary. Usually, we would not even need to explicitly specify the log category, since Seam knows where it is injecting the log.
If User and Product are Seam components available in the current contexts, the code is even more concise:
@Logger private Log log; 
public Order createOrder(User user, Product product, int quantity) { 
  log.debug("Creating new order for user: #{user.username} 
             product: #{product.name} quantity: #0", quantity); 
  return new Order(user, product, quantity); 
}
Copy to Clipboard Toggle word wrap
Seam logging automatically chooses whether to send output to log4j or JDK logging — if log4j is in the classpath, it will be used; if not, Seam uses JDK logging.
Volver arriba
Red Hat logoGithubredditYoutubeTwitter

Aprender

Pruebe, compre y venda

Comunidades

Acerca de la documentación de Red Hat

Ayudamos a los usuarios de Red Hat a innovar y alcanzar sus objetivos con nuestros productos y servicios con contenido en el que pueden confiar. Explore nuestras recientes actualizaciones.

Hacer que el código abierto sea más inclusivo

Red Hat se compromete a reemplazar el lenguaje problemático en nuestro código, documentación y propiedades web. Para más detalles, consulte el Blog de Red Hat.

Acerca de Red Hat

Ofrecemos soluciones reforzadas que facilitan a las empresas trabajar en plataformas y entornos, desde el centro de datos central hasta el perímetro de la red.

Theme

© 2025 Red Hat