Is there a way to pass values through the @LogMethod annotation. I want to pass a String and an Object (DataFileVO). How Can I do it?
Something like this.
@LogMethod(logLevel = LoggerOne.DEBUG, duaNum = "23L", duaDataFile = myListObject)
LoggerOne.java
public enum LoggerOne {
INFO, DEBUG;
}
LogMethod.java
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface LogMethod {
LoggerOne logLevel() default LoggerOne.INFO;
}
Util.java
public class Util {
public static void log(Object o, String methodName) {
Class klass = o.getClass();
for (Method m : klass.getMethods()) {
if (m.getName().equals(methodName)) {
for (Annotation a : m.getAnnotations()) {
if (a instanceof LogMethod) {
LogMethod lm = (LogMethod) a;
switch (lm.logLevel()) {
case INFO:
System.out.println("Performing Custom INFO logging for " + m.getName());
break;
case DEBUG:
System.out.println("Performing Custom DEBUG logging for " + m.getName());
}
}
}
break;
}
}
}
}
DataFileDaoImpl.java
@LogMethod(logLevel = LoggerOne.DEBUG)
public List<DuaDataFileVO> getDuaByDuaAndShipperCode(String duaNum, Long shipperCode) {
List<DuaDataFileVO> list = new ArrayList<DuaDataFileVO>();
// Some code
return list;
}