Discussion:
[jira] [Commented] (LOG4J2-33) Support Annotations
Matt Sicker (JIRA)
2014-01-16 21:03:20 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-33?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13873930#comment-13873930 ]

Matt Sicker commented on LOG4J2-33:
-----------------------------------
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
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)
Ralph Goers (JIRA)
2014-01-18 03:43:20 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-33?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13875531#comment-13875531 ]

Ralph Goers commented on LOG4J2-33:
-----------------------------------

Yes. Something like http://javakane.blogspot.ro/2012/07/automate-log4j-logging-with-aop-and.html. The thought was to provide more than just injecting a logger but to mark methods to automatically log entry and exit.
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
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)
Matt Sicker (JIRA)
2014-01-27 05:29:39 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-33?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Matt Sicker updated LOG4J2-33:
------------------------------

Attachment: 0001-Add-Loggable.patch
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)
Gary Gregory (JIRA)
2014-01-28 01:42:38 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-33?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13883628#comment-13883628 ]

Gary Gregory commented on LOG4J2-33:
------------------------------------

What I do not like about the patch is that it creates a stack trace for every single logging call. And the usual pattern makes x2 worse:

if (Log.get().isDebugEnabled()) {
Log.get().debug(...);
}

So I would want to say:
Logger logger = Log.get();
if (logger.isDebugEnabled()) {
logger.debug(...);
}

Which is not pretty. Which make me want to save the Logger in an ivar, and that's the same as having a wrapper.

Am I missing something?
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)
Gary Gregory (JIRA)
2014-01-28 01:42:38 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-33?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13883628#comment-13883628 ]

Gary Gregory edited comment on LOG4J2-33 at 1/28/14 1:41 AM:
-------------------------------------------------------------

What I do not like about the patch is that it creates a stack trace for every single logging call. And the usual pattern makes x2 worse:

{code:Java}
if (Log.get().isDebugEnabled()) {
Log.get().debug(...);
}
{code}

So I would want to say:

{code:Java}
Logger logger = Log.get();
if (logger.isDebugEnabled()) {
logger.debug(...);
}
{code}

Which is not pretty. Which make me want to save the Logger in an ivar, and that's the same as having a wrapper.

Am I missing something?




was (Author: garydgregory):
What I do not like about the patch is that it creates a stack trace for every single logging call. And the usual pattern makes x2 worse:

if (Log.get().isDebugEnabled()) {
Log.get().debug(...);
}

So I would want to say:
Logger logger = Log.get();
if (logger.isDebugEnabled()) {
logger.debug(...);
}

Which is not pretty. Which make me want to save the Logger in an ivar, and that's the same as having a wrapper.

Am I missing something?
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)
Matt Sicker (JIRA)
2014-01-28 02:04:42 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-33?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13883655#comment-13883655 ]

Matt Sicker commented on LOG4J2-33:
-----------------------------------

No, you're perfectly correct. I'm not sure how to go about getting that data otherwise. This particular style might not be feasible. I'm working on an example using aspects for logging field access and method/constructor calls, so that might be more promising or useful. The thing is, though, we can't just add AOP as a dependency for log4j-api, so I'm not sure where the best place to put it would be. Perhaps a module/bundle?
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)
Matt Sicker (JIRA)
2014-01-29 22:52:08 UTC
Permalink
[ 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)
Matt Sicker (JIRA)
2014-03-13 19:37:44 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-33?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Matt Sicker updated LOG4J2-33:
------------------------------

Affects Version/s: 2.0-rc2
Support Annotations
-------------------
Key: LOG4J2-33
URL: https://issues.apache.org/jira/browse/LOG4J2-33
Project: Log4j 2
Issue Type: New Feature
Components: API
Affects Versions: 2.0-rc2
Reporter: Ralph Goers
Fix For: 0.1, 2.0-rc2
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.2#6252)
Matt Sicker (JIRA)
2014-03-13 19:37:45 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-33?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Matt Sicker updated LOG4J2-33:
------------------------------

Fix Version/s: 2.0-rc2
Support Annotations
-------------------
Key: LOG4J2-33
URL: https://issues.apache.org/jira/browse/LOG4J2-33
Project: Log4j 2
Issue Type: New Feature
Components: API
Affects Versions: 2.0-rc2
Reporter: Ralph Goers
Fix For: 0.1, 2.0-rc2
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.2#6252)
Bruce Brouwer (JIRA)
2014-03-22 00:58:43 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-33?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13943808#comment-13943808 ]

Bruce Brouwer commented on LOG4J2-33:
-------------------------------------

You should check out [Project Lombok|http://projectlombok.org/]. It uses Java's built in annotation processing features to make your code look like this:

{code}
@Log
public class LogExample {
public static void main(String... args) {
log.error("Something's wrong here");
}
}
{code}

And no, that code did not neglect to extend another class, nor did it neglect to define the log field. You could probably take the concepts from Lombok to do stuff like this as well:
{code}
public class LogExample {
@LogEntryExit
public void doStuff() {
// do stuff
}
}
{code}

Basically, it uses byte code manipulation to make this all work. From what I can tell, there is no need to setup anything special with javac or maven; it just works. It looks like there are some issues with some IDEs, which Project Lombok has solved. I haven't used it yet myself, but it might be fun to try it out in Log4j 2 (maybe after 2.0 is released)
Support Annotations
-------------------
Key: LOG4J2-33
URL: https://issues.apache.org/jira/browse/LOG4J2-33
Project: Log4j 2
Issue Type: New Feature
Components: API
Affects Versions: 2.0-rc2
Reporter: Ralph Goers
Fix For: 0.1, 2.0-rc2
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.2#6252)
Ralph Goers (JIRA)
2014-03-22 17:53:42 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-33?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13944164#comment-13944164 ]

Ralph Goers commented on LOG4J2-33:
-----------------------------------

Yes, I've seen that. What I had hoped was that all the logger calls could be annotations, but Java 6 & 7 don't provide support for that. In Java 8 annotations aren't allowed everywhere but it may be possible to do a lot more. I originally thought it would be cool if the annotations did nothing if logging was disabled but then would inject code if it was. However, that doesn't seem realistic the more I think about it.
Support Annotations
-------------------
Key: LOG4J2-33
URL: https://issues.apache.org/jira/browse/LOG4J2-33
Project: Log4j 2
Issue Type: New Feature
Components: API
Affects Versions: 2.0-rc2
Reporter: Ralph Goers
Fix For: 0.1, 2.0-rc2
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.2#6252)
Matt Sicker (JIRA)
2014-03-23 17:55:43 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-33?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13944501#comment-13944501 ]

Matt Sicker commented on LOG4J2-33:
-----------------------------------

The best way I think that it can be auto-initialized while keeping compatibility with everything is to allow an uninitialized Logger instance in the class, then let the annotation processor inject the proper code to instantiate the Logger.
Support Annotations
-------------------
Key: LOG4J2-33
URL: https://issues.apache.org/jira/browse/LOG4J2-33
Project: Log4j 2
Issue Type: New Feature
Components: API
Affects Versions: 2.0-rc2
Reporter: Ralph Goers
Fix For: 0.1, 2.0-rc2
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.2#6252)
Ralph Goers (JIRA)
2014-03-23 22:19:45 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-33?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13944608#comment-13944608 ]

Ralph Goers commented on LOG4J2-33:
-----------------------------------

The reason I've never done anything with this issue is that I am not sure I really see the value in doing

@Log

vs

@Log Logger logger;

vs

Logger logger = LogManager.getLogger(this.getClass());

except that the latter allows you to specify a different logger name.
Support Annotations
-------------------
Key: LOG4J2-33
URL: https://issues.apache.org/jira/browse/LOG4J2-33
Project: Log4j 2
Issue Type: New Feature
Components: API
Affects Versions: 2.0-rc2
Reporter: Ralph Goers
Fix For: 0.1, 2.0-rc2
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.2#6252)
Ralph Goers (JIRA)
2014-06-26 20:37:27 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-33?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Ralph Goers updated LOG4J2-33:
------------------------------

Fix Version/s: (was: 2.0-rc2)
2.0
Support Annotations
-------------------
Key: LOG4J2-33
URL: https://issues.apache.org/jira/browse/LOG4J2-33
Project: Log4j 2
Issue Type: New Feature
Components: API
Affects Versions: 2.0-rc2
Reporter: Ralph Goers
Fix For: 0.1, 2.0
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.2#6252)
Remko Popma (JIRA)
2014-07-18 03:42:05 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-33?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Remko Popma updated LOG4J2-33:
------------------------------

Fix Version/s: (was: 2.0)
2.1
Support Annotations
-------------------
Key: LOG4J2-33
URL: https://issues.apache.org/jira/browse/LOG4J2-33
Project: Log4j 2
Issue Type: New Feature
Components: API
Affects Versions: 2.0-rc2
Reporter: Ralph Goers
Fix For: 0.1, 2.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.2#6252)
Remko Popma (JIRA)
2014-09-20 06:15:34 UTC
Permalink
[ https://issues.apache.org/jira/browse/LOG4J2-33?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Remko Popma updated LOG4J2-33:
------------------------------
Fix Version/s: (was: 2.1)
2.2
Support Annotations
-------------------
Key: LOG4J2-33
URL: https://issues.apache.org/jira/browse/LOG4J2-33
Project: Log4j 2
Issue Type: New Feature
Components: API
Affects Versions: 2.0-rc2
Reporter: Ralph Goers
Fix For: 0.1, 2.2
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.3.4#6332)

Loading...