BeanUtils
BeanUtils copied to clipboard
Logger must use log4J
com.tuyang.beanutils.internal.logger.Logger
springboot recommends logback, but the jar must use the log4j, Otherwise, it will directly system.out.println. it does not make sense,
public static Logger getLogger(Class<?> clazz) {
try {
Class<?> loggerClass = Logger.class.getClassLoader().loadClass("org.apache.log4j.Logger");
Method method = loggerClass.getMethod("getLogger", Class.class);
Object logger = method.invoke(null, clazz);
return new Logger(logger);
}catch (Exception e) {
}
return new Logger(null);
}
public void info(Object message, Throwable t) {
if( logger != null ) {
try {
Method method = logger.getClass().getMethod("info", Object.class, Throwable.class);
method.invoke(logger, message, t);
} catch (Exception e) {
e.printStackTrace();
}
} else {
if( BeanCopyConfig.instance().getLogLevel() < LogLevelInfo )
return;
System.out.println(message.toString());
t.printStackTrace();
}
}
It is designed for common use, not only for springboot. And it is easy to extend log4j to logback.