stockblocks
asked on
Can Java source code know it's parent file and package names without explicitly defining static String's?
I'm beginning to use JBuilder 2005 for servlet programming.
I often embed references to the source filename (and associated package it belongs to) when reporting error exceptions. Currently, I have private static String vars named -- appropriately -- CLASS_NAME and PACKAGE_NAME.
Is there a better way? I was wondering if there was some magical code call that automatically identifies their names. If not a JDK call, but perhaps a JBuilder macro-like call that can be embedded in my .java files (for example -- and I'm making this up -- #CLASSNAME#.)
I often embed references to the source filename (and associated package it belongs to) when reporting error exceptions. Currently, I have private static String vars named -- appropriately -- CLASS_NAME and PACKAGE_NAME.
Is there a better way? I was wondering if there was some magical code call that automatically identifies their names. If not a JDK call, but perhaps a JBuilder macro-like call that can be embedded in my .java files (for example -- and I'm making this up -- #CLASSNAME#.)
Use log4j. It will report the class and package which logged the message
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Excellent. I see that getClass().getName() reports both package and class names together, which is perfect!
Should have known this all along. Thanks!
SB
Should have known this all along. Thanks!
SB
glad to help
Log4j is the de facto standard for logging - i'd use it if i were you ;-)
ASKER
CEHJ, sorry -- thanks for the tip! I'll google it to learn more.