1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| @Singleton
@LocalBean
@Startup
public class Log4jStartupBean {
private static final String LOG4J_XML = "/META-INF/log4j.xmll";
private Logger logger = null;
@PostConstruct
public void startup() {
// Recuperation de l'url du fichier de configuration
URL url = this.getClass().getResource(LOG4J_XML);
// Si l'url est nulle, ou si la taille du path est égal à 0, on retourne
// une erreur
if (url == null || url.getFile().length() == 0) {
throw new RuntimeException("Log4j config file " + url.getPath()
+ " not found");
// }
// On charge le fichier de configuration
DOMConfigurator.configure(url);
// On charge un logger
logger = Logger.getLogger("logger_test");
// On indique que le logger est initialisé
System.out.println("logger initialized");
logger.info("logger initialized with " + LOG4J_XML + "...");
}
} |
Partager