Log acquisition method and device, computer device, and storage medium
By obtaining log types and query strategies, system and component logs are categorized and processed. Target logs are generated using delimiters and filter items, solving the problem of complex log searching and improving testing efficiency and accuracy.
Patent Information
- Application Number
- CN202310449569.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-04-24
- Publication Date
- 2025-12-05
- Estimated Expiration
- 2043-04-24
AI Technical Summary
During testing, the different storage locations and formats of logs generated by various systems and devices make log searching complex, affecting analysis efficiency and even requiring repeated testing, thus slowing down project progress.
By obtaining the log type, formatting method, and query strategy, the target logs are accurately obtained, including system-type and component-type logs. The logs are formatted using delimiters and filter items to generate logs that conform to the target structure.
It improved the accuracy and readability of log acquisition, reduced repetitive work, shortened project development time, and increased development efficiency.
Smart Images

Figure CN116483794B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computer, in particular to a log acquisition method and device, a computer device and a storage medium. BACKGROUND
[0002] The log is a very important basis for analyzing problems encountered in testing. When the system or device used in testing is more, the storage location and storage form of the log may be different, and it is extremely complex to find the problem from the log. The query of the problem log is the key to solving the problem. If the log is not clear, it will cause analysis blockage, and even need to retest to reproduce the problem, which causes repeated labor and prolongs the project time. Therefore, how to accurately acquire the required log from the various and massive logs has been a big problem that has plagued the project progress. SUMMARY
[0003] Therefore, the embodiments of the present application provide a log acquisition method and device, a computer device and a storage medium to solve the problem that the log is difficult to accurately acquire.
[0004] In a first aspect, the embodiments of the present application provide a log acquisition method, comprising:
[0005] acquiring a log type of a log to be queried, a log formatting manner corresponding to the log type and a target log structure;
[0006] determining a log query strategy corresponding to the log type and a log query position corresponding to the log query strategy according to the log type;
[0007] acquiring a first log from the log query position according to the log query strategy;
[0008] performing first formatting processing on the first log according to the log formatting manner to acquire a second log;
[0009] performing second formatting processing on the second log according to the target log structure to acquire a target log.
[0010] In this way, the log type of the log to be queried, the log formatting manner corresponding to the log type, and the target log structure are acquired; the log query strategy corresponding to the log type and the log query position corresponding to the log query strategy are determined according to the log type; the first log is acquired from the log query position according to the log query strategy; the first log is subjected to first formatting processing according to the log formatting manner, and the second log is acquired; and the second log is subjected to second formatting processing according to the target log structure, and the target log is acquired. The corresponding log query strategy and log query position can be determined according to the log type, and then the formatting processing is performed according to the requirement, and finally the accurate and usable log can be generated according to the self-defined format, which provides a convenient log acquisition method for various log types generated in the test work, improves the readability of the log by formatting processing, has a wide application range, is flexible to use, can be customized according to the log type, and greatly improves the development efficiency of the project.
[0011] In combination with the first aspect, in an implementation manner, the log type includes a first log type and a second log type, the first log type is a system class log type, and the second log type is a component class log type.
[0012] In this way, the log type is classified according to the system class log type and the component class log type, the great difference between the two log types can be considered, and the log information required can be more easily acquired by adopting the manner suitable for the log type.
[0013] In combination with the first aspect or the corresponding implementation manner thereof, in an implementation manner, when the log type is the first log type, the log query strategy includes a first query instruction set, a query period, and a query number, and the first log is acquired from the log query position according to the log query strategy, including:
[0014] The query instruction in the first query instruction set is run according to the query period, and the log information is queried from the log query position;
[0015] When the number of times that the query instruction in the first query instruction set is run according to the query period satisfies the query number, the first log is generated according to the log information acquired according to all the query periods.
[0016] In this way, when the log type is the first log type, that is, the system class log, the query period and the query number are set according to the characteristics of the system class log, the log can be cyclically queried according to the set query period and query number in the test process, and thus the required log can be acquired throughout, and the integrity of the acquired log is ensured.
[0017] In an implementation, the log formatting manner includes a separator and a filtering item corresponding to the log type, the first log is first formatted according to the log formatting manner, the second log is obtained, and the method includes the following steps:
[0018] The separator is searched from the first log;
[0019] After the separator in the first log is converted into a preset target separator, the third log is generated;
[0020] The third log is filtered according to the filtering item to obtain the second log.
[0021] In this way, the separator is converted into a unified preset target separator, and the filtering item is used for filtering, so that the log can be uniformly formatted, and the log information that is not needed is filtered out, only the useful log information is retained, the staff can conveniently check the log to locate the problem, time is saved, and work efficiency is greatly improved.
[0022] In an implementation, when the log type is a second log type, the log query strategy includes a second query instruction set, the first log is obtained from the log query location according to the log query strategy, and the method includes the following steps:
[0023] Each query instruction in the second query instruction set is executed in sequence to determine component information corresponding to the second query instruction set;
[0024] The log query tool corresponding to the component information is searched according to the component information;
[0025] The first log is obtained from the log query location by using the log query tool.
[0026] In this way, when the log type is a second log type, that is, a component log, according to the characteristics of the component log, the specific component information is queried by using the second query instruction set, the corresponding query tool is searched according to the component information, and then the first log is obtained from the log query location by using the query tool, so that the required log of the component log can be matched, and the method is very suitable for the scenario of the component log.
[0027] In an implementation, the query instruction in the second query instruction set includes one or more of the following:
[0028] A device component number query instruction, a device name query instruction, and a device identity number query instruction.
[0029] In this way, the component information can be queried according to one or more of the device component number query instruction, the device name query instruction and the device identity number, and the required component information can be matched more easily.
[0030] With reference to the first aspect or the corresponding implementation thereof, in an implementation, the second log is subjected to a second formatting processing according to the target log structure to obtain the target log, including:
[0031] The field information in the target log structure is extracted.
[0032] The second log is filtered according to the field information to obtain the target log.
[0033] In this way, the second log can be filtered according to the field information in the target log structure, which is equivalent to a second formatting processing, and has a better customization effect.
[0034] In a second aspect, an embodiment of the present application provides a log obtaining device, including an obtaining module, a determining module, a processing module, a first formatting processing module and a second formatting processing module.
[0035] The obtaining module is configured to obtain a log type of a log to be queried, a log formatting manner corresponding to the log type and a target log structure.
[0036] The determining module is configured to determine a log query strategy corresponding to the log type and a log query position corresponding to the log query strategy according to the log type.
[0037] The processing module is configured to obtain a first log from the log query position according to the log query strategy.
[0038] The first formatting processing module is configured to perform a first formatting processing on the first log according to the log formatting manner to obtain a second log.
[0039] The second formatting processing module is configured to perform a second formatting processing on the second log according to the target log structure to obtain a target log.
[0040] Optionally, the log type in the obtaining module includes a first log type and a second log type, the first log type is a system log type, and the second log type is a component log type.
[0041] Optionally, when the log type is the first log type, the processing module includes a running unit and a processing unit.
[0042] The running unit is configured to run a query instruction in a first query instruction set according to a query period to query log information from the log query position.
[0043] The processing unit is configured to generate a first log based on log information obtained in all query periods when a number of times of executing a query instruction in the first query instruction set according to a query period meets a query number.
[0044] Optionally, the first formatting processing module comprises a first searching unit, a converting unit and a filtering unit.
[0045] The first searching unit is configured to search for a separator from the first log.
[0046] The converting unit is configured to convert the separator in the first log into a preset target separator to generate a third log.
[0047] The filtering unit is configured to filter the third log according to a filtering item to obtain a second log.
[0048] Optionally, when the log type is the second log type, the processing module comprises an executing unit, a second searching unit and a log obtaining unit.
[0049] The executing unit is configured to execute each query instruction in a second query instruction set in sequence to determine component information corresponding to the second query instruction set.
[0050] The second searching unit is configured to search for a log query tool corresponding to the component information according to the component information.
[0051] The log obtaining unit is configured to obtain the first log from a log query position by using the log query tool.
[0052] Optionally, the query instruction in the second query instruction set in the executing unit comprises one or more of the following:
[0053] A device component number query instruction, a device name query instruction and a device identity number query instruction.
[0054] Optionally, the second formatting processing module comprises an extracting unit and a screening unit.
[0055] The extracting unit is configured to extract field information in a target log structure.
[0056] The screening unit is configured to screen the second log according to the field information to obtain a target log.
[0057] In a third aspect, an embodiment of the present application provides a computer device, which comprises a memory and a processor, the memory and the processor are communicatively connected, the memory stores computer instructions, and the processor executes the computer instructions to execute the log obtaining method in the first aspect or any of the corresponding embodiments.
[0058] In a fourth aspect, an embodiment of the present application provides a computer readable storage medium, which stores computer instructions for causing a computer to execute the log acquisition method of the first aspect or any of the corresponding embodiments. BRIEF DESCRIPTION OF DRAWINGS
[0059] In order to more clearly illustrate the specific embodiments of the present application or the technical solutions in the prior art, the drawings needed in the specific embodiments or prior art description will be briefly introduced as follows. Obviously, the drawings in the following description are some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative labor on the basis of these drawings.
[0060] Figure 1 is a flowchart of a log acquisition method according to some embodiments of the present application;
[0061] Figure 2 is a flowchart of another log acquisition method according to some embodiments of the present application;
[0062] Figure 3 is a flowchart of still another log acquisition method according to some embodiments of the present application;
[0063] Figure 4 is a flowchart of still another log acquisition method according to some embodiments of the present application;
[0064] Figure 5 is a flowchart of still another log acquisition method according to some embodiments of the present application;
[0065] Figure 6 is a structural block diagram of a log acquisition device according to an embodiment of the present application;
[0066] Figure 7 is a hardware structure diagram of a computer device according to an embodiment of the present application. DETAILED DESCRIPTION
[0067] In order to make the purpose, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be described clearly and completely with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are some of the embodiments of the present application, but not all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative labor fall within the scope of protection of the present application.
[0068] In the test process of a storage device or a server, a log is a very important basis for analyzing problems encountered by the test. In the test process of some test projects, especially large and complex projects, many devices or systems are often used, and the logs generated by the devices or systems are different in format, storage location and even form. For example, a server includes system logs, baseboard management controller (BMC) logs and various component logs, and the output log tools and extraction methods in the test process are also different, so that the collection of the logs becomes particularly complex and the development cycle is long. If the useful information in the logs cannot be well extracted, the analysis will be blocked, and even repeated tests are needed to reproduce the problem, which leads to repeated work, prolongs the test time and further delays the project progress.
[0069] Based on this, the present application provides a log acquisition method, which determines the log acquisition strategy, log query location and the like corresponding to the log type through the log type, and performs formatting processing through setting the log formatting mode, such as a separator, a filter item and a target log structure, so as to accurately acquire the required logs and output them after formatting processing, so that the staff can view the required logs at a glance, and the project progress is greatly improved.
[0070] According to the embodiments of the present application, a log acquisition method embodiment is provided. It should be noted that the steps shown in the flowchart of the drawings can be executed in a computer system such as a group of computer executable instructions, and although the logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0071] In the present embodiment, a log acquisition method is provided, which can be used in the above-mentioned computer device, Figure 1 is a flowchart of the log acquisition method according to the embodiments of the present application, as Figure 1 shown, the flow includes the following steps:
[0072] In step S101, the log type of the log to be queried, the log formatting mode corresponding to the log type and the target log structure are acquired.
[0073] Specifically, before acquiring the log type of the log to be queried, the log source structure can be defined first, including the definition of the log type, the log formatting mode and the target log structure. The defined log type, log formatting mode and target log structure are stored in a preset storage location, such as a configuration file. At the beginning of the test, the contents in the configuration file are read to a suitable reading position, such as the memory, and the log type to be queried in the test, the log formatting mode corresponding to the log type and the target log structure are acquired from the memory.
[0074] In an optional example, the log formatting manner can include a log query manner, a log filtering manner, etc., and the target log structure can be a field type, field information, etc. defined according to actual needs, such as an alarm information field or an error information field, which can be defined according to actual conditions.
[0075] In a specific embodiment, the log source structure can include {source serial number, log major category, subcategory, model part number (PN), system-under device name, part ID, query instruction set, tool name, log separator, filtering item, execution frequency, period}, and the customized format structure includes {source serial number, field display order, field name, Chinese translation}. The source serial number is the number of the log source of different types of logs, the log major category and the log subcategory can be used as the classification of the log type, the log major category can be divided by system or part level, and the log subcategory is the subcategory under the major category, for example, the major category is a part, and the subcategory is all specific parts. The model PN, the system-under device name, and the part ID are the information of all parts to be queried in the part log, the query instruction set is the query instruction set corresponding to the log type, which can be a query command or a filtering command, etc., the tool name is the query tool corresponding to each part in the part log type, in general, the part has its own query tool for log query, the log separator is the log separator of the log itself generated by different log types in the test process, the filtering item is the filtering item corresponding to the log type, and the execution frequency and the period are applicable to the case where the log is generated periodically in the test process, and the execution frequency and the period can be set according to the period of generating the log in the test process. The customized format structure is the target format structure, which is a customized field, field information, or Chinese translation of the field name or field information, for example, the log source serial number can be matched, the field order can be defined, and the field name can be translated into Chinese, and the specific customized format can be defined according to actual needs, which is only used as an example here.
[0076] Step S102, determining the log query strategy corresponding to the log type and the log query location corresponding to the log query strategy according to the log type.
[0077] Specifically, each log type has a corresponding log query strategy and a log query location corresponding to the log query strategy, the log query strategy can be a query instruction, a query period, a query format, etc., and the log storage location is determined according to the system type, for example, the log storage location of the server system BMC, the log storage location of the operating system (OS), or the log storage location specific to each part device.
[0078] Step S103, acquiring the first log from the log query location according to the log query strategy.
[0079] Specifically, according to the query mode included in the log query strategy, the first log is obtained from the corresponding log query location.
[0080] In an optional example, for example, the OS log is queried, and according to the log query strategy corresponding to the OS log type, the log is obtained in cycles according to the query instruction, the query period and the like in the log query strategy, and the log obtained in each cycle constitutes the first log, that is, the log obtained through the log query strategy.
[0081] In some optional embodiments, before the log is queried, the stored log in the log query location can be cleaned to ensure that the queried log is the log generated during the execution of the current project.
[0082] Step S104, the first log is first formatted according to the log formatting mode to obtain the second log.
[0083] Specifically, the log formatting mode is a log formatting mode corresponding to the log type, such as symbol conversion, character filtering, field filtering and the like, and the first log obtained is first formatted according to the log formatting mode to obtain the second log.
[0084] Step S105, the second log is second formatted according to the target log structure to obtain the target log.
[0085] Specifically, on the basis of the first formatting processing, the second formatting processing is performed according to the form of the target log structure, and the log in the target format is output, the target log structure is a customizable structure form, for example, a self-defined field name, a self-defined required log field, or a self-defined field format conversion, and finally output is a log form conforming to the target log structure.
[0086] The log acquisition method provided in this embodiment obtains the log type, the corresponding log formatting method, and the target log structure of the log to be queried; determines the log query strategy and the corresponding log query position based on the log type; retrieves the first log from the log query position according to the log query strategy; performs a first formatting process on the first log according to the log formatting method to obtain the second log; and performs a second formatting process on the second log according to the target log structure to obtain the target log. This method allows for determining the corresponding log query strategy and log query position based on the log type, and then performing formatting processing according to requirements. Ultimately, it can generate accurate and usable logs based on a custom format, providing a convenient log acquisition method for the diverse log types generated in testing work. The formatting processing also improves log readability, has a wide range of applications, is flexible in use, and can be customized according to log type, greatly improving project development efficiency.
[0087] In some optional implementations, the log type includes a first log type and a second log type, wherein the first log type is a system-class log type and the second log type is a component-class log type.
[0088] Specifically, system logs refer to logs related to the server system, such as OS logs and BMC logs. Component logs refer to logs of specific devices and components, such as hard drives, Redundant Array of Independent Disks (RAID), power supplies, fans, etc. Each component may have different model numbers or batch numbers and other identifying information.
[0089] System logs are characterized by generating logs cyclically as testing progresses, while component logs are generated only once. Different log retrieval methods can be developed based on these differences. Categorizing logs into system and component types takes into account these significant differences, allowing for the adoption of appropriate processing methods and facilitating the retrieval of necessary log information.
[0090] This embodiment provides a log acquisition method, which can be used in the aforementioned computer device. Figure 2 This is a flowchart of a log acquisition method according to an embodiment of the present invention, such as... Figure 2 As shown, the process includes the following steps:
[0091] Step S201: Obtain the log type, the corresponding log formatting method, and the target log structure of the log to be queried. For details, please refer to [link to relevant documentation]. Figure 1 Step S101 of the illustrated embodiment will not be described again here.
[0092] In step S202, a log query strategy corresponding to the log type and a log query location corresponding to the log query strategy are determined according to the log type. For details, please refer to Figure 1 In step S102 of the embodiment shown in FIG. 1, no further description is given here.
[0093] In step S203, the first log is obtained from the log query location according to the log query strategy.
[0094] Specifically, when the log type is the first log type, the log query strategy includes a first query instruction set, a query period, and a query number, and the step S203 includes:
[0095] In step S2031, the query instructions in the first query instruction set are executed according to the query period, and log information is queried from the log query location.
[0096] Specifically, the system log type is characterized by periodic generation of logs, the first query instruction set can be a query command, which can be one or more, and the query period can be set according to the log generation period. In each query period, all query instructions in the first query instruction set are executed to query log information from the log query location (which can be a log storage location).
[0097] In an optional example, for example, querying the OS log, the query period is set to 30 seconds, and the first query instruction set includes two query instructions. Then, the two query instructions are executed every 30 seconds to query log information from the log query location.
[0098] In step S2032, when the number of times of executing the query instructions in the first query instruction set according to the query period meets the query number, the first log is generated according to the log information obtained in all query periods.
[0099] Specifically, the query number can also be set, and the query instructions are periodically executed according to the query number. When the query number is met, the execution is stopped, and the first log is generated according to the log information obtained in all query periods.
[0100] In an optional embodiment, the log information obtained each time can be stored in a fixed location, such as a pre-configured log file, in an incremental reading manner, and the log file can be named in a fixed format.
[0101] In step S204, the first log is first formatted according to a log formatting manner to obtain a second log. For details, please refer to Figure 1 In step S104 of the embodiment shown in FIG. 1, no further description is given here.
[0102] Step S205: Perform second formatting on the second log according to the target log structure to obtain the target log. For details, please refer to [link to relevant documentation]. Figure 1 Step S105 of the illustrated embodiment will not be described again here.
[0103] In this way, when the log type is the first log type, i.e. system log, the query cycle and number of queries can be set according to the characteristics of system logs. During the test, the log can be queried in a loop according to the set query cycle and number of queries, so as to obtain the required logs throughout the process and ensure the integrity of the obtained logs.
[0104] This embodiment provides a log acquisition method, which can be used in the aforementioned computer device. Figure 3 This is a flowchart of a log acquisition method according to an embodiment of the present invention, such as... Figure 3 As shown, the process includes the following steps:
[0105] Step S301: Obtain the log type, the corresponding log formatting method, and the target log structure of the log to be queried. For details, please refer to [link to relevant documentation]. Figure 1 Step S101 of the illustrated embodiment will not be described again here.
[0106] Step S302: Determine the log query strategy corresponding to the log type and the log query location corresponding to the log query strategy based on the log type. For details, please refer to [link to details]. Figure 1 Step S102 of the illustrated embodiment will not be described again here.
[0107] Step S303: Retrieve the first log from the log query location according to the log query strategy. For details, please refer to [link to details]. Figure 1 Step S103 of the illustrated embodiment will not be described again here.
[0108] Step S304: Perform first formatting on the first log according to the log formatting method to obtain the second log.
[0109] Specifically, the log formatting method includes delimiters and filter items corresponding to the log type. Step S304 includes:
[0110] Step S3041: Search for the delimiter in the first log.
[0111] Specifically, for example, if the delimiter corresponding to the first log type is a comma, then the comma will be searched for in the first log. The delimiter configuration here should be consistent with the actual delimiter in the log, for subsequent unified formatting of the log.
[0112] Step S3042: After converting the delimiter in the first log to a preset target delimiter, the third log is generated.
[0113] Specifically, the separators in the first log are converted into preset target separators, for example, all separators such as commas are converted into vertical bars “|”, and the converted log is generated as a third log.
[0114] In step S3043, the third log is filtered according to the filter item to obtain a second log.
[0115] Specifically, the third log is filtered according to the filter item, for example, the staff does not need to obtain the log of the error type “error”, and the filter item can be set as the log filter item “error” to filter out all “error” log information in the third log, so as to obtain the second log.
[0116] It should be noted that the separators and filter items described above are only examples, and the specific settings can be determined according to actual conditions, and are not limited here.
[0117] In step S305, the second log is subjected to a second formatting process according to the target log structure to obtain a target log. For details, please refer to Figure 1 The step S105 of the embodiment shown in FIG. 1 is not repeated here.
[0118] In this way, the separators are converted into uniform preset target separators, and the filter item is filtered, so that the log can be uniformly formatted, and the unnecessary log information is filtered out by the filter item, only the useful log information is retained, which is convenient for the staff to check the log to locate the problem, saves time, and improves the project progress.
[0119] In this embodiment, a log acquisition method is provided, which can be used for the computer device described above, Figure 4 is a flowchart of the log acquisition method according to an embodiment of the present application, as shown in Figure 4 The flowchart includes the following steps:
[0120] In step S401, the log type of the log to be queried, the log formatting mode corresponding to the log type, and the target log structure are obtained. For details, please refer to Figure 1 The step S101 of the embodiment shown in FIG. 1 is not repeated here.
[0121] In step S402, the log query strategy corresponding to the log type and the log query position corresponding to the log query strategy are determined according to the log type. For details, please refer to Figure 1 The step S102 of the embodiment shown in FIG. 1 is not repeated here.
[0122] In step S403, the first log is obtained from the log query position according to the log query strategy.
[0123] Specifically, when the log type is the second log type, the log query strategy includes a second query instruction set, and the step S403 includes:
[0124] In step S4031, each query instruction in the second query instruction set is executed in sequence to determine the component information corresponding to the second query instruction set.
[0125] Specifically, the query instruction in the second query instruction set is a component class query instruction, which includes one or more query instructions for querying specific component information, such as an identification number, a batch number, and the like.
[0126] In some optional embodiments, for example, during testing, the memory loads all component information, and then according to all query instructions in the second query instruction set, the component information corresponding to the second query instruction set is queried from all component information in the memory.
[0127] In step S4032, the log query tool corresponding to the component information is found according to the component information.
[0128] Specifically, each component corresponds to its own query tool, and the log query tool corresponding to the component information can be determined according to the component information.
[0129] In an optional example, for example, the component is a disk array of model A, and the log query tool of the disk array is determined according to the model of the disk array.
[0130] In step S4033, the first log is obtained from the log query position by using the log query tool.
[0131] Specifically, the first log is obtained from the log query position, i.e., the log storage position of the component, by using the log query tool of the component itself.
[0132] In step S404, the first log is first formatted according to a log formatting manner to obtain a second log. For details, refer to Figure 1 The step S104 of the embodiment shown in
[0133] In step S405, the second log is second formatted according to a target log structure to obtain a target log. For details, refer to Figure 1 The step S105 of the embodiment shown in
[0134] In this way, when the log type is the second log type, i.e., the component class log, according to the characteristics of the component class log, the specific component information is queried by using the second query instruction set, and then the corresponding query tool is found according to the component information, and then the first log is obtained from the log query position by using the query tool, so that the required log of the component class log can be matched, which is very suitable for the scenario of the component class log.
[0135] In some optional embodiments, the query instruction in the second query instruction set in step S4031 comprises one or more of the following:
[0136] The device component number query instruction, the device name query instruction, and the device identity number query instruction.
[0137] Specifically, the device component number query instruction, for example, the component number PN query instruction, is used to query the component through the component PN code, the device name is a specific device component name, which is used to query the component through the device name, and the device identity number is the component identity number (ID), which is used to query the component through the component ID.
[0138] In an optional example, a unique component can be queried through one, two, or three of the above query instructions, for example, a unique component can be determined through the device component number query instruction and the device name query instruction, or the three query instructions can be used for querying.
[0139] In some optional embodiments, step S105 comprises the following method steps:
[0140] Step a1, extracting field information in the target log structure.
[0141] Specifically, the target log structure contains the field information required by the target log, such as {source serial number, field display order, field name}, etc. The field information is extracted.
[0142] Step a2, filtering the second log according to the field information to obtain the target log.
[0143] Then, the required fields are filtered from the second log according to the field information to form the target log. The field display order, field translation method, etc. can also be set, which can be determined according to actual needs.
[0144] In this way, the second log can be filtered according to the field information in the target log structure, which is equivalent to a secondary formatting process, and has better customization effect.
[0145] In a specific embodiment, for example, in an automated testing scenario, it is necessary to customize the log in the automated testing process and output the standard log. The log output in the automated testing process includes system class logs and component class logs. The specific log acquisition method in the automated testing process is as follows: Figure 5As shown, before the test starts, a log program can be developed and a configuration file can be set in the log program to configure the type of customized log, log query strategy, etc. A configured log source structure can be {source serial number, log category (including system category and component category), subcategory (e.g., subcategory under the system, such as OS, BMC, etc.), component model PN, component device name, component ID (which can be further classified here, e.g., the component has multiple IDs, and multiple IDs can be configured for joint query of component ID, such as Vendor Identification (VID), Device Identification (DID), Subsystem Identification (SID), and Revision Identification (RID)), query instruction set, component tool name, log separator, filter item, execution times, and period}. The customized format structure, i.e., the target log structure, includes {source serial number, field display order, field name, and Chinese translation}. The source serial number is used to associate the source serial number of the log source structure to determine the log source. The field display order is used to define the display order of the fields. The field name is used to filter the required field information. The Chinese translation can define the conversion of the field name in other formats to the required field name format, such as Chinese format or a format that is more consistent with the actual meaning of the field information.
[0146] After the log program is uploaded to the device to be tested, the log program is started. Figure 5 In the middle, the log source structure of the configuration file is constructed in the memory, and the configured log items in the configuration file are loaded into the memory.
[0147] At the start of the test, a start instruction is sent to the log program, the log program is started, and multiple threads are created according to the log classification. For example, system category logs can create a thread for each log subcategory according to the log subcategory. The required configuration is extracted from the memory, the log query strategy (query instruction set, log separator, filter item, etc.) corresponding to the log subcategory, execution times, period, and customized format structure (target log structure) are extracted from the memory. According to the execution times, the cycle is set, the query instruction set is split according to the specified period interval, the instruction is executed in a loop, the query result can be obtained in an incremental reading manner, then the query result is converted to a unified format according to the separator, the log is cleaned and filtered according to the filter item to filter out unnecessary log information, and then the required fields are obtained according to the customized format structure to output the target log.
[0148] It should be noted that if the execution times is 1, the query result can be read in full in one query, and if the execution times is N, the query is performed N times according to the set period, and the query result is obtained in increments N times. N is a positive integer greater than 1.
[0149] For component class log, at startup, the memory loads all component information, and loads the required configurations of log query strategy, separator, filter item, etc. The query instruction set of the component class queries the component information, splits the query instruction set to query the component, and compares with the component information in the memory. If there is no matching item, the thread exits and does not perform log query. When all query instructions are executed and the required component is queried, the log tool corresponding to the component is found according to the component, the log tool is executed, the log file is obtained, and then the separator is converted into a unified format, the log is filtered and cleaned according to the filter item, and finally the log is output in the customized format structure, for example, it can be in the form of big class + fine class + date.log and stored in a specified location.
[0150] At the end of the test, a stop instruction is sent to the log program. For system class log, the thread is released after the current cycle ends. For component class log, which is one-time log, the thread is ended after the thread processing is completed to prevent incomplete log acquisition.
[0151] The process of the log program is resident in the memory, and the process can be released by a command or by restarting the computer device.
[0152] The embodiment also provides a log acquisition device for implementing the above embodiments and preferred embodiments, which has been described above. As used below, the term "module" can be a combination of software and / or hardware that implements a predetermined function. Although the device described in the following embodiments is preferably implemented in software, hardware or a combination of software and hardware is also possible and is contemplated.
[0153] The embodiment provides a log acquisition device, as shown in Figure 6 The device includes an acquisition module 601, a determination module 602, a processing module 603, a first formatting processing module 604, and a second formatting processing module 605.
[0154] The acquisition module 601 is configured to acquire a log type of a log to be queried, a log formatting manner corresponding to the log type, and a target log structure.
[0155] The determination module 602 is configured to determine a log query strategy corresponding to the log type and a log query position corresponding to the log query strategy according to the log type.
[0156] The processing module 603 is configured to acquire a first log from the log query position according to the log query strategy.
[0157] The first formatting processing module 604 is configured to perform first formatting processing on the first log according to the log formatting manner to acquire a second log.
[0158] The second formatting processing module 605 is configured to perform second formatting processing on the second log according to a target log structure, and obtain a target log.
[0159] In some optional embodiments, the log types in the obtaining module 601 include a first log type and a second log type, the first log type is a system type, and the second log type is a component type.
[0160] In some optional embodiments, when the log type is the first log type, the processing module includes a running unit and a processing unit.
[0161] The running unit is configured to run a query instruction in the first query instruction set according to a query period, and query log information from a log query location.
[0162] The processing unit is configured to generate the first log according to log information obtained in all query periods when a number of times of running the query instruction in the first query instruction set according to the query period meets a query number.
[0163] In some optional embodiments, the first formatting processing module 604 includes a first searching unit, a converting unit and a filtering unit.
[0164] The first searching unit is configured to search for a separator in the first log.
[0165] The converting unit is configured to convert the separator in the first log into a preset target separator, and generate a third log.
[0166] The filtering unit is configured to filter the third log according to a filtering item, and obtain the second log.
[0167] In some optional embodiments, the processing module 603 includes an executing unit, a second searching unit and a log obtaining unit.
[0168] The executing unit is configured to sequentially execute each query instruction in the second query instruction set, and determine component information corresponding to the second query instruction set.
[0169] The second searching unit is configured to search for a log query tool corresponding to the component information according to the component information.
[0170] The log obtaining unit is configured to obtain the first log from the log query location by using the log query tool.
[0171] In some optional embodiments, the query instruction in the second query instruction set in the executing unit includes one or more of the following:
[0172] A device component number query instruction, a device name query instruction and a device identity number query instruction.
[0173] In some optional implementations, the second formatting processing module includes: an extraction unit and a filtering unit;
[0174] The extraction unit is used to extract field information from the target log structure.
[0175] The filtering unit is used to filter the second log according to field information to obtain the target log.
[0176] In this embodiment, the log acquisition device is presented in the form of a functional unit. Here, a unit refers to an ASIC circuit, a processor and memory that execute one or more software or fixed programs, and / or other devices that can provide the above functions.
[0177] Further functional descriptions of the above modules and units are the same as those in the corresponding embodiments described above, and will not be repeated here.
[0178] This invention also provides a computer device having the above-described features. Figure 6 The log acquisition device shown.
[0179] Please see Figure 7 , Figure 7 This is a schematic diagram of the structure of a computer device provided in an optional embodiment of the present invention, such as... Figure 7 As shown, the computer device includes one or more processors 10, memory 20, and interfaces for connecting the components, including high-speed interfaces and low-speed interfaces. The components communicate with each other via different buses and can be mounted on a common motherboard or otherwise installed as needed. The processors can process instructions executed within the computer device, including instructions stored in or on memory to display graphical information of a GUI on external input / output devices (such as display devices coupled to the interfaces). In some alternative implementations, multiple processors and / or multiple buses can be used with multiple memories and multiple memory modules, if desired. Similarly, multiple computer devices can be connected, each providing some of the necessary operations (e.g., as a server array, a group of blade servers, or a multiprocessor system). Figure 7 Take a processor 10 as an example.
[0180] Processor 10 may be a central processing unit, a network processor, or a combination thereof. Processor 10 may further include a hardware chip. The hardware chip may be an application-specific integrated circuit (ASIC), a programmable logic device (PLD), or a combination thereof. The programmable logic device may be a complex programmable logic device (CAMP), a field-programmable gate array (FPGA), a general-purpose array logic (GDA), or any combination thereof.
[0181] The memory 20 stores instructions executable by the at least one processor 10 to cause the at least one processor 10 to perform the method illustrated in the above embodiments.
[0182] The memory 20 can include a program storage area and a data storage area. The program storage area can store an operating system and application programs required by at least one function. The data storage area can store data created by the use of the computer device according to the presentation of the applet landing page, and the like. In addition, the memory 20 can include a high-speed random access memory, and can also include a non-transitory memory, such as at least one magnetic disk storage device, a flash memory device, or other non-transitory solid-state memory device. In some optional embodiments, the memory 20 can optionally include a memory disposed remotely with respect to the processor 10, and these remote memories can be connected to the computer device through a network. Examples of the network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and a combination thereof.
[0183] The memory 20 can include a volatile memory, such as a random access memory; the memory can also include a non-volatile memory, such as a flash memory, a hard disk, or a solid-state disk; and the memory 20 can also include a combination of the above-mentioned kinds of memories.
[0184] The computer device further includes a communication interface 30 for the computer device to communicate with other devices or communication networks.
[0185] The embodiments of the present application also provide a computer readable storage medium. The above method according to the embodiments of the present application can be implemented in hardware, firmware, or recorded in a storage medium, or stored in a remote storage medium or a non-transitory machine readable storage medium and downloaded to a local storage medium through network downloading, so that the method described herein can be processed by such software on a storage medium using a general computer, a special processor, or programmable or special hardware. The storage medium can be a magnetic disk, an optical disk, a read-only memory, a random access memory, a flash memory, a hard disk, or a solid-state disk, and the like; further, the storage medium can also include a combination of the above-mentioned kinds of memories. It can be understood that the computer, the processor, the microprocessor controller, or the programmable hardware includes a storage component that can store or receive software or computer code, when the software or computer code is accessed and executed by the computer, the processor, or the hardware, the method illustrated in the above embodiments is implemented.
[0186] Although the embodiments of the present application are described in conjunction with the accompanying drawings, various modifications and changes can be made by those skilled in the art without departing from the spirit and scope of the present application, and such modifications and changes fall within the scope defined by the appended claims.
Claims
1. A log acquisition method characterized by comprising: The method comprises: acquiring a log type of a log to be queried, a log formatting manner corresponding to the log type, and a target log structure; determining a log query strategy corresponding to the log type and a log query position corresponding to the log query strategy according to the log type; acquiring a first log from the log query position according to the log query strategy; performing first formatting processing on the first log according to the log formatting manner to acquire a second log; performing second formatting processing on the second log according to the target log structure to acquire a target log; the log formatting manner comprises a separator and a filtering item corresponding to the log type, and the first formatting processing on the first log according to the log formatting manner to acquire the second log comprises: finding the separator in the first log; generating a third log after converting the separator in the first log into a preset target separator; filtering the third log according to the filtering item to acquire the second log; the second formatting processing on the second log according to the target log structure to acquire the target log comprises: extracting field information in the target log structure; screening the second log according to the field information to acquire the target log.
2. The method of claim 1, wherein, the log type comprises a first log type and a second log type, the first log type is a system log type, and the second log type is a component log type.
3. The method of claim 2, wherein, when the log type is the first log type, the log query strategy comprises a first query instruction set, a query period, and a query number, and the acquiring of the first log from the log query position according to the log query strategy comprises: running a query instruction in the first query instruction set according to the query period to query log information from the log query position; generating the first log according to log information acquired according to all the query periods when the number of times of running the query instruction in the first query instruction set according to the query period meets the query number.
4. The method of claim 1, wherein, when the log type is the second log type, the log query strategy comprises a second query instruction set, and the acquiring of the first log from the log query position according to the log query strategy comprises: sequentially executing each query instruction in the second query instruction set to determine component information corresponding to the second query instruction set; finding a log query tool corresponding to the component information according to the component information; acquiring the first log from the log query position by using the log query tool.
5. The method of claim 4, wherein, the query instruction in the second query instruction set comprises one or more of the following: a device component number query instruction, a device name query instruction, and a device identity number query instruction.
6. A log acquisition apparatus characterized by comprising: the device comprises: an acquisition module configured to acquire a log type of a log to be queried, a log formatting manner corresponding to the log type, and a target log structure; a determination module configured to determine a log query strategy corresponding to the log type and a log query position corresponding to the log query strategy according to the log type; The processing module is configured to acquire a first log from the log query position according to the log query strategy. The first formatting processing module is configured to perform first formatting processing on the first log according to the log formatting manner, and acquire a second log. The second formatting processing module is configured to perform second formatting processing on the second log according to the target log structure, and acquire a target log. The log formatting manner includes a separator and a filtering item corresponding to the log type, and the first formatting processing module is configured to: find the separator in the first log; generate a third log after converting the separator in the first log into a preset target separator; filter the third log according to the filtering item, and acquire the second log. The second formatting processing module is configured to: extract field information in the target log structure; screen the second log according to the field information, and acquire the target log.
7. A computer device, comprising: The log acquisition method comprises: a memory and a processor, which are connected in communication with each other, the memory stores computer instructions, and the processor executes the computer instructions to perform the log acquisition method in any one of claims 1 to 5.
8. A computer-readable storage medium, characterized in that, The computer readable storage medium stores computer instructions, and the computer instructions are used to make a computer execute the log acquisition method in any one of claims 1 to 5.
Citation Information
Patent Citations
Game log content query method and device, computer equipment and storage medium
CN111177081A
Log visual presentation management method and device
CN112000564A