Jmeter (42) - From entry to advanced level - A thorough understanding of Jmeter configuration files - Extra chapter (detailed tutorial)

1 Introduction

Why Brother Hong wants to explain Jmeter's configuration file? It's because some children or friends encountered some problems that require modifying the configuration file during the test. They are not very clear or understand it. Even if they are modified, it is still vague. What's more, some people think that it is a sacred place and cannot be violated lightly. They dare not touch it and do not modify it. They are afraid that if they modify it wrongly, Jmeter will not be able to run. After listening to Brother Hong's bold modification, you will not have to reinstall a new Jmeter. Or if you have a good habit of making backups, make bold modifications after backing up before modification. If you make a mistake, you can just use the backup file to restore it.

2. Configuration file

Enter: properties in the search box under the %JMETER_HOME%\bin (or $JMETER_HOME/bin) directory and you  will find that there are multiple configuration files, as shown in the following figure:

If you want to learn automated testing, I recommend a set of videos to you. This video can be said to be the number one automated testing tutorial on the entire network played by Bilibili. The number of people online at the same time has reached 1,000, and there are also notes that can be collected and communicated with various channels. Master technical communication: 798478386    

[Updated] A complete collection of the most detailed practical tutorials on Python interface automation testing taught by Bilibili (the latest practical version)_bilibili_bilibili [Updated] A complete collection of the most detailed practical tutorials on Python interface automated testing taught by Bilibili (practical version) The latest version) has a total of 200 videos, including: 1. Why interface automation should be done for interface automation, 2. Overall view of request for interface automation, 3. Interface practice for interface automation, etc. For more exciting videos from UP master, please follow the UP account . icon-default.png?t=N7T8https://www.bilibili.com/video/BV17p4y1B77x/?spm_id_from=333.337 

In the previous article, the most important one is reportgenerator.properties , which is the Jmeter core configuration item file. It was explained and explained. The following is a summary and description of the settings of some other commonly used configuration files. It is planned that Brother Hong will explain the file today. log4j2.xml.

3.log4j2.xml

This file is not very big, and its contents have been roughly annotated. In fact, developers should be very familiar with this file. Let's take a look at what configuration items it contains.


<?xml version="1.0" encoding="UTF-8"?>
<!--
   Licensed to the Apache Software Foundation (ASF) under one or more
   contributor license agreements.  See the NOTICE file distributed with
   this work for additional information regarding copyright ownership.
   The ASF licenses this file to You under the Apache License, Version 2.0
   (the "License"); you may not use this file except in compliance with
   the License.  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
-->
<!-- Configuration后面的status,这个用于设置log4j2自身内部的信息输出,可以不设置,当设置成trace时,
 你会看到log4j2内部各种详细输出。可以设置成OFF(关闭)、WARN(输出告警信息)或Error(只输出错误信息)。
 级别可以配置为TRACE,DEBUG,INFO,WARN,ERROR,ALL或OFF之一。如果没有指定级别,则默认为ERROR。
 可以为addability属性赋值true或false。如果该属性被省略,则将使用默认值true。
-->
<!--日志级别以及优先级排序: OFF > FATAL > ERROR > WARN > INFO > DEBUG > TRACE > ALL -->
<Configuration status="WARN" packages="org.apache.jmeter.gui.logging">

  <Appenders>
    <!--日志输出到jmeter.log文件中-->
    <File name="jmeter-log" fileName="${sys:jmeter.logfile:-jmeter.log}" append="false">
      <PatternLayout>
        <pattern>%d %p %c{1.}: %m%n</pattern>
      </PatternLayout>
    </File>
    <!--日志输出到GUI界面中-->
    <GuiLogEvent name="gui-log-event">
      <PatternLayout>
        <pattern>%d %p %c{1.}: %m%n</pattern>
      </PatternLayout>
    </GuiLogEvent>

  </Appenders>
  <!-- 全局配置,默认所有的Logger都继承此配置 -->
  <Loggers>
    <!-- jmeter.log文件和GUI界面日志输出级别:info-->
    <Root level="info">
      <AppenderRef ref="jmeter-log" />
      <AppenderRef ref="gui-log-event" />
    </Root>

    <Logger name="org.apache.jmeter.junit" level="debug" />
    <!--
    <Logger name="org.apache.jmeter.control" level="debug" />
    <Logger name="org.apache.jmeter.testbeans" level="debug" />
    <Logger name="org.apache.jmeter.engine" level="debug" />
    <Logger name="org.apache.jmeter.threads" level="debug" />
    <Logger name="org.apache.jmeter.gui" level="warn" />
    <Logger name="org.apache.jmeter.testelement" level="debug" />
    <Logger name="org.apache.jmeter.util" level="warn" />
    <Logger name="org.apache.jmeter.protocol.http" level="debug" />
    -->
    <!-- # For CookieManager, AuthManager etc: -->
    <!--
    <Logger name="org.apache.jmeter.protocol.http.control" level="debug" />
    <Logger name="org.apache.jmeter.protocol.ftp" level="warn" />
    <Logger name="org.apache.jmeter.protocol.jdbc" level="debug" />
    <Logger name="org.apache.jmeter.protocol.java" level="warn" />
    <Logger name="org.apache.jmeter.testelements.property" level="debug" />
    -->
    <Logger name="org.apache.jorphan" level="info" />

    <!--
      # Apache HttpClient logging examples
    -->
    <!-- # Enable header wire + context logging - Best for Debugging -->
    <!--
    <Logger name="org.apache.http" level="debug" />
    <Logger name="org.apache.http.wire" level="error" />
    -->

    <!-- # Enable full wire + context logging -->
    <!-- <Logger name="org.apache.http" level="debug" /> -->

    <!-- # Enable context logging for connection management -->
    <!-- <Logger name="org.apache.http.impl.conn" level="debug" /> -->

    <!-- # Enable context logging for connection management / request execution -->
    <!--
    <Logger name="org.apache.http.impl.conn" level="debug" />
    <Logger name="org.apache.http.impl.client" level="debug" />
    <Logger name="org.apache.http.client" level="debug" />
    -->

    <!--
      # Reporting logging configuration examples
    -->
    <!-- # If you want to debug reporting, uncomment this line -->
    <!-- <Logger name="org.apache.jmeter.report" level="debug" /> -->

    <!--
      # More user specific logging configuration examples.
    -->
    <!-- <Logger name="org.apache.jorphan.reflect" level="debug" /> -->
    <!--
      # Warning: Enabling the next debug line causes javax.net.ssl.SSLException: Received fatal alert: unexpected_message
                 for certain sites when used with the default HTTP Sampler
    -->
    <!--
    <Logger name="org.apache.jmeter.util.HttpSSLProtocolSocketFactory" level="debug" />
    <Logger name="org.apache.jmeter.util.JsseSSLManager" level="debug" />
    -->

    <!--
      # Enable Proxy request debug
    -->
    <!-- <Logger name="org.apache.jmeter.protocol.http.proxy.HttpRequestHdr" level="debug" /> -->

  </Loggers>

</Configuration>

 

4. Configuration file node description

4.1 Root node Configuration

Root node Configuration: There are two child nodes: Appenders and Loggers.
status: used to specify the level of logs printed by log4j itself.
monitorinterval: used to specify the monitoring interval for log4j automatic reconfiguration, the unit is seconds (s), the minimum interval is 5s.

4.2Appenders node

The appender configuration uses the name of a specific appender plug-in or an appender element whose type attribute value is the name of the appender plug-in. In addition, each appender must have a name attribute that specifies a unique value within the appender collection. The logger will use this name to refer to the appender, which has three common sub-nodes: Console, RollingFile, and File.

4.2.1Console

Console: used to define the Appender output to the console.
name: Specify the name of the Appender.
target: SYSTEM_OUT or SYSTEM_ERR, generally only the default: SYSTEM_OUT is set.
PatternLayout: Output format, if not set, the default is %m%n.

4.2.2File

File: Appender used to define the file output to the specified location.
name: Specify the name of the Appender.
fileName: Specifies the file name with the full path of the destination file for the output log.
PatternLayout: Output format, if not set, the default is %m%n.

4.2.3RollingFile

RollingFile: Define the specified method to trigger a new Appender.
name: Appender name.
fileName: The name of the output log file (with full path).
filePattern: The file name pattern of archive log files.
PatternLayout: Output format, if not set, the default is: %m%n.
Policies: Specify the policy for rolling logs.
TimeBasedTriggeringPolicy: Policies subnode, time-based rolling policy. The interval attribute is how often to flip based on the most specific time unit in the date pattern. Defaults to 1.
SizeBasedTriggeringPolicy: Policies subnode, rolling policy based on file size. The size attribute is used to define the size of each log file. The size can be specified in bytes with a suffix of KB, MB or GB, for example 20MB.
DefaultRolloverStrategy: Used to specify the maximum number of log files in the same folder, starting to delete the oldest and create new ones (through the max attribute).

4.3Loggers node

LoggerConfig is configured using the logger element. The logger element must specify a name attribute. Usually a level attribute is specified, and an additivity attribute can also be specified. The level can be configured as one of TRACE, DEBUG, INFO, WARN, ERROR, ALL or OFF. If no level is specified, it defaults to ERROR. The addability attribute can be assigned a value of true or false. If this attribute is omitted, the default value true will be used.
LoggerConfig (including the root LoggerConfig) can configure properties that will be added to the properties copied from the ThreadContextMap. These properties can be referenced from Appenders, Filters, Layouts, etc. as if they were part of the ThreadContext Map. Properties can contain variables that will be resolved when the configuration is parsed, or dynamically resolved as each event is logged. For more information about using variables, see Property Substitution.
LoggerConfig can also configure one or more AppenderRef elements. Each referenced appender will be associated with the specified LoggerConfig. If multiple appenders are configured on the LoggerConfig, each of them will be called when processing logging events.
Every Log4j overall configuration must have a root logger. If a default root LoggerConfig is not configured, the default usage level is ERROR and a root LoggerConfig connected to a console appender. The main difference between the root logger and other loggers is that
the root logger does not have a name attribute.
The root logger does not support additivity properties because it has no parent.

There are two common nodes: Root and Logger.

4.3.1Root

Root: Specify the root log of the project. If the Logger is not specified separately, the Root log output will be used by default.
level: The output level of the log, there are 8 levels in total, from low to high, All < Trace < Debug < Info < Warn < Error < Fatal < OFF.
AppenderRef: Child node of Root, used to specify which Appender the log is output to.

4.3.2Logs

Logger: used to specify the log format individually.
level: The output level of the log, consistent with Root.
name: used to specify the class that the Logger is applicable to or the full path of the package where the class is located, inherited from the Root node.
AppenderRef: Child node of Logger, used to specify which Appender the log is output to. If not specified, it will be inherited from Root by default. If specified, it will be output in both the specified Appender and the Appender of Root. At this time we You can set the additivity="false" of the Logger to only output in the custom Appender.

5. Summary

5.1 Log level setting

Starting from JMeter3.2, the log level is no longer set in jmeter.properties, but through apache log4j2.xml.

Note: The program will print logs that are higher than or equal to the set level. The higher the log level is set, the fewer logs will be printed.

Set the log level in the configuration file log4j2.xml:

level="info">
ref="jmeter-log" />
ref="gui-log-event" />
#将level的值改为对应的日志级别,默认为info,也可以在GUI界面临时设置日志级别
log4j2定义了8个级别的日志,优先级从高到低依次为:
OFF > FATAL > ERROR > WARN > INFO > DEBUG > TRACE > ALL
ALL 用于打开所有日志记录
TRACE 追踪日志
DEBUG 指出细粒度信息事件对调试应用程序是非常有帮助的
INFO 消息在粗粒度级别上突出强调应用程序的运行过程
WARN 表明会出现潜在错误的情形
ERROR 指出虽然发生错误事件,但仍然不影响系统的继续运行
FATAL 指出每个严重的错误事件将会导致应用程序的退出
OFF 用于关闭所有日志记录

Take a look at the contents of the jmeter.log file:

2021-01-19 10:42:47,378 INFO o.a.j.r.d.JsonExporter: Writing statistics JSON to C:\Users\DELL\Desktop\HttpReports\statistics.json
2021-01-19 10:42:47,880 INFO o.a.j.r.d.ReportGenerator: Exporting data using exporter:'html' of className:'org.apache.jmeter.report.dashboard.HtmlTemplateExporter'
2021-01-19 10:42:47,882 INFO o.a.j.r.d.HtmlTemplateExporter: Will generate dashboard in folder: C:\Users\DELL\Desktop\HttpReports
2021-01-19 10:42:47,977 INFO o.a.j.r.d.HtmlTemplateExporter: Report will be generated in: C:\Users\DELL\Desktop\HttpReports, creating folder structure
2021-01-19 10:42:47,988 INFO o.a.j.r.d.TemplateVisitor: Copying folder from 'D:\software\apache-jmeter-5.1.1\bin\report-template' to 'C:\Users\DELL\Desktop\HttpReports', got message:[C:\Users\DELL\Desktop\HttpReports\html.csv, C:\Users\DELL\Desktop\HttpReports\statistics.json], found non empty folder with following content {}, will be ignored
2021-01-19 10:42:49,607 INFO o.a.j.JMeter: Dashboard generated

Copy a part. As you can see from the above, the content level is: INFO.

5.2Conversion modes provided by Log4j

%m 输出代码中指定的消息
%p 输出优先级,即DEBUG,INFO,WARN,ERROR,FATAL
%r 输出自应用启动到输出该log信息耗费的毫秒数
%c 输出所属的类目,通常就是所在类的全名
%t 输出产生该日志事件的线程名
%n 输出一个回车换行符,Windows平台为“\r\n”,Unix平台为“\n”
%d 输出日志时间点的日期或时间,默认格式为ISO8601,也可以在其后指定格式
如:%d{dd MMM yyyy HH:mm:ss,SSS},输出类似:02 Nov 2012 14:34:02,781
%l 输出日志事件的发生位置,包括类目名、发生的线程,以及在代码中的行数
如:Testlog.main(TestLog.java:10)
%F 输出日志消息产生时所在的文件名称
%L 输出代码中的行号
%x 输出和当前线程相关联的NDC(嵌套诊断环境),像java servlets多客户多线程的应用中
%% 输出一个"%"字符

Guess you like

Origin blog.csdn.net/Faith_Lzt/article/details/132876509