有一个sun的内部使用的类里面有一个方法可以得到调用者的类, 不过我觉得还是要小心一点儿,尽量不要使用这种内部的类sun.reflect.Reflection 类 /** Returns the class of the method <code>realFramesToSkip</code> frames up the stack (zero-based), ignoring frames associated with java.lang.reflect.Method.invoke() and its implementation. The first frame is that associated with this method, so <code>getCallerClass(0)</code> returns the Class object for sun.reflect.Reflection. Frames associated with java.lang.reflect.Method.invoke() and its implementation are completely ignored and do not count toward the number of "real" frames skipped. */ public static native Class getCallerClass(int realFramesToSkip);
不甚明白你们的意思……
我不需要用户名和时间之类的。譬如说com.exam.Example调用了log,
希望log记录下“com.exam.Example"
楼主您有空到这里看看
对您可能有帮助
对不起楼主啦
爱莫能助
学习ing
帮您顶
用Exception也是一个办法。。
看看log4j或者有吧
希望log记录下“com.exam.Example"////////////////////////////////////你用Class类的方法不就可以得到哪个class调到log了?,
然后Logger.getLogger(""),放到里面不就ok了?
塞个OB在被监视方法中即可
或者你创造一个被监听方法,该方法继承或者运行你要的方法
这样做更OO.
这里有关堆和栈的相关介绍
感觉还算详细啦
具体是哪个方法啊,我找了半天没找到……
不过eclipse里确实都可以看到那个class的信息了,只是我
找不到具体的方法而已……晕。
塞个OB在被监视方法中即可
或者你创造一个被监听方法,该方法继承或者运行你要的方法
你的意思是??我怎么不太明白?被监听的方法?
frames up the stack (zero-based), ignoring frames associated
with java.lang.reflect.Method.invoke() and its implementation.
The first frame is that associated with this method, so
<code>getCallerClass(0)</code> returns the Class object for
sun.reflect.Reflection. Frames associated with
java.lang.reflect.Method.invoke() and its implementation are
completely ignored and do not count toward the number of "real"
frames skipped. */
public static native Class getCallerClass(int realFramesToSkip);