Log level consistency detection method and device, equipment, medium and product
Through automated detection methods, log-level consistency detection is used to use configuration files and keywords, which solves the problem of inefficient relying on manual detection in the existing technology, and realizes efficient and accurate log-level consistency detection to ensure consistency between the test environment and the production environment.
Patent Information
- Application Number
- CN202510622069.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-14
- Publication Date
- 2025-08-15
AI Technical Summary
In the prior art, log-level consistency detection depends on the subjective ability of the tester, resulting in inefficient detection and easy to miss, and it is impossible to ensure the log-level consistency between the test environment and the production environment.
By receiving the configuration file of the program to be tested, obtaining the keywords of the test environment and production environment input by the user, automatically traversing the configuration files, performing consistency detection based on the keywords, generating alarm information and sending it to the user.
It realizes automated log-level consistency detection, reduces manual intervention, improves detection accuracy and efficiency, ensures log-level consistency between the test environment and the production environment, and reduces the risk of human omissions and misjudgments.
Smart Images

Figure CN120492349A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of consistency detection technology, and in particular to a log level consistency detection method, apparatus, device, medium and product. Background Art
[0002] When conducting software testing, especially performance testing, it's crucial to ensure that the log levels of the application system being tested are consistent with those of the production environment. If these levels are inconsistent, the measured performance data will be inaccurate and offer no useful reference for the subsequent rollout of the tested functionality. Therefore, ensuring the consistency of logs in the test and production environments is a pressing issue.
[0003] In the prior art, the method for checking the consistency of log levels usually adopts manual detection. First, the tester is required to understand the code structure of the system to be tested, the configuration file content and configuration logic, and then manually check whether the log output statement is consistent with the log level set in the configuration.
[0004] However, the log-level consistency checking method in the prior art places high demands on the subjective ability of the tester, resulting in unstable test efficiency. Summary of the Invention
[0005] The present application provides a log level consistency detection method to solve the problem in the prior art that the consistency check process requires high subjective ability of testers and has low test efficiency.
[0006] In a first aspect, the present application provides a log level consistency detection method, comprising:
[0007] Receive the configuration file of the program to be tested;
[0008] receiving a first keyword representing a test environment and a second keyword representing a production environment input by a user;
[0009] Traversing the configuration files to obtain a target configuration file containing a target keyword;
[0010] Based on the target configuration file, the first keyword, and the second keyword, consistency between the test environment and the production environment is detected to obtain a consistency detection result.
[0011] In a possible implementation, the detecting consistency between the test environment and the production environment based on the target configuration file, the first keyword, and the second keyword to obtain a consistency detection result includes:
[0012] Obtaining the area content of the first tag area and the attribute value under the second tag in the target configuration file;
[0013] Determining consistency of specific logger configurations in the test environment and the production environment based on the area content, the first keyword, and the second keyword;
[0014] Determining consistency of root logger configurations in the test environment and the production environment based on the second tag, the attribute value, the first keyword, and the second keyword;
[0015] The consistency of the specific logger configuration and the consistency of the root logger configuration are determined as the consistency detection result.
[0016] In a possible implementation, determining consistency of specific logger configurations in the test environment and the production environment based on the area content, the first keyword, and the second keyword includes:
[0017] Checking whether the first keyword and the second keyword appear in pairs in the regional content;
[0018] If so, determining that the specific logger configurations in the test environment and the production environment are consistent;
[0019] If not, an alarm message is generated.
[0020] In a possible implementation, determining consistency of the root logger configurations in the test environment and the production environment based on the second tag, the attribute value, the first keyword, and the second keyword includes:
[0021] When determining that a conditional statement exists in the first two nodes of the level where the second tag is located, determining whether the conditional statement hits the first keyword or the second keyword;
[0022] If the first keyword is hit, assign the attribute value to the first variable;
[0023] If the second keyword is hit, assigning the attribute value to the second variable;
[0024] Determining whether the contents of the first variable and the second variable are consistent;
[0025] When the contents of the first variable and the second variable are consistent, determining that the root logger configurations in the test environment and the production environment are consistent;
[0026] When the contents of the first variable and the second variable are inconsistent, an alarm message is generated.
[0027] In a possible implementation, after obtaining the consistency detection result, the method further includes:
[0028] When the consistency check result includes the alarm information, writing the alarm information into an alarm log file;
[0029] Send the alarm log file to the user.
[0030] In a possible implementation, sending the alarm log file to the user includes:
[0031] The warning log file is sent to the user via the Simple Mail Transfer Protocol (SMTP).
[0032] In a second aspect, the present application provides a log level consistency detection device, comprising:
[0033] The acquisition module is used to receive the configuration file of the program to be tested;
[0034] A receiving module, configured to receive a first keyword representing a test environment and a second keyword representing a production environment input by a user;
[0035] A traversal module, configured to traverse the configuration file to obtain a target configuration file containing a target keyword;
[0036] A processing module is used to detect the consistency of the test environment and the production environment based on the target configuration file, the first keyword and the second keyword to obtain a consistency detection result.
[0037] In a possible implementation, the processing module is specifically configured to:
[0038] Obtaining the area content of the first tag area and the attribute value under the second tag in the target configuration file;
[0039] Determining consistency of specific logger configurations in the test environment and the production environment based on the area content, the first keyword, and the second keyword;
[0040] Determining consistency of root logger configurations in the test environment and the production environment based on the second tag, the attribute value, the first keyword, and the second keyword;
[0041] The consistency of the specific logger configuration and the consistency of the root logger configuration are determined as the consistency detection result.
[0042] In a possible implementation, the processing module is specifically configured to:
[0043] Checking whether the first keyword and the second keyword appear in pairs in the regional content;
[0044] If so, determining that the specific logger configurations in the test environment and the production environment are consistent;
[0045] If not, an alarm message is generated.
[0046] In a possible implementation, the processing module is specifically configured to:
[0047] When determining that a conditional statement exists in the first two nodes of the level where the second tag is located, determining whether the conditional statement hits the first keyword or the second keyword;
[0048] If the first keyword is hit, assign the attribute value to the first variable;
[0049] If the second keyword is hit, assigning the attribute value to the second variable;
[0050] Determining whether the contents of the first variable and the second variable are consistent;
[0051] When the contents of the first variable and the second variable are consistent, determining that the root logger configurations in the test environment and the production environment are consistent;
[0052] When the contents of the first variable and the second variable are inconsistent, an alarm message is generated.
[0053] In a possible implementation, the processing module is further configured to:
[0054] When the consistency check result includes the alarm information, writing the alarm information into an alarm log file;
[0055] Send the alarm log file to the user.
[0056] In a possible implementation, the processing module is specifically configured to:
[0057] The warning log file is sent to the user via SMTP.
[0058] In a third aspect, the present application provides an electronic device, comprising: a memory, a processor;
[0059] The memory stores computer-executable instructions;
[0060] The processor executes the computer-executable instructions stored in the memory, so that the processor executes the above first aspect and / or various possible implementations of the first aspect.
[0061] In a fourth aspect, the present application provides a computer-readable storage medium, in which computer-executable instructions are stored. When the computer-executable instructions are executed by a processor, they are used to implement the above first aspect and / or various possible implementations of the first aspect.
[0062] In a fifth aspect, the present application provides a computer program product, comprising a computer program, which, when executed by a processor, implements the above first aspect and / or various possible implementations of the first aspect.
[0063] The present application provides a log level consistency detection method, device, equipment, medium and product. The method includes: first, receiving the configuration file of the program to be tested; then, receiving the first keyword representing the test environment and the second keyword representing the production environment input by the user, ensuring the relevance of the detection range; then, traversing the configuration file to obtain a target configuration file containing the target keyword; finally, based on the target configuration file, the first keyword and the second keyword, the consistency of the test environment and the production environment is detected to obtain a consistency detection result. At this point, by automatically traversing and identifying the configuration content, the time for manually locating the configuration file and content is saved, and the environment is located by keywords, and the log configuration is accurately compared to reduce human omissions or misjudgments. This method effectively solves the pain points of relying on manual labor, low efficiency, and easy omissions in the existing technology by automatically extracting and comparing the log configuration content, improves the accuracy of log detection, and ensures the testing quality of the software. BRIEF DESCRIPTION OF THE DRAWINGS
[0064] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0065] Figure 1 Schematic diagram of the log level consistency detection method provided in this application embodiment Figure 1 ;
[0066] Figure 2 Schematic diagram of the log level consistency detection method provided in this application embodiment Figure 2 ;
[0067] Figure 3 A schematic diagram of the structure of a log level consistency detection device provided in an embodiment of the present application;
[0068] Figure 4 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application.
[0069] The above drawings illustrate specific embodiments of the present application, which will be described in more detail below. These drawings and the textual description are not intended to limit the scope of the present application in any way, but rather to illustrate the concepts of the present application to those skilled in the art by reference to specific embodiments. DETAILED DESCRIPTION
[0070] Exemplary embodiments will be described in detail herein, with examples illustrated in the accompanying drawings. In the following description, when referring to the drawings, identical numerals in different figures represent identical or similar elements, unless otherwise indicated. The embodiments described in the following exemplary embodiments are not intended to represent all embodiments consistent with the present application. Rather, they are merely examples of apparatus and methods consistent with certain aspects of the present application, as detailed in the appended claims.
[0071] First, let’s explain the terms involved in this application:
[0072] Logback is a logging framework for Java applications. It's an open-source logging component developed and designed by Ceki Gülcü, the creator of the log4j framework. Logback is built on three main classes: the Logger, the Appender, and the Layout. These three components work together, allowing developers to log messages based on message type and level, and to control the output format and destination of messages during runtime. Loggers are responsible for generating logs. When the application starts, the LoggerContext class is responsible for creating Loggers and initializing each Logger's level based on the configuration. Logger level definitions are inherited. If a Logger does not have a defined level, its effective level is taken from the nearest ancestor with a valid level.
[0073] The root configuration (RootLogger) is the common parent of all loggers. By default, the root logger's level is DEBUG. This design ensures that all loggers ultimately achieve a valid level. When the root logger level is set to DEBUG, all loggers that do not explicitly set a log level will output DEBUG or lower logs. This can easily generate a large number of logs in a production environment and cause problems. Therefore, when using Logback's custom configuration, you should explicitly configure the root logger node and set the level to INFO or higher.
[0074] Appender is a component responsible for writing and logging events. Appender must implement the interface ch.qos.logback.core.Appender. Commonly used Appender classes include ConsoleAppender and FileAppender.
[0075] Layout is responsible for converting events into strings. The format() method of the Layout interface takes a parameter representing any type of event and returns a string.
[0076] When conducting software testing, especially performance testing, it's crucial to ensure that the log levels of the application system being tested are consistent with those of the production environment. If these levels are inconsistent, the measured performance data will be inaccurate and offer no useful reference for the subsequent rollout of the tested functionality. Therefore, ensuring the consistency of logs in the test and production environments is a pressing issue.
[0077] In the prior art, the method for checking the consistency of log levels usually adopts manual detection. First, the tester is required to understand the code structure of the system to be tested, the configuration file content and configuration logic, and then manually check whether the log output statement is consistent with the log level set in the configuration.
[0078] However, the existing log level consistency check method requires testers to understand the code structure of the system to be tested as well as the configuration file content and configuration logic, which places high demands on the testers' subjective ability. Moreover, when the test cycle is tight, the testers may easily forget to check the consistency of the log level, resulting in difficulty in ensuring the test quality and unstable test efficiency.
[0079] Based on this, the present application proposes a log level consistency detection method. Since the log level consistency detection method in the prior art is highly dependent on the experience of the tester, the workload is large and prone to errors. With the rapid development of intelligent detection, the structured configuration characteristics and standardized log level definitions of open source log components can be used to distinguish the log files of the test environment and the production environment by file name, and further accurately identify the log level and scope through the configuration file, which is convenient for extraction and comparison. Finally, according to whether the log level settings of the corresponding keywords in the extracted different environments are consistent, for example, whether they are all INFO or WARN, if it is found that the test environment is DEBUG and the production environment is an error (ERROR), it is determined to be inconsistent, and an early warning is generated or recorded in the detection report. Through this method, the consistency detection of the log level configuration of the test environment and the production environment is achieved, the test accuracy is improved, the manual dependence is reduced, and the consistency and controllability of the log behavior in different deployment environments are guaranteed.
[0080] The technical solution of the present application and how the technical solution of the present application solves the above technical problems will be described in detail below with specific embodiments. These several specific embodiments below can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present application will be described below with reference to the accompanying drawings.
[0081] Figure 1 Flow schematic of the log level consistency detection method provided by the embodiments of the present application Figure 1 The method includes:
[0082] S101. Receive the configuration file of the program to be tested.
[0083] Among them, the configuration file is a key file that describes the running parameters, dependencies, paths, ports, database connection information, etc. of the program in different environments (such as testing, production, etc.).
[0084] It should be noted that the program to be tested can be the program to be tested of the Logback open-source logging component.
[0085] It can be understood that receiving the configuration file of the program to be tested is the input preparation stage, providing a basic file for subsequent consistency detection of log files.
[0086] S102. Receive the first keyword representing the test environment and the second keyword representing the production environment input by the user.
[0087] Exemplarily, after receiving the first keyword representing the test environment input by the user, the first keyword can be stored in variable A. Correspondingly, after receiving the second keyword representing the production environment input by the user, the second keyword can be stored in variable B.
[0088] It can be understood that the first keyword is used to identify the configuration characteristics in the test environment; the second keyword is used to identify the configuration characteristics in the production environment; then, the keywords are used as screening and matching conditions to distinguish the configurations of different environments.
[0089] S103. Traverse the configuration file to obtain the target configuration file containing the target keyword.
[0090] Exemplarily, by traversing the configuration file of Logback, find the target configuration file corresponding to the keywords "<logger" and "", so as to perform log consistency detection according to this target configuration file subsequently.
[0091] It can be understood that in this way, the automatic extraction of environment-specific configurations is realized; thus, the workload of manually searching and comparing different configurations is reduced, and the efficiency of consistency detection is improved.
[0092] S104: Based on the target configuration file, the first keyword, and the second keyword, the consistency of the test environment and the production environment is detected to obtain a consistency detection result.
[0093] It can be understood that by performing a consistency check on the log configuration content level based on the extracted target configuration file, the first keyword and the second keyword, if the first keyword and the second keyword do not appear in a pair, it can be regarded as an inconsistency in the test / production environment configuration, thereby obtaining a consistency test result.
[0094] The present application provides a log level consistency detection method. The method includes: first, receiving the configuration file of the program to be tested; then, receiving the first keyword representing the test environment and the second keyword representing the production environment input by the user, ensuring the relevance of the detection range; then, traversing the configuration file to obtain a target configuration file containing the target keyword; finally, based on the target configuration file, the first keyword and the second keyword, the consistency of the test environment and the production environment is detected to obtain a consistency detection result. At this point, by automatically traversing and identifying the configuration content, the time for manually locating the configuration file and content is saved, and the environment is located by keywords, and the log configuration is accurately compared to reduce human omissions or misjudgments. This method effectively solves the pain points of relying on manual labor, low efficiency, and easy omissions in the existing technology by automatically extracting and comparing the log configuration content, improves the accuracy of log detection, and ensures the testing quality of the software.
[0095] Figure 2 Schematic diagram of the log level consistency detection method provided in this application embodiment Figure 2 ,like Figure 2 As shown, this embodiment Figure 2 Based on the embodiment, the process of how to perform consistency detection is described in detail. The method includes:
[0096] S201: Obtain the area content of the first tag area and the attribute value under the second tag in the target configuration file.
[0097] It's understandable that after obtaining the target configuration file, the content can be accurately extracted through fuzzy matching and structural parsing. This involves first obtaining the content of the first tag area in the target configuration file, and then obtaining the attribute values under the second tag. This approach eliminates parsing errors caused by formatting differences such as tag nesting, indentation, and line breaks, improving consistency detection accuracy.
[0098] S202: Determine consistency of specific logger configurations in the test environment and the production environment based on the region content, the first keyword, and the second keyword.
[0099] In one achievable manner, first check whether the first keyword and the second keyword appear in pairs in the region content; if so, determine whether the specific logger configurations in the test environment and the production environment are consistent; if not, generate an alarm message.
[0100] It should be noted that due to the Logback <logger>Tags are used to define a certain type of logger, and its scope is usually limited to a specific package, class name, or module. Therefore, in a multi-environment configuration, to ensure functional consistency and predictable behavior, it is usually required that if the log level of com.example.test is defined as DEBUG in the test environment, the corresponding item should also be explicitly defined in the production environment, even if the levels are different. Therefore, the configuration items should exist in pairs.
[0101] Exemplarily, it can be achieved by obtaining "<logger” and "< / logger> "The content between these two flag fields is used to determine whether the first keyword and the second keyword appear in pair. If they appear in pair, it indicates that the configuration of the specific logger in the test environment and the production environment is consistent. Otherwise, it indicates that there is a configuration missing or unequal problem between the test environment and the production environment, and an alarm information needs to be generated.
[0102] It is understandable that this method can effectively discover configuration "missing" or "asymmetric" problems, reducing the complexity of troubleshooting problems caused by environment switching.
[0103] S203: Determine consistency of the root logger configurations in the test environment and the production environment based on the second tag, the attribute value, the first keyword, and the second keyword.
[0104] In one feasible method, first, when determining whether a conditional statement exists in the first two nodes of the hierarchy where the second label is located, determine whether the conditional statement hits the first keyword or the second keyword; then, if the first keyword is hit, assign the attribute value to the first variable; and if the second keyword is hit, assign the attribute value to the second variable; then, determine whether the contents of the first variable and the second variable are consistent; finally, when the contents of the first variable and the second variable are consistent, determine that the root logger configurations in the test environment and the production environment are consistent; when the contents of the first variable and the second variable are inconsistent, generate an alarm message.
[0105] It should be noted that the first tag area, logger, is mainly used for local configuration and can only control the logging behavior within a certain package name or class name. To further clarify the logging behavior, you also need to use the attribute values under the second tag (root). The second tag can serve as the global default setting.
[0106] It should be understood that after determining that the first keyword and the second keyword appear in pairs based on the regional content, it is necessary to perform consistency detection on the attribute value under the second tag, the first keyword and the second keyword to improve the accuracy of consistency detection of the log file.
[0107] Exemplarily, according to the target configuration file, the content after the attribute value "level=" following the second tag root is extracted into the variable C, and it is determined whether the first keyword or the second keyword is hit in the conditional statement of the first two level nodes of the level where the second tag root is located, so as to determine whether the statement is a test environment or a production environment. If the first keyword is hit, it indicates that it is a test environment, and the attribute value (variable C) is assigned to the first variable (variable D); if the second keyword is hit, it indicates that it is a production environment, and the attribute value (variable C) is assigned to the second variable (variable F); then, it is determined whether the contents of the first variable and the second variable are consistent. If they are consistent, it indicates that the root logger configurations in the test environment and the production environment are consistent. Otherwise, it indicates that the root logger configurations in the test environment and the production environment are inconsistent, and an alarm message needs to be generated.
[0108] It can be understood that this method can accurately identify inconsistencies in log output content or levels in the two environments by respectively detecting whether the area content of the first label area and the attribute value under the second label in the target configuration file are consistent in the test environment and the production environment, thereby providing early warning of potential configuration differences, avoiding the difficulty of troubleshooting online problems caused by missing logs or inconsistent levels, and improving maintainability and stability.
[0109] Optionally, after obtaining the consistency check result, when the consistency check result includes alarm information, the alarm information is written into an alarm log file, and the alarm log file is sent to the user.
[0110] It should be noted that when sending the alarm log file to the user, in order to ensure real-time and security, the alarm log file can be sent to the user via SMTP.
[0111] It is understandable that when it is determined that the root logger configurations in the test environment and the production environment are inconsistent, in order to quickly locate the fault and solve the configuration problem, it is also necessary to write the generated alarm information into the alarm log file, and send the alarm log file to the user via SMTP, so that the user can obtain the alarm log in real time and securely.
[0112] S204: Determine the consistency of the specific logger configuration and the consistency of the root logger configuration as a consistency detection result.
[0113] Figure 3 A structural diagram of a log level consistency detection device provided in an embodiment of the present application; Figure 3 As shown, the device includes:
[0114] The acquisition module 301 is used to receive the configuration file of the program to be tested;
[0115] A receiving module 302 is configured to receive a first keyword representing a test environment and a second keyword representing a production environment input by a user;
[0116] A traversal module 303 is used to traverse the configuration file to obtain a target configuration file containing the target keyword;
[0117] The processing module 304 is configured to detect the consistency between the test environment and the production environment based on the target configuration file, the first keyword, and the second keyword, and obtain a consistency detection result.
[0118] In a possible implementation, the processing module 304 is specifically configured to:
[0119] Get the area content of the first tag area in the target configuration file, and the attribute value under the second tag;
[0120] Determine the consistency of a specific logger configuration in the test environment and the production environment based on the region content, the first keyword, and the second keyword;
[0121] Determining consistency of root logger configurations in the test environment and the production environment based on the second tag, the attribute value, the first keyword, and the second keyword;
[0122] The consistency of the specific logger configuration and the consistency of the root logger configuration are determined as the consistency check result.
[0123] In a possible implementation, the processing module 304 is specifically configured to:
[0124] Check whether the first keyword and the second keyword appear in pairs in the region content;
[0125] If so, make sure that the specific logger configuration is consistent between the test environment and the production environment;
[0126] If not, an alarm message is generated.
[0127] In a possible implementation, the processing module 304 is specifically configured to:
[0128] When determining whether a conditional statement exists in the first two nodes of the level where the second tag is located, determining whether the conditional statement hits the first keyword or the second keyword;
[0129] If the first keyword is hit, the attribute value is assigned to the first variable;
[0130] If the second keyword is hit, the attribute value is assigned to the second variable;
[0131] Determine whether the contents of the first variable and the second variable are consistent;
[0132] When the contents of the first and second variables are consistent, confirm that the root logger configurations in the test environment and the production environment are consistent;
[0133] When the contents of the first variable and the second variable are inconsistent, an alarm message is generated.
[0134] In a possible implementation, the processing module 304 is further configured to:
[0135] When the consistency check result includes alarm information, the alarm information is written to the alarm log file;
[0136] Send the alarm log file to the user.
[0137] In a possible implementation, the processing module 304 is specifically configured to:
[0138] Send warning log files to users via SMTP.
[0139] The log level consistency detection device provided in the embodiment of the present application can execute the method provided in the above method embodiment. Its implementation principle and technical effects are similar, and are not described in detail in this embodiment.
[0140] Figure 4 This is a schematic diagram of the structure of the electronic device provided in the embodiment of the present application. Figure 4 As shown, the electronic device 40 provided in this embodiment includes: at least one processor 401 and a memory 402. Optionally, the device 40 further includes a communication component 403. The processor 401, the memory 402 and the communication component 403 are connected via a bus 404.
[0141] In a specific implementation process, at least one processor 401 executes the computer-executable instructions stored in the memory 402, so that the at least one processor 401 performs the above method.
[0142] The specific implementation process of the processor 401 can be found in the above method embodiment. Its implementation principle and technical effects are similar and will not be repeated here in this embodiment.
[0143] In the above embodiments, it should be understood that the processor may be a central processing unit (CPU), or other general-purpose processors, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), etc. The general-purpose processor may be a microprocessor or any conventional processor. The steps of the method disclosed in the present invention may be directly implemented by a hardware processor or implemented by a combination of hardware and software modules in the processor.
[0144] The memory may include a high-speed memory (Random Access Memory, RAM), and may also include a non-volatile memory (NVM), such as at least one disk memory.
[0145] The bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus. Buses can be divided into address buses, data buses, control buses, etc. For ease of presentation, the buses in the drawings of the embodiments of the present application are not limited to just one bus or just one type of bus.
[0146] An embodiment of the present application also provides a computer program product, including a computer program, which implements the above method when executed by a processor.
[0147] An embodiment of the present application further provides a computer-readable storage medium, in which computer-executable instructions are stored. When the computer-executable instructions are executed, any of the above methods is implemented.
[0148] The above-mentioned readable storage medium can be implemented by any type of volatile or non-volatile memory device or a combination thereof, such as static random-access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk. The readable storage medium can be any available medium that can be accessed by a general-purpose or special-purpose computer.
[0149] An exemplary readable storage medium is coupled to a processor so that the processor can read information from the readable storage medium and write information to the readable storage medium. Of course, the readable storage medium can also be an integral part of the processor. The processor and the readable storage medium can be located in an application specific integrated circuit (ASIC). Of course, the processor and the readable storage medium can also exist in a device as discrete components.
[0150] The division of units is merely a logical functional division; actual implementations may employ alternative divisions, such as combining or integrating multiple units or components into another system, or omitting or disabling certain features. Furthermore, any direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection between devices or units, either through an interface, electrical, mechanical, or other means.
[0151] Units described as separate components may or may not be physically separate, and components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.
[0152] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0153] If the function is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes a number of instructions for enabling a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the various embodiments of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), magnetic disk or optical disk, and other media that can store program code.
[0154] Those skilled in the art will appreciate that all or part of the steps in the above-described method embodiments can be implemented using hardware associated with program instructions. The aforementioned program can be stored in a computer-readable storage medium. When executed, the program performs the steps of the above-described method embodiments. The aforementioned storage medium includes various media capable of storing program code, such as ROM, RAM, magnetic disks, or optical disks.
[0155] Finally, it should be noted that those skilled in the art will readily identify other embodiments of the present invention after considering the specification and practicing the invention disclosed herein. The present invention is intended to cover any variations, uses, or adaptations of the present invention that follow the general principles of the present invention and include common knowledge or customary techniques in the art not disclosed herein. The present invention is not limited to the precise structure described above and illustrated in the accompanying drawings, and various modifications and variations may be made without departing from the scope thereof. The scope of the present invention is limited solely by the appended claims.
Claims
1. A log level consistency detection method, characterized in that: The method comprises: Receive the configuration file of the program to be tested; receiving a first keyword representing a test environment and a second keyword representing a production environment input by a user; Traversing the configuration files to obtain a target configuration file containing a target keyword; Based on the target configuration file, the first keyword, and the second keyword, consistency between the test environment and the production environment is detected to obtain a consistency detection result.
2. The method according to claim 1, characterized in that The detecting consistency between the test environment and the production environment based on the target configuration file, the first keyword, and the second keyword to obtain a consistency detection result includes: Obtaining the area content of the first tag area and the attribute value under the second tag in the target configuration file; Determining consistency of specific logger configurations in the test environment and the production environment based on the area content, the first keyword, and the second keyword; Determining consistency of root logger configurations in the test environment and the production environment based on the second tag, the attribute value, the first keyword, and the second keyword; The consistency of the specific logger configuration and the consistency of the root logger configuration are determined as the consistency detection result.
3. The method according to claim 2, characterized in that The determining, based on the area content, the first keyword, and the second keyword, consistency of the specific logger configurations in the test environment and the production environment includes: Checking whether the first keyword and the second keyword appear in pairs in the regional content; If so, determining that the specific logger configurations in the test environment and the production environment are consistent; If not, an alarm message is generated.
4. The method according to claim 2, characterized in that The determining, according to the second tag, the attribute value, the first keyword, and the second keyword, consistency of the root logger configurations in the test environment and the production environment includes: When determining that a conditional statement exists in the first two nodes of the level where the second tag is located, determining whether the conditional statement hits the first keyword or the second keyword; If the first keyword is hit, assign the attribute value to the first variable; If the second keyword is hit, assigning the attribute value to the second variable; Determining whether the contents of the first variable and the second variable are consistent; When the contents of the first variable and the second variable are consistent, determining that the root logger configurations in the test environment and the production environment are consistent; When the contents of the first variable and the second variable are inconsistent, an alarm message is generated.
5. The method according to claim 3 or 4, characterized in that After obtaining the consistency test result, the method further includes: When the consistency check result includes the alarm information, writing the alarm information into an alarm log file; Send the alarm log file to the user.
6. The method according to claim 5, characterized in that The sending of the alarm log file to the user includes: The warning log file is sent to the user via the Simple Mail Transfer Protocol (SMTP).
7. A log level consistency detection device, characterized in that: include: The acquisition module is used to receive the configuration file of the program to be tested; A receiving module, configured to receive a first keyword representing a test environment and a second keyword representing a production environment input by a user; A traversal module, configured to traverse the configuration file to obtain a target configuration file containing a target keyword; A processing module is used to detect the consistency of the test environment and the production environment based on the target configuration file, the first keyword and the second keyword to obtain a consistency detection result.
8. An electronic device, characterized in that: include: Memory, processor; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory, so that the processor performs the method according to any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that The computer-readable storage medium stores computer-executable instructions, which are used to implement the method according to any one of claims 1 to 6 when executed.
10. A computer program product, characterized in that The method comprises a computer program, which implements the method according to any one of claims 1 to 6 when the computer program is executed.