Log4jLoggerを特別な目的で拡張したいと思います。これが私が書いたクラスです:
package com.edfx.adb.common.logger;
import javax.faces.application.ProjectStage;
import javax.faces.context.FacesContext;
import org.apache.log4j.LogManager;
public final class Logger extends org.apache.log4j.Logger {
protected Logger(String name) {
super(name);
}
public static org.apache.log4j.Logger getLogger(String name) {
return LogManager.getLogger(name);
}
@Override
public void debug(Object message) {
if (isDebugEnable()) {
super.debug(message);
}
}
@Override
public void debug(Object message, Throwable throwable) {
if (isDebugEnable()) {
super.debug(message, throwable);
}
}
private boolean isDebugEnable() {
return FacesContext.getCurrentInstance().isProjectStage(ProjectStage.Development);
}
}
そして私はそれを次のように呼んでいます:
protected final Logger log = (Logger) Logger.getLogger(getClass());
しかし、私は例外を得ています:
Caused by: java.lang.ClassCastException: org.jboss.logmanager.log4j.BridgeLogger cannot be cast to com.edfx.adb.common.logger.Logger
at com.edfx.adb.web.controller.BaseWebController.<init>(BaseWebController.java:18) [classes:]
at com.edfx.adb.web.controller.AuthController.<init>(AuthController.java:27) [classes:]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [rt.jar:1.7.0_09]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) [rt.jar:1.7.0_09]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) [rt.jar:1.7.0_09]
at java.lang.reflect.Constructor.newInstance(Constructor.java:525) [rt.jar:1.7.0_09]
at java.lang.Class.newInstance0(Class.java:372) [rt.jar:1.7.0_09]
at java.lang.Class.newInstance(Class.java:325) [rt.jar:1.7.0_09]
at com.sun.faces.mgbean.BeanBuilder.newBeanInstance(BeanBuilder.java:188) [jsf-impl-2.1.7-jbossorg-2.jar:]