Witam,
Mam za zadanie napisanie Loggera do pewnej aplikacji.
Niestety Logger za każdym wywołaniem potrzebuje podania mu obiektu
Log.Show("Tekst Przykladowy" , this);
W loggerze potrzebuje wywołać parę funkcji tego obiektu.
Czy można to jakoś obejść ? czy da się by logger sam przechwycił obiekt ?
Logger :
public static void Show(String msg,Object obiekt) {
//String callerClassName = new Exception().getStackTrace()[1].getClassName();
// String simpleClassName = callerClassName.substring(callerClassName.lastIndexOf('.') + 1);
Method method = null;
try {
method = obiekt.getClass().getMethod("getValueF");
} catch (SecurityException e) {
// exception handling omitted for brevity
} catch (NoSuchMethodException e) {
// exception handling omitted for brevity
}
Object ret = null;
try {
ret = method.invoke(obiekt );
} catch (IllegalArgumentException e) { // exception handling omitted for brevity
} catch (IllegalAccessException e) { // exception handling omitted for brevity
} catch (InvocationTargetException e) { // exception handling omitted for brevity
}