Java JMeter 在哪里保存测试/应用程序日志?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23553208/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 23:51:21  来源:igfitidea点击:

Where does JMeter keep test/application logs?

javajmeter

提问by JBT

I want to monitor the logs from my tests (or applications if you will). For example, I might have a log line in the code like this:

我想监视来自我的测试(或应用程序,如果你愿意的话)的日志。例如,我可能在代码中有这样一行日志:

logger.info( "dummy log" );

However, when I run JMeter like this:

但是,当我像这样运行 JMeter 时:

jmeter -n -t foobar.jmx

I have no idea where to look for that dummy log. So, where does JMeter keep the logs from the tests? Better yet, how can I configure it?

我不知道去哪里寻找那个虚拟日志。那么,JMeter 在哪里保存测试日志?更好的是,我该如何配置它?

Thank you very much.

非常感谢。

update
I forgot to mention that the test logs were not found in the default log file jmeter.log. Is that true that the test logs should appear in the jmeter.logunless there are some settings disabling the output of the test logs?

更新
我忘了提到在默认日志文件中找不到测试日志jmeter.logjmeter.log除非有一些设置禁用了测试日志的输出,否则测试日志是否应该出现在 中?

update 2
I have pasted the jmeter.properties here: http://pastebin.com/6paTqRrK

更新2
我在这里贴了jmeter.properties:http://pastebin.com/6paTqRrK

Below are relevant code snippets.

下面是相关的代码片段。

package foo.bar;

import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.junit.Assert.assertTrue;

public class DummyTest {
    private static final Logger logger = LoggerFactory.getLogger( DummyTest.class.getName() );

    @Test
    public void test(){
        System.out.println("dummy message");
        logger.info("dummy log");
        assertTrue( true );
    }
}

Gradle build.gradle:

Gradle build.gradle:

dependencies {
    compile 'org.codehaus.groovy:groovy-all:2.2.1'

    compile 'org.slf4j:slf4j-api:1.7.5'
    runtime 'ch.qos.logback:logback-classic:1.0.13'
    runtime 'ch.qos.logback:logback-core:1.0.13'

    testCompile 'junit:junit:4.11'
}

// bundle everything into a fat jar
jar {
    from {
        configurations.testRuntime.collect {
            it.isDirectory() ? it : zipTree(it)
        } + sourceSets.main.output + sourceSets.test.output

    }
    archiveName = 'junit_sampler.jar'
}

task updateJar( type: Copy, dependsOn: jar ) {
    from './junit_sampler.jar'
    into "${System.properties['user.home']}/opt/apache-jmeter-2.11/lib/junit"
}

foobar.jmx:

foob​​ar.jmx

<?xml version="1.0" encoding="UTF-8"?>
<jmeterTestPlan version="1.2" properties="2.6" jmeter="2.11 r1554548">
  <hashTree>
    <TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="Check Logging" enabled="true">
      <stringProp name="TestPlan.comments"></stringProp>
      <boolProp name="TestPlan.functional_mode">false</boolProp>
      <boolProp name="TestPlan.serialize_threadgroups">false</boolProp>
      <elementProp name="TestPlan.user_defined_variables" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
        <collectionProp name="Arguments.arguments"/>
      </elementProp>
      <stringProp name="TestPlan.user_define_classpath"></stringProp>
    </TestPlan>
    <hashTree>
      <ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="Thread Group" enabled="true">
        <stringProp name="ThreadGroup.on_sample_error">continue</stringProp>
        <elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="Loop Controller" enabled="true">
          <boolProp name="LoopController.continue_forever">false</boolProp>
          <stringProp name="LoopController.loops">3</stringProp>
        </elementProp>
        <stringProp name="ThreadGroup.num_threads">1</stringProp>
        <stringProp name="ThreadGroup.ramp_time">1</stringProp>
        <longProp name="ThreadGroup.start_time">1399656770000</longProp>
        <longProp name="ThreadGroup.end_time">1399656770000</longProp>
        <boolProp name="ThreadGroup.scheduler">false</boolProp>
        <stringProp name="ThreadGroup.duration"></stringProp>
        <stringProp name="ThreadGroup.delay"></stringProp>
      </ThreadGroup>
      <hashTree>
        <JUnitSampler guiclass="JUnitTestSamplerGui" testclass="JUnitSampler" testname="JUnit Request" enabled="true">
          <stringProp name="junitSampler.classname">foo.bar.DummyTest</stringProp>
          <stringProp name="junitsampler.constructorstring"></stringProp>
          <stringProp name="junitsampler.method">test</stringProp>
          <stringProp name="junitsampler.pkg.filter"></stringProp>
          <stringProp name="junitsampler.success">Test successful</stringProp>
          <stringProp name="junitsampler.success.code">1000</stringProp>
          <stringProp name="junitsampler.failure">Test failed</stringProp>
          <stringProp name="junitsampler.failure.code">0001</stringProp>
          <stringProp name="junitsampler.error">An unexpected error occured</stringProp>
          <stringProp name="junitsampler.error.code">9999</stringProp>
          <stringProp name="junitsampler.exec.setup">false</stringProp>
          <stringProp name="junitsampler.append.error">false</stringProp>
          <stringProp name="junitsampler.append.exception">false</stringProp>
          <boolProp name="junitsampler.junit4">true</boolProp>
        </JUnitSampler>
        <hashTree/>
      </hashTree>
    </hashTree>
  </hashTree>
</jmeterTestPlan>

Somehow, the "dummy log" message just doesn't show up in the jmeter.log.

不知何故,“虚拟日志”消息没有出现在 jmeter.log 中。

回答by Nidheesh

The log file name is defined in the jmeter.propertiesfile (or using the -j option, see below). It defaults to jmeter.log , and will be found in the directory from which JMeter was launched.

日志文件名在jmeter.properties文件中定义(或使用 -j 选项,见下文)。它默认为jmeter.log,可以在启动 JMeter 的目录中找到

http://jmeter.apache.org/usermanual/get-started.html#logging

http://jmeter.apache.org/usermanual/get-started.html#logging

回答by Dmitri T

By default all logging goes to jmeter.logfile which is usually located in /bin folder of your JMeter installation. However the location may vary basing on how you launch JMeter and what would be it's working directory. See FileServerAPI for more details.

默认情况下,所有日志记录都转到jmeter.log通常位于 JMeter 安装的 /bin 文件夹中的文件。但是,位置可能会根据您启动 JMeter 的方式以及它的工作目录而有所不同。请参阅文件服务器API的更多细节。

If you want logging output from a custom class, extension or plugin it might be supressed by configuration. Try "telling" JMeter the desired log level for your class via property.

如果您想记录自定义类、扩展或插件的输出,它可能会被配置抑制。尝试通过属性“告诉”JMeter 类所需的日志级别。

See user.propertiesfile in /bin folder of your JMeter installation for sample logging levels configuration and Apache JMeter Properties Customization Guidefor how to change them.

有关user.properties示例日志记录级别配置和Apache JMeter 属性自定义指南,请参阅JMeter 安装的 /bin 文件夹中的文件以了解如何更改它们。

However I'm pretty sure that if you initialize your loggeras follows:

但是,我很确定,如果您logger按如下方式初始化:

import org.apache.jorphan.logging.LoggingManager;
...
...
private static final Logger logger = LoggingManager.getLoggerForClass(); 
...
logger.info("sonething");

You will see that "something" line in the log.

您将在日志中看到“某事”行。

Hope this helps.

希望这可以帮助。

回答by vim

For JMeter 2.13 you need to edit bin/log4j.conf where general log4j settings can be placed. For example, the bin/root.log file will be recorded as specified below:

对于 JMeter 2.13,您需要编辑 bin/log4j.conf,其中可以放置一般的 log4j 设置。例如,bin/root.log 文件将被记录如下:

###############################  IMPORTANT NOTE  ##############################
# JMeter does not use log4j as logging system
# This configuration will only be used by libraries that do use log4j
# or your custom code if it uses it

log4j.appender.Root_Appender=org.apache.log4j.RollingFileAppender
log4j.appender.Root_Appender.File=root.log
log4j.appender.Root_Appender.Append=true
log4j.appender.Root_Appender.MaxBackupIndex=0
log4j.appender.Root_Appender.layout=org.apache.log4j.PatternLayout
log4j.appender.Root_Appender.layout.ConversionPattern=%-5p %d{MM/dd, hh:mm:ss} %-20.30c %m%n

log4j.rootCategory=DEBUG,Root_Appender

回答by Prabhu

you have to allow your class package in log4j property of jmeter (under bin folder ex: apache-jmeter-4.0/bin/log4j.xml)

您必须在 jmeter 的 log4j 属性中允许您的类包(在 bin 文件夹下,例如:apache-jmeter-4.0/bin/log4j.xml)

sample log4j.xml com.tgs.jmeter with debug level added

添加了调试级别的示例 log4j.xml com.tgs.jmeter