A log display processing method
By obtaining type tags through the log printing API and automatically replacing log identifiers, the problem of time-consuming and laborious manual modification of log source code in OEM scenarios is solved, achieving efficient and accurate log identifier replacement.
Patent Information
- Application Number
- CN202311397052.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-10-25
- Publication Date
- 2026-11-24
- Estimated Expiration
- 2043-10-25
AI Technical Summary
In existing technologies, since the logs contain strings related to the first user identifier, they need to be replaced with strings related to the second user identifier in OEM scenarios. Existing methods rely on manual modification of the source code, which is time-consuming, labor-intensive, and prone to omissions.
By obtaining the type label through the log printing API, the system automatically identifies and replaces the first user identifier string in the log with the second user identifier string. The processing method is encapsulated using the log printing driver, avoiding manual modification of the source code.
It enables automatic replacement of log identifiers, reducing the time and errors of manual modification, improving processing efficiency and accuracy, and adapting to the needs of OEM scenarios.
Smart Images

Figure CN117331519B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of electronic digital data processing technology, and in particular to a method for displaying logs. Background Technology
[0002] Current technology implements log printing functionality by calling a log printing function. If the source code corresponding to the log to be printed was written by a first user and contains a string related to the first user's identifier, then the printed log will also contain that string. However, in Original Equipment Manufacture (OEM) scenarios, the log often doesn't need to print the string related to the first user's identifier, but rather a string related to a second user's identifier. The current approach involves manually modifying the source code corresponding to the log to be printed, which is time-consuming, labor-intensive, and prone to omissions in modifications. Summary of the Invention
[0003] The purpose of this invention is to provide a log display processing method to solve the problems of time-consuming, labor-intensive, and prone to omissions in the modification of the source program corresponding to the log to be printed, which is done manually.
[0004] According to the present invention, a method for displaying logs is provided, the method comprising the following steps:
[0005] S100, in response to the log printing API being called, obtain the type label of the log to be printed; the label is a first value or a second value, the first value is used to indicate that the log with a first user identifier is being printed; the second value is used to indicate that the log with a second user identifier is being printed.
[0006] S200: If label is the first value, then print log; if label is the second value, then proceed to S300.
[0007] S300, Get the first string list str1, str1=(str 1,1 str 1,2 ,…,str 1,i ,…,str 1,n ), str 1,i The i-th string is a preset string associated with the first user identifier, where i ranges from 1 to n, and n is the preset number of strings associated with the first user identifier.
[0008] S400, iterate through str1, if str appears in log... 1,i Then the log will contain str. 1,iThe position is appended to the preset i-th position sequence pos i , get pos i =(pos i,1 ,pos i,2 ,…,pos i,mi ,…,pos i,Mi ), and enter S500, pos i The sequence is initialized to an empty sequence, pos i,mi For the mi-th occurrence of str in log 1,i The position of mi, where mi ranges from 1 to Mi, and Mi is the position of str in the logarithm. 1,i The number of positions.
[0009] S500, obtain the second string list str2, str2=(str 2,1 str 2,2 ,…,str 2,i ,…,str 2,n ), str 2,i For str 1,i Related records, str 2,i =(str 1,i ,str' 1,i ), str' 1,i For the preset replacement str associated with the second user identifier 1,i The string.
[0010] S600, Traverse the set of position sequences pos, pos={pos1,pos2,…,pos} i ,…,pos n}, put pos in log i The corresponding str 1,i Replace with str' 1,i .
[0011] S700 prints the replaced log.
[0012] Compared with the prior art, the present invention has at least the following beneficial effects:
[0013] The log display processing method of this invention, in response to a log printing API call, first obtains the type label of the log to be printed. This type label has two values: a first value indicates that the current requirement is to print logs with a first user identifier, and a second value indicates that the current requirement is to print logs with a second user identifier. If the type label of the log to be printed is the first value, the log to be printed can be printed directly. If the type label of the log to be printed is the second value, subsequent steps are executed. Specifically, a first string list is first obtained, which stores preset strings related to the first user identifier. By matching each preset string related to the first user identifier in the first string list with the log to be printed, this invention can obtain... The system identifies the positions where each preset string related to the first user identifier appears in the log to be printed, and stores the position of the i-th preset string related to the first user identifier in the i-th position sequence. Based on this, a second string list is obtained, which stores each preset string related to the first user identifier in the first string list and the corresponding string used to replace it. The corresponding string used to replace it is a string related to the second user identifier. Therefore, when the string at the corresponding position in each of the above position sequences in the log to be printed is replaced by the above-mentioned string used to replace it, the log to be printed after the replacement will no longer contain a string related to the first user identifier, but will instead contain a string related to the second user identifier.
[0014] This invention addresses the potential need to replace strings related to the first user identifier in logs with strings related to the second user identifier. Instead of manually modifying the source code after confirming the need, it encapsulates the processing method for automatically printing logs with either the first or second user identifier within the log printing driver. This ensures compatibility with scenarios involving printing either type of log. Consequently, when the log printing API is called, the function of printing either logs with either the first or second user identifier will be executed automatically, eliminating the need to modify the source code. This avoids the time-consuming, labor-intensive, and potentially inaccurate modification issues associated with manually modifying the source code of the logs to be printed, as is common in existing technologies. Attached Figure Description
[0015] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0016] Figure 1 The present invention provides a log display processing method. Detailed Implementation
[0017] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0018] According to this embodiment, as Figure 1 As shown, a method for displaying logs is provided, the method including the following steps:
[0019] S100, in response to the log printing API being called, obtain the type label of the log to be printed; the label is a first value or a second value, the first value is used to indicate that the log with a first user identifier is being printed; the second value is used to indicate that the log with a second user identifier is being printed.
[0020] In one specific implementation, the first value is 0 and the second value is 1. When label=0, it is determined that the current requirement is to print logs with the first user's identifier; when label=1, it is determined that the current requirement is to print logs with the second user's identifier. In this embodiment, the first user specifically refers to the user who wrote the source code corresponding to the log to be printed, that is, the user who undertakes the outsourcing task; the second user does not specifically refer to any particular user, but rather to the user who entrusts the first user with the outsourcing task in the current OEM scenario.
[0021] S200: If label is the first value, then print log; if label is the second value, then proceed to S300.
[0022] S300, Get the first string list str1, str1=(str 1,1 str 1,2 ,…,str 1,i ,…,str 1,n ), str 1,i The i-th string is a preset string associated with the first user identifier, where i ranges from 1 to n, and n is the preset number of strings associated with the first user identifier.
[0023] In this embodiment, str1 is a manually preset list, and the person makes the judgment on which strings are related to the first user identifier.
[0024] S400, iterate through str1, if str appears in log... 1,i Then the log will contain str. 1,i The position is appended to the preset i-th position sequence pos i , get pos i =(pos i,1 ,pos i,2 ,…,pos i,mi ,…,pos i,Mi ), and enter S500, pos i The sequence is initialized to an empty sequence, pos i,mi For the mi-th occurrence of str in log 1,i The position of mi, where mi ranges from 1 to Mi, and Mi is the position of str in the logarithm. 1,i The number of positions.
[0025] Preferably, S400 includes:
[0026] S410, retrieve the string list str0 of log, str0 = (str 0,1 str 0,2 ,…,str 0,q ,…,str 0,Q ), str 0,q This is the q-th string in log, obtained in a forward-to-back order. The value of q ranges from 1 to Q, where Q is the number of strings included in log.
[0027] S420, Get the first character count list num1, num1=(num 1,1 ,num 1,2 ,…,num 1,j ,…,num 1,δ ), num 1,j δ represents the number of the j-th type of character in the string str1, where j ranges from 1 to δ, and δ is the number of different types of characters in the string str1.
[0028] It should be understood that the number of characters in a string is the number of characters it contains. For example, the string "maca" contains 4 characters, and the string "mx" contains 2 characters.
[0029] Preferably, the process of obtaining num1 includes:
[0030] S421, retrieve str 1,1 The number of characters included is num'1, and num'1 is appended to the preset character count list num', which is initialized to an empty list.
[0031] S422, obtain a first variable k, where the initial value of k is 2.
[0032] S423, obtain the number of characters num' included in str 1,k k , if num' does not include num' k , append num' k to num'; otherwise, do not append num' k to num'.
[0033] S424, if k<n, set k=k+1, and repeat S423 until k=n.
[0034] S425, determine num' as num1.
[0035] num1 obtained according to S421-S421 neither includes the same number of characters nor omits the number of characters included in any string in str1; performing subsequent S430-S440 based on this num1 can improve the accuracy of obtaining the position of the string related to the first user identifier in the log to be printed.
[0036] S430, traverse str0, and obtain the number of characters num included in str 0,q 0,q , if num 0,q =num 1,j , proceed to S440.
[0037] In this embodiment, S430 further includes: if num 0,q is not equal to any num in num1 1,j , do not append str 0,q to any pos i .
[0038] S440, traverse the j-th substring list str j 1, str j 1=(str j 1,1 ,str j 1,2 ,…,str j 1,u(j) ,…,str j 1,v(j) ), if str 0,q =str j 1,u(j) , append q to a preset η-th position sequence, where η is the ordinal number of str j 1,u(j) in str1, str j 1,u(j) Let num be the number of characters included in the u(j)th element of str1. 1,j The string is defined by u(j), where u(j) ranges from 1 to v(j), and v(j) is the number of characters in str1. 1,j The number of strings.
[0039] It should be understood that if str j 1,u(j) =str 1,i Then str j 1,u(j) The ordinal number in str1 is i; for example, if str j 1,u(j) =str 1,1 Then str j 1,u(j) The ordinal number in str1 is 1; if str j 1,u(j) =str 1,2 Then str j 1,u(j) The ordinal number in str1 is 2.
[0040] In this embodiment, S440 further includes: if str 0,q Not equal to str j any str in 1 j 1,u(j) Then str will not be 0,q Append to any pos i .
[0041] In steps S410-S440 of this embodiment, for the log to be printed, a corresponding string list and a first character count list are first obtained. The first character count list stores the character counts corresponding to all strings in the first string list. By matching the character counts of each string in the log to be printed with the character counts in the first string count list, strings in the log to be printed that do not match the character counts of the strings in the first string list are first filtered out, reducing the workload of comparing whether the strings are the same and improving the efficiency of obtaining the position of the string related to the first user identifier in the log to be matched. For the strings in the log to be printed that match the character counts of the strings in the first string list, only the strings that match the character counts in the first string list are compared, reducing the number of strings to be compared and further improving the efficiency of obtaining the position of the string related to the first user identifier in the log to be matched.
[0042] S500, obtain the second string list str2, str2=(str 2,1 str 2,2 ,…,str2,i ,…,str 2,n ), str 2,i For str 1,i Related records, str 2,i =(str 1,i ,str' 1,i ), str' 1,i For the preset replacement str associated with the second user identifier 1,i The string.
[0043] In this embodiment, str2 is a manually preset list, and the human judges which strings are replaced by the user and are related to the first user identifier.
[0044] S600, Traverse the set of position sequences pos, pos={pos1,pos2,…,pos} i ,…,pos n}, put pos in log i The corresponding str 1,i Replace with str' 1,i .
[0045] S700 prints the replaced log.
[0046] In this embodiment, the computer program corresponding to steps S100-S700 is encapsulated in the log printing driver, so steps S100-S700 are executed when the log printing driver is run.
[0047] Preferably, label, str1, and str2 are obtained from a pre-defined encapsulated setting class. The process of obtaining the pre-defined encapsulated setting class includes:
[0048] S010, retrieve label, str1, and str2 from a preset configuration file, which is stored in eEPROM.
[0049] S020, encapsulate label, str1, and str2 in a setting class to obtain the preset encapsulated setting class.
[0050] Those skilled in the art will understand that any packaging method in the prior art falls within the protection scope of this invention.
[0051] In this embodiment, the preset configuration file is stored in the EEPROM, which ensures that the configuration file is not lost after power failure, thus improving the reliability of configuration file storage. Furthermore, this embodiment encapsulates the type tags, the first string list, and the second string list read from the configuration file into a setting class. This allows for direct reading of the type tags from the encapsulated setting class during execution S100, the first string list during execution S300, and the second string list during execution S500. This embodiment directly reads the type tags, the first string list, and the second string list from the encapsulated setting class, resulting in faster reading speeds and improved log printing efficiency.
[0052] The log display processing method in this embodiment responds to the log printing API being called by first obtaining the type label of the log to be printed. This type label has two values: a first value indicates that the current requirement is to print logs with a first user identifier, and a second value indicates that the current requirement is to print logs with a second user identifier. If the type label of the log to be printed is the first value, then the log to be printed can be printed directly. If the type label of the log to be printed is the second value, then subsequent steps are executed. Specifically, a first string list is first obtained, which stores preset strings related to the first user identifier. By matching each preset string related to the first user identifier in the first string list with the log to be printed, this embodiment can obtain... The system retrieves the position of each preset string related to the first user identifier in the log to be printed, and stores the position of the i-th string related to the first user identifier in the i-th position sequence. Based on this, a second string list is obtained, which stores each preset string related to the first user identifier in the first string list and the corresponding string used to replace it. The corresponding string used to replace it is a string related to the second user identifier. Therefore, when the string at the corresponding position in each of the above position sequences in the log to be printed is replaced with the above-mentioned string used to replace it, the log to be printed after the replacement will no longer contain a string related to the first user identifier, but will instead contain a string related to the second user identifier.
[0053] In this embodiment, for the potential need to replace strings related to the first user identifier in the log with strings related to the second user identifier, instead of manually modifying the source code corresponding to the log after confirming the existence of the need, the processing method of automatically executing the printing of logs with the first user identifier or the printing of logs with the second user identifier is encapsulated in the log printing driver to be compatible with scenarios of printing logs with the first user identifier or printing logs with the second user identifier. Thus, when the log printing API is called, the function of printing logs with the first user identifier or printing logs with the second user identifier will be executed automatically, without the need to modify the source code corresponding to the log. This avoids the problems of manual modification of the source program corresponding to the log to be printed in the prior art, which is time-consuming, laborious, and prone to omissions.
[0054] While specific embodiments of the invention have been described in detail by way of example, those skilled in the art should understand that the examples are for illustrative purposes only and not intended to limit the scope of the invention. It should also be understood that various modifications can be made to the embodiments without departing from the scope and spirit of the invention. The scope of the invention is defined by the appended claims.
Claims
1. A method for processing log display, characterized in that, The processing method comprises the following steps: S100: In response to a log printing API being called, obtain the type label of the log to be printed; the label is a first value or a second value, wherein the first value is used to indicate that logs with a first user identifier are to be printed, and the second value is used to indicate that logs with a second user identifier are to be printed; S200: If the label is the first value, print the log; if the label is the second value, proceed to S300; S300, Get the first string list str1, str1=(str 1,1 str 1,2 ,…,str 1,i ,…,str 1,n ), str 1,i The i-th string is a preset string associated with the first user identifier, where i ranges from 1 to n, and n is the preset number of strings associated with the first user identifier. S400, iterate through str1, if str appears in log... 1,i Then the log will contain str. 1,i The position is appended to the preset i-th position sequence pos i , get pos i =(pos i,1 ,pos i,2 ,…,pos i,mi ,…,pos i,Mi ), and enter S500, pos i The sequence is initialized to an empty sequence, pos i,mi For the mi-th occurrence of str in log 1,i The position of mi, where mi ranges from 1 to Mi, and Mi is the position of str in the logarithm. 1,i The number of positions; S500, obtain the second string list str2, str2=(str 2,1 str 2,2 ,…,str 2,i ,…,str 2,n ), str 2,i For str 1,i Related records, str 2,i =(str 1,i ,str' 1,i ), str' 1,i For the preset replacement str associated with the second user identifier 1,i The string; S600, Traverse the set of position sequences pos, pos={pos1,pos2,…,pos} i ,…,pos n }, put pos in log i The corresponding str 1,i Replace with str' 1,i ; S700: Print the replaced log; S400 includes: S410, retrieving the string list str0 of the log, str0 = (str 0,1 str 0,2 ,…,str 0,q ,…,str 0,Q ), str 0,q This is the q-th string of log obtained in reverse order, where q ranges from 1 to Q, and Q is the number of strings included in log. S420, Get the first character count list num1, num1=(num 1,1 ,num 1,2 ,…,num 1,j ,…,num 1,δ ), num 1,j δ represents the number of the j-th type of character in the string str1, where j ranges from 1 to δ, and δ is the number of different types of characters in the string str1. S430, iterate through str0 and get str 0,q Number of characters included (num) 0,q If num 0,q =num 1,j Then enter S440; S440, iterate through the list of the j-th substrings str j 1, str j 1=(str j 1,1 str j 1,2 ,…,str j 1,u(j) ,…,str j 1,v(j) If str 0,q =str j 1,u(j) Then q will be appended to the preset nth position sequence, where n is str j 1,u(j) The ordinal number in str1, str j 1,u(j) Let num be the number of characters included in the u(j)th element of str1. 1,j The string is defined by u(j), where u(j) ranges from 1 to v(j), and v(j) is the number of characters in str1. 1,j The number of strings.
2. The log display processing method according to claim 1, characterized in that, The label, str1 and str2 are obtained from a pre-configured encapsulated setting class.
3. The log display processing method according to claim 2, characterized in that, The obtaining process of the pre-configured encapsulated setting class comprises: S010: Obtain the label, str1 and str2 from a pre-configured configuration file, which is stored in an EEPROM; S020: Encapsulate the label, str1 and str2 into a setting class to obtain the pre-configured encapsulated setting class.
4. The log display processing method according to claim 1, characterized in that, Steps S100 to S700 are executed when a driver for running log printing is executed.
5. The log display processing method according to claim 1, characterized in that, The obtaining process of num1 comprises: S421, retrieve str 1,1 The number of characters included is num'1, and num'1 is appended to the preset character count list num', which is initialized to an empty list; S422: Obtain a first variable k, with an initial value of 2; S423, retrieve str 1,k The number of characters included, num' k If num' does not include num' k Then num' k Append to num'; otherwise, do not append to num'. k Append to num'; S424: If k<n, set k=k+1, and repeat S423 until k=n; S425: Determine num' as num1.
6. The log display processing method according to claim 1, characterized in that, S430 also includes: if num 0,q Not equal to any num in num1 1,j Then str will not be 0,q Append to any pos i .
7. The log display processing method according to claim 1, characterized in that, S440 also includes: if str 0,q Not equal to str j any str in 1 j 1,u(j) Then str will not be 0,q Append to any pos i .
Citation Information
Patent Citations
Application log printing method and apparatus, computer device and storage medium
CN109375884A
Log-based software debugging method
CN114116475A
