CN-115269324-B - Log recording method, device, equipment and readable storage medium
Abstract
The application discloses a log recording method, a log recording device, log recording equipment and a readable storage medium in the technical field of computers. According to the application, all items to be detected in the URL can be determined in reverse order from the tail part of the URL, then the current URL is matched according to the determined order (namely, the reverse order) of all the items to be detected, if the current URL is matched with the preset rule, the key information to be recorded to the log is indicated to be matched, so that the log recording is carried out on the matched content, and therefore, the key information to be recorded can be accurately determined. According to the scheme, the whole URL is not required to be analyzed in a full quantity, but the key information to be recorded to the log in the URL is rapidly determined from the tail part of the URL, so that the log recording efficiency is improved, the probability of recording redundant information to the log can be reduced, and the log precision is improved. Correspondingly, the log recording device, the log recording equipment and the readable storage medium have the technical effects.
Inventors
- WANG JIE
Assignees
- 济南浪潮数据技术有限公司
Dates
- Publication Date
- 20260512
- Application Date
- 20220727
Claims (5)
- 1. A method of logging, comprising: acquiring a URL corresponding to the HTTP request; Starting from the tail of the URL, determining each item to be detected existing in the URL in an inverted order; Matching the URL according to the determined sequence of each item to be detected, and if the URL is matched with a preset rule, carrying out log record on the matched content; If the URL is matched with a preset rule, log recording is performed on the matched content, including: The preset rules comprise a key information rule, a position rule of key information and a regular expression rule; For the URL, firstly utilizing the key information rule to match, and if the URL is matched with the key information rule, logging for matching content; If the URL is not matched with the key information rule, matching is carried out by utilizing the position rule of the key information, and if the URL is matched with the position rule of the key information, log recording is carried out for matching content; if the URL is not matched with the key information rule and the position rule of the key information, matching by using the regular expression rule, and if the URL is matched with the regular expression rule, logging the matched content; If the URL is not matched with the key information rule, the position rule of the key information and the regular expression rule, recording the URL to a log; The preset rules also comprise full character matching rules; correspondingly, before determining each item to be tested existing in the URL in reverse order from the tail of the URL, the method further comprises: matching all characters in the URL by using a full character matching rule; If the matching fails, executing the steps of starting from the tail part of the URL, and determining each item to be detected existing in the URL in an inverted sequence; and matching the URL according to the determined sequence of each item to be detected, and if the URL is matched with a preset rule, carrying out log recording on the matched content.
- 2. The method of claim 1, wherein determining each item under test present in the URL in reverse order, starting from the tail of the URL, comprises: From the tail to the head of the URL, determining characters located between adjacent separators as an item to be tested, and/or determining characters at specific positions as an item to be tested, and/or determining specific characters as an item to be tested, and determining each item to be tested existing in the URL in an inverse order.
- 3. A logging device, comprising: the acquisition module is used for acquiring the URL corresponding to the HTTP request; the determining module is used for determining all items to be detected existing in the URL in reverse order from the tail part of the URL; The recording module is used for matching the URLs according to the determined sequence of each item to be detected, and if the URLs are matched with a preset rule, log recording is carried out on the matched content; The preset rules comprise a key information rule, a position rule where key information is located and a regular expression rule; Accordingly, the recording module includes: the keyword matching unit is used for matching the URL by utilizing the keyword rule, and if the URL is matched with the keyword rule, log recording is carried out on the matched content; the key position matching unit is used for matching by utilizing the position rule of the key information if the URL is not matched with the position rule of the key information, and logging the matched content if the URL is matched with the position rule of the key information; The regular matching unit is used for matching by utilizing the regular expression rule if the URL is not matched with the key information rule and the position rule of the key information, and logging the matched content if the URL is matched with the regular expression rule; The URL recording unit is used for recording the URL to a log if the URL is not matched with the key information rule, the position rule of the key information and the regular expression rule; the preset rules further comprise full character matching rules, and correspondingly, the method further comprises the steps of: The method comprises the steps of starting from the tail of the URL, determining all the items to be detected in the URL in an inverse sequence, matching all the characters in the URL by utilizing a full character matching rule before determining all the items to be detected in the URL in an inverse sequence, executing the steps of starting from the tail of the URL if the matching is failed, determining all the items to be detected in the URL in an inverse sequence, matching the URL according to the determining sequence of all the items to be detected, and recording logs aiming at matching contents if the URL is matched with a preset rule.
- 4. An electronic device, comprising: A memory for storing a computer program; a processor for executing the computer program to implement the method of any one of claims 1 to 2.
- 5. A readable storage medium for storing a computer program, wherein the computer program when executed by a processor implements the method of any one of claims 1 to 2.
Description
Log recording method, device, equipment and readable storage medium Technical Field The present application relates to the field of computer technologies, and in particular, to a method, an apparatus, a device, and a readable storage medium for recording logs. Background Currently, when logging URLs that are actually accessed, it is necessary to parse the URL path in full. In a more complex service scenario, because URLs are relatively complex, the full resolution of all URLs requires more computational effort to support, and the recorded log information may not be sufficiently simplified, which may increase the log recording difficulty. Therefore, how to efficiently determine the information to be recorded to the log in the URL, and improve the log precision and the recording efficiency is a problem that needs to be solved by those skilled in the art. Disclosure of Invention Accordingly, the present application is directed to a method, apparatus, device and readable storage medium for recording logs, so as to efficiently determine the information to be recorded to the logs in the URL, and improve the accuracy and efficiency of the logs. The specific scheme is as follows: in a first aspect, the present application provides a logging method, including: acquiring a URL corresponding to the HTTP request; Starting from the tail of the URL, determining each item to be detected existing in the URL in an inverted order; and matching the URL according to the determined sequence of each item to be detected, and if the URL is matched with a preset rule, carrying out log record on the matched content. Optionally, the determining each item to be tested existing in the URL in reverse order from the tail of the URL includes: From the tail to the head of the URL, determining characters located between adjacent separators as an item to be tested, and/or determining characters at specific positions as an item to be tested, and/or determining specific characters as an item to be tested, and determining each item to be tested existing in the URL in an inverse order. Optionally, if the URL matches with a preset rule, logging is performed for the matching content, including: The preset rules comprise a key information rule, a position rule of key information and a regular expression rule; and for the URL, firstly utilizing the key information rule to match, and if the URL is matched with the key information rule, logging for the matched content. Optionally, the method further comprises: and if the URL is not matched with the key information rule, matching by using the position rule of the key information, and if the URL is matched with the position rule of the key information, logging the matched content. Optionally, the method further comprises: and if the URL is not matched with the key information rule, matching by using the position rule of the key information, and if the URL is matched with the position rule of the key information, logging the matched content. Optionally, the method further comprises: And if the URL is not matched with the key information rule, the position rule of the key information and the regular expression rule, recording the URL to a log. Optionally, the method further comprises: analyzing each URL recorded in the log to obtain an analysis result; and complementing the preset rule based on the analysis result. Optionally, the preset rule further comprises a full character matching rule, and correspondingly, before each item to be tested existing in the URL is determined in reverse order from the tail part of the URL, the method further comprises the steps of: matching all characters in the URL by using a full character matching rule; If the matching fails, executing the steps of starting from the tail part of the URL, and determining each item to be detected existing in the URL in an inverted sequence; and matching the URL according to the determined sequence of each item to be detected, and if the URL is matched with a preset rule, carrying out log recording on the matched content. In a second aspect, the present application provides a logging apparatus comprising: the acquisition module is used for acquiring the URL corresponding to the HTTP request; the determining module is used for determining all items to be detected existing in the URL in reverse order from the tail part of the URL; And the recording module is used for matching the URLs according to the determined sequence of each item to be detected, and if the URLs are matched with a preset rule, log recording is carried out on the matched content. Optionally, the determining module is specifically configured to: From the tail to the head of the URL, determining characters located between adjacent separators as an item to be tested, and/or determining characters at specific positions as an item to be tested, and/or determining specific characters as an item to be tested, and determining each item to be tested existing in the URL in an invers