简体   繁体   English

是否可以在没有log4j的情况下使用perf4j?

[英]Is it possible to use perf4j without log4j?

I'm writing a library and would like to use perf4j mainly to expose JMX performance counters. 我正在编写一个库,并且想主要使用perf4j来公开JMX性能计数器。
According to the instructions here http://perf4j.codehaus.org/devguide.html perf4j is meant to be used in conjunction with log4j, however since I'm writing a library I have no control over log4j usage, users of the library may or may not wish to use log4j and I don't want to make this a requirement. 根据此处的说明http://perf4j.codehaus.org/devguide.html perf4j旨在与log4j结合使用,但是由于我正在编写一个库,因此无法控制log4j的使用,该库的用户可能或可能不希望使用log4j,而我不想将此成为要求。
Is there a way to use perf4j, specifically expose perf4j JMX counters programatically without requiring use of log4j? 有没有一种使用perf4j的方法,特别是以编程方式公开perf4j JMX计数器而无需使用log4j?

My answer is more or less. 我的回答或多或少。 Perf4J needs to output its measurements somewhere and this somewhere is a logging framework. Perf4J需要将其测量结果输出到某个地方,而这个地方是一个日志记录框架。 Perf4J is built to work with Log4J compatible frameworks, but you can change the underlying logging framework. Perf4J旨在与Log4J兼容框架一起使用,但是您可以更改底层的日志记录框架。 For example you can choose to use SFL4J or Commons Logging instead. 例如,您可以选择使用SFL4J或Commons Logging。

Here is a sample that depends only on perf4j's jar: 这是仅依赖于perf4j的jar的示例:

import org.perf4j.LoggingStopWatch;
import org.perf4j.StopWatch;

public class Perf4JEx {
    public static void main (String[] args) {
        StopWatch stopWatch = new LoggingStopWatch();
        // for demo purposes just sleep
        Thread.sleep(170);
        stopWatch.stop("timing");
    }
}

This code will output the measurements to the standard output (the default minimalist logging framework). 此代码会将测量结果输出到标准输出(默认的最小日志记录框架)。

start[1310075342634] time[171] tag[timing] 开始[1310075342634]时间[171]标签[时间]

Note that Perf4J uses log4j configuration files and also supports JMX. 请注意,Perf4J使用log4j配置文件,并且还支持JMX。

I would say yes. 我会说是的。 I followed the link you posted and noticed that the first paragraph said 我点击了您发布的链接,并注意到第一段内容

Some of the the Perf4J tools require additional dependencies (for example, the custom log4j appenders require the log4j jar to also be in your classpath). 一些Perf4J工具需要附加的依赖关系(例如,自定义log4j附加程序要求log4j jar也位于您的类路径中)。

That suggests to me that not having log4j in your classpath is a normal thing. 对我来说,这表明在类路径中没有log4j是很正常的事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM