Hi Bram, as I wrote you in the previous email, Apache Onami-Logging release is currently under vote in the Incubator, it not available yet - but soon it will be. You can have a look anyway to the source code[1], which is not so different to what you implemented, but we support a series of known loggers. I'll send an announce on this ML anyway as soon as it will be released.
All the best, -Simo [1] https://svn.apache.org/repos/asf/incubator/onami/trunk/logging/ http://people.apache.org/~simonetripodi/ http://simonetripodi.livejournal.com/ http://twitter.com/simonetripodi http://www.99soft.org/ On Mon, Jan 28, 2013 at 2:08 PM, Bram <[email protected]> wrote: > @Christian: > > Thanks for your answer, I ended up with the following helper method: > > > public static void set(Object object, String fieldName, Object > fieldValue) { > Field field = null; > Class<?> clazz = object.getClass(); > > while(field == null) { > try { > field = clazz.getDeclaredField(fieldName); > field.setAccessible(true); > field.set(object, fieldValue); > break; > } catch (Exception ex) { > if (null != clazz.getSuperclass()) { > clazz = clazz.getSuperclass(); > } else { > throw new RuntimeException(ex); > } > } > } > } > > @Simone: > Is it correct the maven repositories for the logging project are not working > (yet)? I tried including it in my maven pom.xml but it can't fetch the > dependency > > > Op vrijdag 25 januari 2013 18:01:12 UTC+1 schreef Christian Gruber het > volgende: >> >> Make a method like this >> >> public static void set(Object object, String fieldName, Object fieldValue) >> { >> Class<?> objectClass = object.getClass(); >> String fieldName = (String) fieldValues[i]; >> try { >> Field field = findField(objectClass, fieldName); >> field.setAccessible(true); >> field.set(object, fieldValue); >> } catch (Exception ex) { >> throw new RuntimeException(String.format("Unable to set field '%s' of >> %s to %s: %s", >> fieldName, object, fieldValue, ex.getMessage()), ex); >> } >> } >> >> … and use it in your test infrastructure to: >> >> Utils.set(testInstance, "logger", mock(Logger)); >> >> or something like that. >> >> Christian. >> >> On 23 Jan 2013, at 5:54, Bram wrote: >> >> Im working on implementing Guice in some existing code. I use log4j2 as >> logger in that code, so I implemented an injector using this example: >> http://code.google.com/p/google-guice/wiki/CustomInjections >> >> I'm injecting my logger in the following way: >> >> clas Test { >> @InjectLogger >> private Logger logger; >> } >> >> This works perfectly, however all of my unit tests break because of >> logging >> statements in the code and no logger injected (thus: nullpointer >> exception). Ofcourse I understand why this is, but I dont know the best >> way >> to solve this. >> >> I can obviously add a setter for the logger that I call in my unit test >> set-up, but is that realy a proper solution? >> >> ________________________________ >> >> You received this message because you are subscribed to the Google Groups >> "google-guice" group. >> To post to this group, send email to [email protected]. >> To unsubscribe from this group, send email to >> [email protected]. >> >> Visit this group at http://groups.google.com/group/google-guice?hl=en. >> For more options, visit https://groups.google.com/groups/opt_out. > > -- > You received this message because you are subscribed to the Google Groups > "google-guice" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > Visit this group at http://groups.google.com/group/google-guice?hl=en. > For more options, visit https://groups.google.com/groups/opt_out. > > -- You received this message because you are subscribed to the Google Groups "google-guice" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/google-guice?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
