[ https://issues.apache.org/jira/browse/LOG4J2-33?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13885946#comment-13885946 ]
Matt Sicker commented on LOG4J2-33: ----------------------------------- I've got a better idea on how to implement this. Two particular ways to do it, both are essentially injecting a Logger into a declared (but not defined) Logger field of the class. One way to use it would be to mark the class or field with an annotation that an annotation processor would be able to statically inject the proper Logger (which could use annotation attributes to specify any default settings to override). The other way would be similar to how Mockito uses {{MockitoAnnotations.injectMocks(this)}} (or whatever the actual method is called; I forget thanks to autocomplete). A class wishing to inject a logger could add a line of code to each class like: {code:java} static { LogManager.inject(); } {code} Or a special-purpose abuse of class names could be made like: {code:java} public class Foo { static { L4J.inject(); } private static Logger LOGGER; } {code} I'd specify using {{@Inject}} on a Logger field, but last time I tried looking into that, CDI has several different candidates for injection and I'm not very experienced with it. I'd prefer the annotation route myself as doing it the other way is practically the same thing as the usual initialization. It could be done as an actual annotation processor, or it could be done with reflection somehow. I may have to think more in regard to the reflective version. > Support Annotations > ------------------- > > Key: LOG4J2-33 > URL: https://issues.apache.org/jira/browse/LOG4J2-33 > Project: Log4j 2 > Issue Type: New Feature > Components: API > Reporter: Ralph Goers > Fix For: 0.1 > > Attachments: 0001-Add-Loggable.patch > > > The Log4j API should support using annotations as provided in Java 6 so > applications can use them instead of calls to logger APIs. This is especially > useful for entering & exiting type of events, but could be used wherever > annotations are allowed. -- This message was sent by Atlassian JIRA (v6.1.5#6160) --------------------------------------------------------------------- To unsubscribe, e-mail: log4j-dev-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-dev-h...@logging.apache.org