You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by bu...@apache.org on 2007/08/23 20:56:05 UTC

DO NOT REPLY [Bug 43204] New: - Contribution Java 5+ Improvements: String formatter, stack trace inspection

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=43204>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=43204

           Summary: Contribution Java 5+ Improvements: String formatter,
                    stack trace inspection
           Product: Log4j
           Version: unspecified
          Platform: Other
        OS/Version: other
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Other
        AssignedTo: log4j-dev@logging.apache.org
        ReportedBy: rbodkin+LISTS@gmail.com


I wrote a small enhancement to log4j that takes advantage of two useful Java
APIs: String.formatter to avoid creating garbage strings when a logger isn't
enabled and the ability to use a management factory to programmatically get
stack traces to avoid boilerplate code. I have implemented this as a decorator
(LogFormatter). E.g.,

public static class MyClass {
    public LogFormatter formatter = LogFormatter.get();

    public void myMethod(int foo) {
        formatter.debug("The value %d was received", foo);
        try {
            something();
        } catch (MyException e) {
            formatter.error(e, "Failure for %d", foo);
        }
    }
}

See attached code. Please feel free to reuse or incorporate this if you like any
of these features.

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


DO NOT REPLY [Bug 43204] - Contribution Java 5+ Improvements: String formatter, stack trace inspection

Posted by bu...@apache.org.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=43204>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=43204





------- Additional Comments From rbodkin+LISTS@gmail.com  2007-08-23 18:34 -------
Ok, the issue I noted was indeed just with LogF. The others guard object
construction appropriately. Thanks.


-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


DO NOT REPLY [Bug 43204] - Contribution Java 5+ Improvements: String formatter, stack trace inspection

Posted by bu...@apache.org.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=43204>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=43204





------- Additional Comments From rbodkin+LISTS@gmail.com  2007-08-23 11:58 -------
Created an attachment (id=20694)
 --> (http://issues.apache.org/bugzilla/attachment.cgi?id=20694&action=view)
Added features


-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


DO NOT REPLY [Bug 43204] - Contribution Java 5+ Improvements: String formatter, stack trace inspection

Posted by bu...@apache.org.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=43204>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=43204





------- Additional Comments From carnold@apache.org  2007-08-23 13:16 -------
Please review the LogMF and LogSF classes in the extras companion (http://svn.apache.org/repos/asf/
logging/log4j/companions/extras).  At one time there was a third parameterized logging wrapper LogF 
that used java.util.formatter, but development of that was dropped as there didn't seem to be any interest.  
See http://svn.apache.org/viewvc/logging/sandbox/log4j/formatter/src/main/java/org/apache/log4j/
formatter/?pathrev=532884.

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


DO NOT REPLY [Bug 43204] - Contribution Java 5+ Improvements: String formatter, stack trace inspection

Posted by bu...@apache.org.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=43204>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=43204





------- Additional Comments From rbodkin+LISTS@gmail.com  2007-08-23 11:59 -------
Created an attachment (id=20695)
 --> (http://issues.apache.org/bugzilla/attachment.cgi?id=20695&action=view)
Some initial tests. The other features have already been integration tested but
those tests can be split out into unit tests.


-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


DO NOT REPLY [Bug 43204] - Contribution Java 5+ Improvements: String formatter, stack trace inspection

Posted by bu...@apache.org.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=43204>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=43204





------- Additional Comments From carnold@apache.org  2007-08-23 14:44 -------
The intent and my expecation is that the LogMF and LogSF classes do not format or require array creation  
unless the request meets the threshold of the logger.  If they do not, it is a flaw in the implementation that 
can be corrected.  The LogF class has been discontinued due to lack of interest and perhaps it did not 
appropriately defer formatting.


-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


DO NOT REPLY [Bug 43204] - Contribution Java 5+ Improvements: String formatter, stack trace inspection

Posted by bu...@apache.org.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=43204>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=43204





------- Additional Comments From rbodkin+LISTS@gmail.com  2007-08-23 14:29 -------
It would be great to see formatting capabilities built-in to the core log4j
logger in the next major release, rather than having a wrapper. Failing that, I
think a wrapper that lets you make all the usual logger calls but supporting
formatting is a lot more usable than a helper class with static methods. A
wrapper could even be done with a subclass of Logger.

Note that a key requirement for this is to not format strings unless the log is
enabled for a given level. The code you pointed to in the companion will format
strings, generating garbage, even if the given logger is disabled. Creating
arrays of arguments is also probably another source of inefficiency (that could
be addressed by special cases for say 4 or fewer arguments).

It's also valuable to have exception logging with arguments for formatting.


-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org