2014-05-08 59 views
4

我想从我的测试(或应用程序,如果你愿意)监视日志。例如,我可能有这样的代码日志行:JMeter在哪里保存测试/应用程序日志?

logger.info("dummy log"); 

然而,当我运行的JMeter是这样的:

jmeter -n -t foobar.jmx 

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

非常感谢。

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

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

下面是相关的代码片段。

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); 
    } 
} 

摇篮的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

<?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> 

不知何故, “虚拟日志” 消息,只是没有在JMeter的出现。登录。

回答

0

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

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

+0

嗨,我没有在jmeter.log中看到测试日志。请参阅我的更新。 – JBT

+0

我刚刚在我的机器上用** jmeter-2.9 **进行了测试。我通过将目录更改为** \ apache-jmeter-2.9 \ apache-jmeter-2.9 \ bin **并输入* jmeter -n -t test.jmx -l logjtl.jtl *来以命令行模式运行jmeter。 – Nidheesh

+0

在bin文件夹中发现jmeter.log已更新并且包含日志。 – Nidheesh

2

默认情况下,所有的日志去jmeter.log文件,它通常位于你的安装Jmeter的/ bin文件夹。但是,根据启动JMeter的方式以及它的工作目录,位置可能会有所不同。有关更多详细信息,请参阅FileServer API。

如果你想从自定义类,扩展或插件输出日志,它可能会被配置压制。尝试通过属性“告诉”JMeter为您的课程设置所需的日志级别。

请参阅user.properties文件位于JMeter安装的样本日志记录级别配置的/ bin文件夹中,Apache JMeter Properties Customization Guide有关如何更改它们的文件。

不过,我敢肯定,如果你初始化logger如下:

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

你会看到在日志中说:“东西”行。

希望这会有所帮助。

+0

- @ Dmitri:感谢您的详细解答。但是,不知何故,它不是我的最终目标。我在这个问题中增加了更多细节。请看一下。我也将我的jmeter.properties粘贴到pastebin。链接在问题中。另外,我尝试了'org.apache.jorphan.logging.LoggingManager',但是gradle无法解析jorphan的依赖关系,所以这个解决方案对我来说不会起作用,因为我想保持gradle。 – JBT

+0

您需要额外配置'sl4j'日志记录以将输出追加到jmeter.log文件(或任何其他文件)。 http://www.slf4j.org/faq.html –

1

对于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 
相关问题