You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by "Connerth, David" <DC...@gmti.gannett.com> on 2003/04/21 16:33:58 UTC

Logging method signature, parm values

I would like to log method signature and parm values in my log file.  I am currently doing this manually:

Class SomeClass {

public void foo(String parm1, int parm2, MyClass parm3) {
	log.debug("Enter: " + this + " String parm1, int parm2, MyClass parm3");
	log.debug(" parm1=" + parm1 + " parm2= " + new Integer(parm2).stringVal + " parm3=" + parm3);
}

My log file uses a conversion pattern of:

%4.4L %-27.27C{1}%-22.22M %m%n

which creates log entries like:

1383 SomeClass                  foo                    Enter: SomeclassToString [String parm1, int parm2, MyClass parm3]
1384 SomeClass                  foo                    parm1="Hello" parm2=0 parm3="MyClassToString"
1500 Someclass			  foo				 Some other log entry later in the method...  
 
This way I can look at the log file and see the parm values when each method is entered.   Since I only only use this setup for my console appender, I assume that using the M and C performance hit won't matter as long as the console appender is turned off, which it normally is.  

The problem with this approach is that making the log.debug commands is tedious.  Would it be possible to have something like a "debugM" (debug method):

log.debugM(new Object[] { parm1, new Integer(parm2), parm3 });

where is passed an array of parm values.

Since log4j knows the line number, it could look up the method signature and print something like:

Enter: Someclass.foo(String parm1, int parm2, MyClass parm3)
	parm1="Hello"
	parm2=0
	parm3="MyClassToString"

This way, if the parm values are long they are easy to read.
	
Thanks,

David L. Connerth
Director, Digicol Development

Gannett Media Technologies International
513.587.2941 Desk
513.478-7583 Mobile
513.241.7219 Fax
dconnert@gmti.gannett.com
http://www.gmti.com


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


Re: Logging method signature, parm values

Posted by Steve Ebersole <st...@austin.rr.com>.
It doesn't get you exactly what you want, but have you looked at the
Logger.l7dlog() methods?  It gets you pretty close.


----- Original Message -----
From: "Connerth, David" <DC...@gmti.gannett.com>
To: <lo...@jakarta.apache.org>
Cc: "Christopher Burkey (E-mail)" <cb...@einnovation.com>; "Eric Galluzzo
(E-mail)" <eg...@einnovation.com>
Sent: Monday, April 21, 2003 9:33 AM
Subject: Logging method signature, parm values


I would like to log method signature and parm values in my log file.  I am
currently doing this manually:

Class SomeClass {

public void foo(String parm1, int parm2, MyClass parm3) {
log.debug("Enter: " + this + " String parm1, int parm2, MyClass parm3");
log.debug(" parm1=" + parm1 + " parm2= " + new Integer(parm2).stringVal + "
parm3=" + parm3);
}

My log file uses a conversion pattern of:

%4.4L %-27.27C{1}%-22.22M %m%n

which creates log entries like:

1383 SomeClass                  foo                    Enter:
SomeclassToString [String parm1, int parm2, MyClass parm3]
1384 SomeClass                  foo                    parm1="Hello" parm2=0
parm3="MyClassToString"
1500 Someclass   foo Some other log entry later in the method...

This way I can look at the log file and see the parm values when each method
is entered.   Since I only only use this setup for my console appender, I
assume that using the M and C performance hit won't matter as long as the
console appender is turned off, which it normally is.

The problem with this approach is that making the log.debug commands is
tedious.  Would it be possible to have something like a "debugM" (debug
method):

log.debugM(new Object[] { parm1, new Integer(parm2), parm3 });

where is passed an array of parm values.

Since log4j knows the line number, it could look up the method signature and
print something like:

Enter: Someclass.foo(String parm1, int parm2, MyClass parm3)
parm1="Hello"
parm2=0
parm3="MyClassToString"

This way, if the parm values are long they are easy to read.

Thanks,

David L. Connerth
Director, Digicol Development

Gannett Media Technologies International
513.587.2941 Desk
513.478-7583 Mobile
513.241.7219 Fax
dconnert@gmti.gannett.com
http://www.gmti.com


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



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