On Tuesday, November 8, 2016 at 4:36:20 AM UTC+1, vitrums wrote:
>
> Recently I found, that some log4j-like functionality in my client's code 
> could be handy. So with the GWT logging module I can pretty much have a 
> shared logging code, which is very convenient to use on both sides. The 
> tutorial is here http://www.gwtproject.org/doc/latest/DevGuideLogging.html 
> . However, I instantly ran into multiple questions:
>
> 1) How many loggers *(Logger.getLogger("logger-name")) *should I 
> typically get away with in an average size project? What will their 
> hierarcy and naming convention *("" -> "Parent-name" -> 
> "Parent-name.Child-name") *be? And therefore which one should be the most 
> common across the code for debugging and user's feedback during 
> troubleshooting *(is it some "parent.child.grandson...Adam"?)* // *see 2)*
>

The common practice (with almost any Java logging framework) is to have 
your loggers as static final fields and using the class name as the logger 
name (some logging frameworks even have static factory methods taking a 
java.lang.Class<?> as "name").
 

> 2) I'm developing my projects with GIN, and since a call like 
> *Logger.getLogger("logger-name")* has a string constant *"logger-name"*, 
> then any logger should definitely become a subject of injection (in my 
> opinion). Hence, I created providers - one per *"logger-name"* - and 
> bound *Logger.class* to them with an annotation, just like this:
> bind(Logger.class).annotatedWith(DefaultLogger.class).toProvider(
> DefaultLoggerProvider.class).in(Singleton.class);
> Clients of this logger are all sorts of views, presenters and UI 
> components. They usually obtain an instance by field or constructor 
> injection:
> @Inject @DefaultLogger private java.util.logging.Logger logger;
> I would like to know the *pros and cons* of this solution from your point 
> of view. Again, any best practices are very much welcome.
>

Re. the common practice above, you won't generally inject loggers.
Guice (but not GIN AFAIK) has custom support for java.util.logging.Logger 
and will inject them without the need for any 
configuration: https://github.com/google/guice/wiki/BuiltInBindings#loggers 
Note that this is only to remove some boilerplate, and Guice would inject a 
logger whose name is the name of the class it's injected in (see 1 above 
re. the common practice for naming loggers)

-- 
You received this message because you are subscribed to the Google Groups "GWT 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-web-toolkit+unsubscr...@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

Reply via email to