如何将日志写入btrace中的文件? [英] How can write logs to a file in btrace?

查看:117
本文介绍了如何将日志写入btrace中的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下 btrace 脚本.我想记录特定类中函数的进入和退出.

I have following btrace script. I would like to record entry and exit of functions in a specific class.

..
package com.sun.btrace.samples;

import com.sun.btrace.BTraceUtils;
import com.sun.btrace.Profiler;
import com.sun.btrace.annotations.*;
@BTrace class Profiling {
@Property
Profiler swingProfiler = BTraceUtils.Profiling.newProfiler();

@OnMethod(
    clazz="com.pkg.classname", 
    method="/.*/")
    void entry(@ProbeMethodName(fqn=true) String probeMethod) {
        BTraceUtils.print("Entry" );
        BTraceUtils.println(BTraceUtils.timestamp() );
        BTraceUtils.println(probeMethod);
    }

@OnMethod(
    clazz="com.pkg.classname", 
    location=@Location(value=Kind.RETURN)
    )
    void exit(@ProbeMethodName(fqn=true) String probeMethod, @Duration long duration) {
        BTraceUtils.print("Exit:" );
        BTraceUtils.println(BTraceUtils.timestamp() );
        BTraceUtils.println(probeMethod);
    }

}

这会在控制台上发出声音.如何将结果写入文件? Btrace不允许创建新对象.

This gives outout on the console. How could I write the result to a file? Btrace does not allow to create new objects.

(明显的解决方法是重定向到文件.另一种选择是使用VisualVM btrace插件-输出随后进入visualVM窗口.请注意,它是否可以处理500Mb左右的非常大的输出.)

(Obvious work around is redirect to a file. Another choice is to use VisualVM btrace plugin - the output then goes to visualVM window. Note sure if it an handle very large output 500Mb or so.)

谢谢

推荐答案

您可以使用BTrace代理(

You can start your application with BTrace agent (http://kenai.com/projects/btrace/pages/UserGuide#btrace-agent). Then you can specify scriptOutputFile argument to the agent and all output generated by calls to println etc. will go to the specified file instead of the stdout.

这篇关于如何将日志写入btrace中的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆