Artificial Intelligence-Based Log Printing Method, Device, Electronic Device, and Medium
By analyzing and safely processing logs to be printed, the problem of malicious user modification in open source Log4J2 log printing is solved, efficient and secure log printing is achieved, ensuring the accuracy of logs and system response speed.
Patent Information
- Application Number
- CN202111531290.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-14
- Publication Date
- 2025-07-18
- Estimated Expiration
- 2041-12-14
AI Technical Summary
When using open source Log4J2 for log printing, there is a problem that the request parameters are modified by malicious users, resulting in low accuracy of the log to be printed, and modifying the code may cause code repetition problems.
By parsing the log printing request, obtain the log to be printed in the dependency package, determine whether the log security check master switch is on, and perform safe processing when it is turned on, including identifying and deleting special characters or serializing the log to be printed, generating the target printing log, and finally log printing is performed through a custom printing method.
Improves the security and accuracy of log printing, avoids malicious users inserting any log entries, improves system response speed and log printing efficiency, and does not need to modify the original log printing framework.
Smart Images

Figure CN114185501B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence technology, and particularly relates to a log printing method, device, electronic device and medium based on artificial intelligence. Background Art
[0002] Currently, the system realizes the log printing function by calling the open-source Log4J2. When using the open-source Log4J2 for log printing, developers generally print out the page request parameters of third-party applications.
[0003] However, when using the open-source Log4J2 to print log request parameters, some interfaces are directly released without any verification by the security gateway, resulting in the phenomenon that the request parameters are modified by malicious users. At the same time, if business developers are asked to modify the code modified by malicious users, there may be a problem of code duplication, resulting in low accuracy of the logs to be printed.
[0004] Therefore, it is necessary to propose a method that can accurately and quickly print logs. Summary of the Invention
[0005] In view of the above, it is necessary to propose a log printing method, device, electronic device and medium based on artificial intelligence, which solves the problem that malicious users insert arbitrary log entries using the same mechanism, and improves the security and accuracy of log printing.
[0006] The first aspect of the present invention provides a log printing method based on artificial intelligence, and the method includes:
[0007] Parse the received log printing request to obtain the dependency package of the log to be printed, where the dependency package contains class objects and the log to be printed;
[0008] Determine whether the overall switch of log security verification is turned on;
[0009] When the overall switch of log security verification is turned on, obtain the log to be printed from the dependency package;
[0010] Perform security processing on the log to be printed to obtain the target printed log;
[0011] Perform log printing on the target printed log according to the log printing method corresponding to the log printing request.
[0012] Optionally, the performing security processing on the log to be printed to obtain the target printed log includes:
[0013] Identify the parameter type of the parameter to be printed in the log to be printed;
[0014] When the parameter type of the parameter to be printed in the log to be printed is of the ordinary string type, identify the special characters in the log to be printed, and delete the special characters from the log to be printed to obtain the target print log; or
[0015] When the parameter type of the parameter to be printed in the log to be printed is not of the ordinary string type, serialize the log to be printed to obtain the target print log.
[0016] Optionally, the serializing the log to be printed includes:
[0017] Serialize the log to be printed according to a preset first method;
[0018] When the serialization of the log to be printed is successful, determine the serialized log to be printed as the target print log; or
[0019] When the serialization of the log to be printed fails, process the log to be printed using a preset second method, and determine the processed log to be printed as the target print log.
[0020] Optionally, the printing the target print log according to the log printing method corresponding to the log printing request includes:
[0021] Load the print request into a custom print factory class, and perform a security format process on the parameter to be printed in the target print log;
[0022] Forward the target print log after the security format process to the class object in the dependency package;
[0023] Call the log printing method on the class object to print the target print log.
[0024] Optionally, after printing the target print log according to the log printing method corresponding to the log printing request, the method further includes:
[0025] Provide a pointcut through the log printing framework Log4j2, and obtain a preset file directory in the resource file;
[0026] Create a log file to be printed under the file directory, and insert a special record into the log file to be printed using a preset decorator design pattern to generate the log to be printed, where the value in the special record is a class object of the custom log to be printed;
[0027] Inject the class object of the log to be printed into the Log4j2 log framework through the log file to be printed to generate a corresponding dependency package.
[0028] Optionally, when the overall switch for log security verification is turned on, obtaining the log to be printed from the dependency package includes:
[0029] Parsing the dependency package to obtain the identifier to be printed;
[0030] Obtaining the log to be printed from the dependency package based on the identifier to be printed.
[0031] Optionally, determining whether the overall switch for log security verification is turned on includes:
[0032] Determining the parameter identifier corresponding to the overall switch for log security verification;
[0033] When the value corresponding to the parameter identifier is the first preset value, determining that the overall switch for log security verification is turned on; or
[0034] When the value corresponding to the parameter identifier is the second preset value, determining that the overall switch for log security verification is turned off.
[0035] The second aspect of the present invention provides a log printing device based on artificial intelligence, and the device includes:
[0036] A parsing module, configured to parse the received log printing request to obtain the dependency package of the log to be printed, where the dependency package contains class objects and the log to be printed;
[0037] A judgment module, configured to judge whether the overall switch for log security verification is turned on;
[0038] An obtaining module, configured to obtain the log to be printed from the dependency package when the overall switch for log security verification is turned on;
[0039] A security processing module, configured to perform security processing on the log to be printed to obtain the target printed log;
[0040] A log printing module, configured to perform log printing on the target printed log according to the log printing method corresponding to the log printing request.
[0041] The third aspect of the present invention provides an electronic device, and the electronic device includes a processor and a memory. When the processor executes the computer program stored in the memory, the log printing method based on artificial intelligence is implemented.
[0042] The fourth aspect of the present invention provides a computer-readable storage medium, and a computer program is stored on the computer-readable storage medium. When the computer program is executed by a processor, the log printing method based on artificial intelligence is implemented.
[0043] In summary, for the log printing method, device, electronic device, and medium based on artificial intelligence according to the present invention, by parsing the received log printing request to obtain the dependent package of the log to be printed, since the dependent package is directly obtained through the log object to be printed, the client does not need to modify any code, ensuring the efficiency of obtaining the log to be printed. Determine whether the overall switch for log security verification is turned on. When the overall switch for log security verification is turned on, close the log security verification function through security processing configuration to improve the response speed of the entire system, solving the problem of slow log printing caused by a sharp increase in traffic during a certain period of time and improving the log printing efficiency. When the overall switch for log security verification is turned on, obtain the log to be printed from the dependent package, perform security processing on the log to be printed to obtain the target printed log. By performing security processing on the log to be printed, the problem of malicious users inserting arbitrary log entries using the same mechanism is solved, improving the security and accuracy of log printing. Perform log printing on the target printed log according to the log printing method corresponding to the log printing request, avoiding the phenomenon of inconsistent printing results caused by changing the log printing method in the original log printing framework and improving the security of log printing. Brief Description of the Drawings
[0044] Figure 1 FIG. is a flowchart of a log printing method based on artificial intelligence provided in Embodiment 1 of the present invention.
[0045] Figure 2 FIG. is a structural diagram of a log printing device based on artificial intelligence provided in Embodiment 2 of the present invention.
[0046] Figure 3 FIG. is a schematic structural diagram of an electronic device provided in Embodiment 3 of the present invention. Detailed Embodiments
[0047] In order to more clearly understand the above objects, features, and advantages of the present invention, the present invention will be described in detail below with reference to the accompanying drawings and specific embodiments. It should be noted that, without conflict, the embodiments of the present invention and the features in the embodiments may be combined with each other.
[0048] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by those skilled in the technical field to which the present invention belongs. The terms used in the specification of the present invention herein are only for the purpose of describing specific embodiments and are not intended to limit the present invention.
[0049] Embodiment 1
[0050] Figure 1 FIG. is a flowchart of a log printing method based on artificial intelligence provided in Embodiment 1 of the present invention.
[0051] In this embodiment, the artificial intelligence-based log printing method can be applied to electronic devices. For electronic devices that need to perform artificial intelligence-based log printing, the artificial intelligence-based log printing function provided by the method of the present invention can be directly integrated into the electronic device, or run in the electronic device in the form of a software development kit (Software Development Kit, SDK).
[0052] like Figure 1 As shown, the artificial intelligence-based log printing method specifically includes the following steps. According to different requirements, the order of the steps in the flowchart can be changed, and some can be omitted.
[0053] S11, parsing the received log printing request, and obtaining a dependency package of the log to be printed, wherein the dependency package includes a class object and the log to be printed.
[0054] In this embodiment, when the client needs to print a log, the client initiates a log printing request to the server. The client can be a smart phone, IPAD or other existing smart devices, and the server can be a log printing subsystem. During the log printing process, the client can send a log printing request to the log printing subsystem, and the log printing subsystem is used to receive the log printing request sent by the client.
[0055] In this embodiment, when the log printing subsystem receives a log printing request, it parses the log printing request and obtains a dependency package. Specifically, the dependency package is a ConfigChangeListener class that implements a log to be printed in advance, and then injects the class into the IOC container through the spring.factories file.
[0056] In this embodiment, the log to be printed refers to the log requested to be printed by the application. When printing the log, the log printing framework used by the application can be identified in advance. Specifically, the log printing framework can be the Log4j2 log framework.
[0057] In an optional embodiment, parsing the received log printing request and obtaining the dependent package of the log to be printed includes:
[0058] Parse the received log printing request and obtain the message information;
[0059] The log object to be printed is extracted from the message information, and the dependent package of the log to be printed is obtained based on the log object to be printed.
[0060] In this embodiment, when a log printing request is received, a dependency package is obtained through the log object to be printed. The log to be printed in the dependency package refers to the addition of a Maven dependency for security log printing in the POM file of the corresponding project. The log object to be printed is the log object introduced by the client. The dependency package is directly obtained based on the log object, and the client does not need to modify any code, ensuring the efficiency of obtaining the log to be printed.
[0061] In this embodiment, the POM file refers to the project file corresponding to the application in the printing request. It is an XML file that contains the project configuration information of the entire project. Each project has only one pom.xml file.
[0062] S12. Determine whether the overall switch for log security verification is enabled.
[0063] In this embodiment, when the APP regularly holds an activity festival, it causes a sharp increase in traffic during a certain period. To solve the server pressure, it is determined whether the overall switch for log security verification is enabled. When the overall switch for log security verification is enabled, the log security verification function is turned off through the security processing configuration to improve the response speed of the entire system, solving the problem of slow log printing caused by a sharp increase in traffic during a certain period and improving the log printing efficiency.
[0064] In an alternative embodiment, the determination of whether the overall switch for log security verification is enabled includes:
[0065] Determine the parameter identifier corresponding to the overall switch for log security verification;
[0066] When the value corresponding to the parameter identifier is the first preset value, it is determined that the overall switch for log security verification is enabled; or
[0067] When the value corresponding to the parameter identifier is the second preset value, it is determined that the overall switch for log security verification is disabled.
[0068] In this embodiment, the parameter identifier can be safeCheck, and it is determined whether safeCheck is enabled.
[0069] In this embodiment, the first preset value can be "safeCheck = TRUE", and the second preset value can be "safeCheck = FALSE".
[0070] S13. When the overall switch for log security verification is enabled, obtain the log to be printed from the dependency package.
[0071] In this embodiment, the log to be printed contains the parameters to be printed.
[0072] In an optional embodiment, when the overall switch for log security verification is turned on, obtaining the log to be printed from the dependent package includes:
[0073] Parse the dependent package to obtain the identifier to be printed;
[0074] Obtain the log to be printed from the dependent package based on the identifier to be printed.
[0075] In some other optional embodiments, when the overall switch for log security verification is turned on, if the log to be printed obtained from the dependent package is empty, end the log printing.
[0076] In some other optional embodiments, when the overall switch for log security verification is turned on, if the log to be printed obtained from the dependent package is abnormal, end the log printing.
[0077] In this embodiment, when it is determined that the overall switch for log security verification is turned on, it is determined that security processing needs to be performed on the log to be printed.
[0078] S14, perform security processing on the log to be printed to obtain the target printed log.
[0079] In this embodiment, the target printed log refers to the log after security processing of the log to be printed.
[0080] In an optional embodiment, the performing security processing on the log to be printed to obtain the target printed log includes:
[0081] Identify the parameter type of the parameter to be printed in the log to be printed;
[0082] When the parameter type of the parameter to be printed in the log to be printed is the ordinary string type, identify the special characters in the log to be printed and delete the special characters from the log to be printed to obtain the target printed log; or
[0083] When the parameter type of the parameter to be printed in the log to be printed is a non-ordinary string type, serialize the log to be printed to obtain the target printed log.
[0084] In this embodiment, the parameter types include two categories, one is the ordinary string type, and the other is the non-ordinary string type. Different security processing methods are adopted for different parameter types, which is more targeted, thereby improving the security processing efficiency of the log to be printed and further improving the log printing efficiency.
[0085] Further, the serializing the log to be printed includes:
[0086] Serialize the log to be printed according to a preset first method;
[0087] When the serialization of the log to be printed is successful, determine the serialized log to be printed as the target print log; or
[0088] When the serialization of the log to be printed fails, process the log to be printed using a preset second method, and determine the processed log to be printed as the target print log.
[0089] In this embodiment, the preset first method may be: JSON serialization, and the preset second method may be: try{}catch(Exception){} processing, where the try{}catch(Exception){}.
[0090] In this embodiment, the special characters may be \r, \n and other pre-set characteristic characters.
[0091] In this embodiment, when printing logs, there may be printing vulnerabilities. If the string submitted by the client "val" is: "twenty-one", the following entry will be recorded in the log: INFO: Failed to parse val=twenty-one. However, if the attacker submits the string: "twenty-one%0a%0aINFO:+User+logged+out%3dbadguy", the following entry will be recorded in the log: INFO:User logged out=badguy. Obviously, malicious users can use the same mechanism to insert arbitrary log entries, resulting in low security and accuracy of log printing.
[0092] In this embodiment, by securely processing the log to be printed: "twenty-one" as "twentyone", malicious users cannot insert the log entry "twentyone". By securely processing the log to be printed, the problem of malicious users using the same mechanism to insert arbitrary log entries is solved, and the security and accuracy of log printing are improved.
[0093] In this embodiment, the latest open-source serialization tool FastJSON is adopted. By traversing all the getter methods in the class object, the object is serialized into a JSON string. During this process, special characters encountered will be escaped to ensure the security of the serialized string. At the same time, during the serialization process of the log to be printed, there may be two situations: serialization failure and success. When serialization fails, it is determined that there may be problems with some of the logs to be printed being unreasonable. To solve the problem of some logs to be printed being unreasonable, some logs to be printed that cannot be JSON serialized are safely processed by adopting a preset second method to obtain the target print log that can be printed.
[0094] S15. Perform log printing on the target print log according to the log printing method corresponding to the log printing request.
[0095] In this embodiment, by performing security processing on the log to be printed before printing and performing security processing on the special characters involved, the problem of the log to be printed being attacked by malicious users is prevented. At the same time, the log printing method on the class object is called to print the target print log, avoiding the phenomenon of inconsistent printing results caused by changing the log printing method in the original log printing framework, and improving the security of log printing.
[0096] In an alternative embodiment, performing log printing on the target print log according to the log printing method corresponding to the log printing request includes:
[0097] Load the printing request into a custom printing factory class and perform security format processing on the parameters to be printed in the target print log;
[0098] Forward the target print log after security format processing to the class object in the dependency package;
[0099] Call the log printing method on the class object to print the target print log.
[0100] Further, after performing log printing on the target print log according to the log printing method corresponding to the log printing request, the method further includes:
[0101] Provide a pointcut through the log printing framework Log4j2 and obtain a preset file directory in the resource file;
[0102] Create a log file to be printed under the file directory, and insert special records into the log file to be printed by adopting a preset decorator design pattern to generate a log to be printed, where the value in the special record is a custom class object of the log to be printed;
[0103] Inject the class object of the log to be printed into the Log4j2 logging framework through the log file to be printed, and generate the corresponding dependency package.
[0104] In this embodiment, after logging the target log according to the log printing method corresponding to the log printing request, a pointcut is provided through the logging framework Log4j2, and a file: log4j.component.properties is created under the META-INF directory of the resource file, and a special record is inserted in the log4j.component.properties file using the decorator design pattern: log4j2.messageFactory=cn.ping.hczlife.log.FlexibleLog4jMessageFactory, where the value corresponding to the special record: "cn.ping.hczlife.log.FlexibleLog4jMessageFactory" is a custom parameter printing object, that is, the class object of the log to be printed.
[0105] In this embodiment, inserting a special record through the decorator design pattern will not change the original class file, dynamically implement the extended object function, and improve the security of the log to be printed.
[0106] In this embodiment, the generated dependency package is made into a scaffold and uploaded to the Maven server. When relevant business developers perform log printing, they only need to introduce this maven dependency in the pom file of the corresponding project, without any code changes, to achieve the function of secure log printing with zero code injection, improving the security and efficiency of subsequent log printing.
[0107] S16. When the total switch of the log security check is turned off, obtain the log to be printed from the dependency package and perform log printing on the log to be printed.
[0108] In this embodiment, when the total switch of the log security check is turned off, it is determined that the log to be printed in the dependency package does not need to be security processed, and the log printing is directly executed.
[0109] In this embodiment, by judging whether the total switch of the log security check is turned on, it is possible to avoid security processing of some logs to be printed that do not need to be security processed, improving the printing efficiency and accuracy of the logs to be printed.
[0110] In summary, for the log printing method based on artificial intelligence described in this embodiment, by parsing the received log printing request, the dependent package of the log to be printed is obtained. Since the dependent package is directly obtained through the log object to be printed, the client does not need to modify any code, ensuring the efficiency of obtaining the log to be printed. It is judged whether the overall switch of log security verification is turned on. When the overall switch of log security verification is turned on, the log security verification function is turned off through security processing configuration to improve the response speed of the entire system, solving the problem of slow log printing caused by a sharp increase in traffic during a certain period of time and improving the log printing efficiency. When the overall switch of log security verification is turned on, the log to be printed is obtained from the dependent package, and the log to be printed is subjected to security processing to obtain the target printed log. By performing security processing on the log to be printed, the problem of malicious users inserting arbitrary log entries using the same mechanism is solved, improving the security and accuracy of log printing. The target printed log is printed according to the log printing method corresponding to the log printing request, avoiding the phenomenon of inconsistent printing results caused by changing the log printing method in the original log printing framework and improving the security of log printing.
[0111] Embodiment 2
[0112] Figure 2 It is a structural diagram of the log printing device based on artificial intelligence provided in Embodiment 2 of the present invention.
[0113] In some embodiments, the log printing device 20 based on artificial intelligence may include multiple functional modules composed of program code segments. The program code of each program segment in the log printing device 20 based on artificial intelligence can be stored in the memory of the electronic device and executed by the at least one processor to execute (see details in Figure 1 description) the functions of log printing based on artificial intelligence.
[0114] In this embodiment, the log printing device 20 based on artificial intelligence can be divided into multiple functional modules according to the functions it performs. The functional modules may include: a parsing module 201, a judgment module 202, an acquisition module 203, a security processing module 204, a log printing module 205, a creation module 206, and an injection module 207. The module referred to in the present invention means a series of computer-readable instruction segments that can be executed by at least one processor and can complete fixed functions, and are stored in the memory. In this embodiment, the functions of each module will be described in detail in subsequent embodiments.
[0115] The parsing module 201 is used to parse the received log printing request and obtain the dependent package of the log to be printed, where the dependent package contains class objects and the log to be printed.
[0116] In this embodiment, when the client needs to print a log, the client initiates a log printing request to the server. The client can be a smart phone, IPAD or other existing smart devices, and the server can be a log printing subsystem. During the log printing process, the client can send a log printing request to the log printing subsystem, and the log printing subsystem is used to receive the log printing request sent by the client.
[0117] In this embodiment, when the log printing subsystem receives a log printing request, it parses the log printing request and obtains a dependency package. Specifically, the dependency package is a ConfigChangeListener class that implements a log to be printed in advance, and then injects the class into the IOC container through the spring.factories file.
[0118] In this embodiment, the log to be printed refers to the log requested to be printed by the application. When printing the log, the log printing framework used by the application can be identified in advance. Specifically, the log printing framework can be the Log4j2 log framework.
[0119] In an optional embodiment, the parsing module 201 parses the received log printing request, and obtains the dependent package of the log to be printed, including:
[0120] Parse the received log printing request and obtain the message information;
[0121] The log object to be printed is extracted from the message information, and the dependent package of the log to be printed is obtained based on the log object to be printed.
[0122] In this embodiment, when a log printing request is received, the dependency package is obtained through the log object to be printed. The log to be printed in the dependency package refers to the security log printing Maven dependency added to the POM file of the corresponding project. The log object to be printed is the log object introduced by the client. The dependency package is directly obtained based on the log object. The client does not need to modify any code, thereby ensuring the efficiency of obtaining the log to be printed.
[0123] In this embodiment, the POM file refers to the project file corresponding to the application in the print request, which is an XML file containing the project configuration information of the entire project. Each project has only one pom.xml file.
[0124] The judgment module 202 is used to judge whether the main switch of the log security verification is turned on.
[0125] In this embodiment, when the APP regularly holds activity sessions, resulting in a sharp increase in traffic during a certain period, to solve the server pressure, it is determined whether the total switch of the log security check is turned on. When the total switch of the log security check is turned on, the log security check function is turned off through the security processing configuration to improve the response speed of the entire system, solve the problem of slow log printing caused by the sharp increase in traffic during a certain period, and improve the log printing efficiency.
[0126] In an alternative embodiment, the determining module 202 determines whether the total switch of the log security check is turned on, including:
[0127] Determine the parameter identifier corresponding to the total switch of the log security check;
[0128] When the value corresponding to the parameter identifier is the first preset value, it is determined that the total switch of the log security check is turned on; or
[0129] When the value corresponding to the parameter identifier is the second preset value, it is determined that the total switch of the log security check is turned off.
[0130] In this embodiment, the parameter identifier may be safeCheck, and it is determined whether safeCheck is turned on.
[0131] In this embodiment, the first preset value may be "safeCheck = TRUE", and the second preset value may be "safeCheck = FALSE".
[0132] The obtaining module 203 is configured to obtain the log to be printed from the dependency package when the total switch of the log security check is turned on.
[0133] In this embodiment, the log to be printed contains the parameter to be printed.
[0134] In an alternative embodiment, when the total switch of the log security check is turned on, the obtaining module 203 obtains the log to be printed from the dependency package, including:
[0135] Parse the dependency package to obtain the identifier to be printed;
[0136] Based on the identifier to be printed, obtain the log to be printed from the dependency package.
[0137] In some other alternative embodiments, when the total switch of the log security check is turned on, if the log to be printed obtained from the dependency package is empty, the log printing ends.
[0138] In some other alternative embodiments, when the total switch of the log security check is turned on, if the log to be printed obtained from the dependency package is abnormal, the log printing ends.
[0139] In this embodiment, when it is determined that the total switch for log security verification is turned on, it is determined that security processing needs to be performed on the log to be printed.
[0140] The security processing module 204 is configured to perform security processing on the log to be printed to obtain a target printed log.
[0141] In this embodiment, the target printed log refers to the log after security processing of the log to be printed.
[0142] In an optional embodiment, the security processing module 204 performing security processing on the log to be printed to obtain a target printed log includes:
[0143] Identifying the parameter type of the parameter to be printed in the log to be printed;
[0144] When the parameter type of the parameter to be printed in the log to be printed is the ordinary string type, identifying special characters in the log to be printed and deleting the special characters from the log to be printed to obtain a target printed log; or
[0145] When the parameter type of the parameter to be printed in the log to be printed is a non-ordinary string type, serializing the log to be printed to obtain a target printed log.
[0146] In this embodiment, the parameter types include two categories, one is the ordinary string type, and the other is the non-ordinary string type. Different security processing methods are adopted for different parameter types, which is more targeted, thereby improving the security processing efficiency of the log to be printed and further improving the printing efficiency of the log.
[0147] Further, the serializing the log to be printed includes:
[0148] Serializing the log to be printed according to a preset first method;
[0149] When the serialization of the log to be printed is successful, determining the serialized log to be printed as the target printed log; or
[0150] When the serialization of the log to be printed fails, processing the log to be printed by using a preset second method and determining the processed log to be printed as the target printed log.
[0151] In this embodiment, the preset first method may be: JSON serialization, and the preset second method may be: try{}catch(Exception){} processing, where the try{}catch(Exception){}.
[0152] In this embodiment, the special characters can be \r, \n and other pre-set characteristic characters.
[0153] In this embodiment, when logging is printed, there may be printing vulnerabilities. If the string submitted by the client "val" is: "twenty-one", the following entry will be recorded in the log: INFO: Failed to parse val=twenty-one. However, if the attacker submits the string: "twenty-one%0a%0aINFO:+User+logged+out%3dbadguy", the following entry will be recorded in the log: INFO: User logged out=badguy. Obviously, malicious users can use the same mechanism to insert arbitrary log entries, resulting in low security and accuracy of log printing.
[0154] In this embodiment, by securely processing the log to be printed: "twenty-one" as "twentyone", malicious users cannot insert "twentyone" into the log entry. By securely processing the log to be printed, the problem that malicious users use the same mechanism to insert arbitrary log entries is solved, and the security and accuracy of log printing are improved.
[0155] In this embodiment, the latest open-source serialization tool FastJSON is adopted. By traversing all the getter methods in the class object, the object is serialized into a json string. During this process, the special characters encountered will be escaped to ensure that the serialized string is secure. At the same time, during the serialization process of the log to be printed, there may be two situations: serialization failure and success. When the serialization fails, it is determined that there may be a problem that some of the logs to be printed are unreasonable. To solve the problem of unreasonable logs to be printed, some logs to be printed that cannot be JSON serialized are securely processed by adopting a preset second method to obtain the target print log that can be printed.
[0156] The log printing module 205 is used to print the target print log according to the log printing method corresponding to the log printing request.
[0157] In this embodiment, by securely processing the log to be printed before printing and securely processing the special characters involved, the problem that the log to be printed is attacked by malicious users is prevented. At the same time, the log printing method on the class object is called to print the target print log, avoiding the phenomenon that the printing result is inconsistent due to changing the log printing method in the original log printing framework, and improving the security of log printing.
[0158] In an optional embodiment, the log printing module 205 performs log printing on the target print log according to the log printing method corresponding to the log printing request, including:
[0159] Loading the print request into a custom print factory class, and performing security format processing on the parameters to be printed in the target print log;
[0160] Forwarding the target print log after security format processing to the class object in the dependency package;
[0161] Invoking the log printing method on the class object to print the target print log.
[0162] Further, after performing log printing on the target print log according to the log printing method corresponding to the log printing request, the acquisition module 203 is further configured to provide an entry point through the log printing framework Log4j2, and acquire a preset file directory in the resource file.
[0163] The creation module 206 is configured to create a log file to be printed under the file directory, and insert a special record into the log file to be printed by using a preset decorator design pattern to generate a log to be printed, where the value in the special record is a class object of the custom log to be printed.
[0164] The injection module 207 is configured to inject the class object of the log to be printed into the Log4j2 log framework through the log file to be printed, and generate a corresponding dependency package.
[0165] In this embodiment, after performing log printing on the target print log according to the log printing method corresponding to the log printing request, an entry point is provided through the log printing framework Log4j2, and a file: log4j.component.properties is created under the META-INF directory of the resource file, and a special record: log4j2.messageFactory = cn.ping.hczlife.log.FlexibleLog4jMessageFactory is inserted into the log4j.component.properties file by using the decorator design pattern, where the value corresponding to the special record: "cn.ping.hczlife.log.FlexibleLog4jMessageFactory" is a custom parameter printing object, that is, a class object of the log to be printed.
[0166] In this embodiment, inserting a special record through the decorator design pattern does not change the original class file, dynamically realizes the extended object function, and improves the security of the log to be printed.
[0167] In this embodiment, the generated dependency package is made into a scaffolding and uploaded to the Maven server. When relevant business developers perform log printing, they only need to introduce this maven dependency in the pom file of the corresponding project, without any code changes, achieving zero code injection to complete the secure log printing function, improving the security and efficiency of subsequent log printing.
[0168] The log printing module 205 is further configured to, when the total switch of the log security check is turned off, obtain the log to be printed from the dependency package and perform log printing on the log to be printed.
[0169] In this embodiment, when the total switch of the log security check is turned off, it is determined that the log to be printed in the dependency package does not need to be securely processed, and the log printing is directly executed.
[0170] In this embodiment, by determining whether the total switch of the log security check is turned on, it is possible to avoid securely processing some logs to be printed that do not require security processing, improving the printing efficiency and accuracy of the logs to be printed.
[0171] In summary, for the log printing device based on artificial intelligence described in this embodiment, by parsing the received log printing request, the dependency package of the log to be printed is obtained. Since the dependency package is directly obtained through the log object to be printed, the client does not need to modify any code, ensuring the efficiency of the obtained log to be printed. Determine whether the total switch of the log security check is turned on. When the total switch of the log security check is turned on, the log security check function is turned off through the security processing configuration to improve the response speed of the entire system, solving the problem of slow log printing caused by a sudden increase in traffic during a certain period of time and improving the log printing efficiency. When the total switch of the log security check is turned on, the log to be printed is obtained from the dependency package, and the log to be printed is securely processed to obtain the target printed log. By securely processing the log to be printed, the problem of malicious users inserting arbitrary log entries using the same mechanism is solved, improving the security and accuracy of log printing. The target printed log is printed according to the log printing method corresponding to the log printing request, avoiding the phenomenon of inconsistent printing results caused by changing the log printing method in the original log printing framework and improving the security of log printing.
[0172] Embodiment Three
[0173] Refer to Figure 3 As shown in the figure, it is a schematic structural diagram of an electronic device provided in Embodiment Three of the present invention. In a preferred embodiment of the present invention, the electronic device 3 includes a memory 31, at least one processor 32, at least one communication bus 33, and a transceiver 34.
[0174] Those skilled in the art should understand that Figure 3 the structure of the illustrated electronic device does not constitute a limitation on the embodiments of the present invention. It can be a bus structure or a star structure. The electronic device 3 may also include more or fewer other hardware or software than shown in the figure, or different component arrangements.
[0175] In some embodiments, the electronic device 3 is an electronic device capable of automatically performing numerical calculations and / or information processing according to pre-set or stored instructions. Its hardware includes but is not limited to microprocessors, application-specific integrated circuits, programmable gate arrays, digital signal processors, and embedded devices, etc. The electronic device 3 may also include a client device, and the client device includes but is not limited to any electronic product that can perform human-computer interaction with the client through means such as a keyboard, mouse, remote control, touchpad, or voice control device. For example, a personal computer, a tablet computer, a smart phone, a digital camera, etc.
[0176] It should be noted that the electronic device 3 is only an example. Other existing or future possible electronic products that can be adapted to the present invention should also be included within the protection scope of the present invention and are hereby incorporated by reference.
[0177] In some embodiments, the memory 31 is used to store program codes and various data, such as the artificial intelligence-based log printing device 20 installed in the electronic device 3, and realizes high-speed and automatic access to programs or data during the operation of the electronic device 3. The memory 31 includes a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), a one-time programmable read-only memory (OTPROM), an electrically-erasable programmable read-only memory (EEPROM), a compact disc read-only memory (CD-ROM), or other optical disc memories, magnetic disk memories, tape memories, or any other computer-readable medium that can be used to carry or store data.
[0178] In some embodiments, the at least one processor 32 may be composed of integrated circuits. For example, it may be composed of a single packaged integrated circuit, or may be composed of multiple packaged integrated circuits with the same or different functions, including a combination of one or more central processing units (CPUs), microprocessors, digital processing chips, graphics processors, and various control chips. The at least one processor 32 is the control core (Control Unit) of the electronic device 3, connecting various components of the entire electronic device 3 through various interfaces and circuits, and executing various functions of the electronic device 3 and processing data by running or executing programs or modules stored in the memory 31 and calling data stored in the memory 31.
[0179] In some embodiments, the at least one communication bus 33 is arranged to enable connection communication between the memory 31 and the at least one processor 32, etc.
[0180] Although not shown, the electronic device 3 may further include a power source (such as a battery) for powering each component. Optionally, the power source may be logically connected to the at least one processor 32 through a power management device, so as to implement functions such as management of charging, discharging, and power consumption management through the power management device. The power source may further include any components such as one or more DC or AC power sources, a recharge device, a power failure detection circuit, a power converter or inverter, and a power status indicator. The electronic device 3 may further include various sensors, a Bluetooth module, a Wi-Fi module, etc., which will not be elaborated here.
[0181] It should be understood that the embodiments are only for illustration purposes and are not limited by this structure in the scope of the patent application.
[0182] The above-mentioned integrated units implemented in the form of software function modules may be stored in a computer-readable storage medium. The above-mentioned software function modules are stored in a storage medium and include several instructions for causing a computer device (which may be a personal computer, an electronic device, or a network device, etc.) or a processor to execute parts of the methods described in various embodiments of the present invention.
[0183] In a further embodiment, in combination with Figure 2 , the at least one processor 32 can execute the operating device of the electronic device 3 and various installed application programs (such as the above-mentioned artificial intelligence-based log printing device 20), program codes, etc. For example, the above-mentioned various modules.
[0184] The memory 31 stores program codes, and the at least one processor 32 can call the program codes stored in the memory 31 to perform related functions. For example, Figure 2 Each of the modules described in [reference] is a program code stored in the memory 31 and executed by the at least one processor 32, so as to implement the functions of the respective modules to achieve the purpose of artificial intelligence-based log printing.
[0185] Exemplarily, the program code can be split into one or more modules / units. The one or more modules / units are stored in the memory 31 and executed by the processor 32 to complete this application. The one or more modules / units can be a series of computer-readable instruction segments capable of performing specific functions, and the instruction segments are used to describe the execution process of the program code in the electronic device 3. For example, the program code can be split into a parsing module 201, a judgment module 202, an acquisition module 203, a security processing module 204, a log printing module 205, a creation module 206, and an injection module 207.
[0186] In an embodiment of the present invention, the memory 31 stores a plurality of computer-readable instructions, and the plurality of computer-readable instructions are executed by the at least one processor 32 to implement the function of artificial intelligence-based log printing.
[0187] Specifically, for the specific implementation method of the above instructions by the at least one processor 32, reference can be made to Figure 1 the description of the relevant steps in the corresponding embodiment, which will not be elaborated here.
[0188] In several embodiments provided by the present invention, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of the modules is only a logical function division, and there can be other division methods in actual implementation.
[0189] The modules described as separate components may or may not be physically separated. The components shown as modules may or may not be physical units. They can be located in one place or distributed to multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0190] In addition, in each embodiment of the present invention, the various functional modules can be integrated in one processing unit, or each unit can exist physically alone, or two or more units can be integrated in one unit. The above integrated units can be implemented in the form of hardware or in the form of hardware plus software functional modules.
[0191] For those skilled in the art, it is obvious that the present invention is not limited to the details of the above-described exemplary embodiments, and the present invention can be implemented in other specific forms without departing from the spirit or basic characteristics of the present invention. Therefore, from any point of view, the embodiments should be regarded as exemplary and non-limiting. The scope of the present invention is defined by the appended claims rather than the above description. Therefore, all changes falling within the meaning and scope of the equivalent elements of the claims are intended to be embraced by the present invention. Any reference signs in the claims should not be construed as limiting the claims involved. In addition, it is obvious that the term "including" does not exclude other units, and the singular does not exclude the plural. The multiple units or devices described in the present invention can also be implemented by one unit or device through software or hardware. The terms such as "first" and "second" are used to indicate names and do not represent any specific order.
[0192] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and not to limit them. Although the present invention has been described in detail with reference to the preferred embodiments, those of ordinary skill in the art should understand that the technical solutions of the present invention can be modified or equivalently replaced without departing from the spirit and scope of the technical solutions of the present invention.
Claims
1. A log printing method based on artificial intelligence, characterized in that, The method includes: Parsing the received log printing request to obtain the dependency package of the log to be printed, including: parsing the received log printing request to obtain message information; extracting the log object to be printed from the message information, and obtaining the dependency package of the log to be printed based on the log object to be printed, where the dependency package contains class objects and the log to be printed; Judging whether the overall switch of log security verification is turned on; When the overall switch of log security verification is turned on, obtaining the log to be printed from the dependency package and determining that security processing needs to be performed on the log to be printed; Performing security processing on the log to be printed to obtain the target printed log, including: identifying the parameter type of the parameter to be printed in the log to be printed; when the parameter type of the parameter to be printed in the log to be printed is the ordinary string type, identifying the special characters in the log to be printed and deleting the special characters from the log to be printed to obtain the target printed log; or when the parameter type of the parameter to be printed in the log to be printed is a non-ordinary string type, serializing the log to be printed to obtain the target printed log, and the serializing the log to be printed includes: serializing the log to be printed according to a preset first method; when the serialization of the log to be printed is successful, determining the serialized log to be printed as the target printed log; or when the serialization of the log to be printed fails, processing the log to be printed by a preset second method and determining the processed log to be printed as the target printed log; Performing log printing on the target printed log according to the log printing method corresponding to the log printing request.
2. The method for printing logs based on artificial intelligence according to claim 1, wherein The performing log printing on the target printed log according to the log printing method corresponding to the log printing request includes: Loading the printing request into a custom printing factory class and performing security format processing on the parameter to be printed in the target printed log; Forwarding the target printed log after security format processing to the class object in the dependency package; Invoking the log printing method on the class object to print the target printed log.
3. The method for printing logs based on artificial intelligence according to claim 1, wherein, After performing log printing on the target printed log according to the log printing method corresponding to the log printing request, the method further includes: Providing a pointcut through the log printing framework Log4j2 and obtaining a preset file directory in the resource file; Creating a log file to be printed under the file directory and inserting special records into the log file to be printed by using a preset decorator design pattern to generate the log to be printed, where the value in the special record is the class object of the custom log to be printed; Injecting the class object of the log to be printed into the Log4j2 log framework through the log file to be printed to generate a corresponding dependency package.
4. The method for printing logs based on artificial intelligence according to claim 1, wherein The obtaining the log to be printed from the dependency package when the overall switch of log security verification is turned on includes: Parsing the dependency package to obtain the print identifier; Obtaining the log to be printed from the dependency package based on the print identifier.
5. The log printing method based on artificial intelligence according to claim 1, wherein The judging whether the overall switch of log security verification is turned on includes: Determine the parameter identifier corresponding to the total switch of the log security check; When the value corresponding to the parameter identifier is the first preset value, determine that the total switch of the log security check is turned on; or When the value corresponding to the parameter identifier is the second preset value, determine that the total switch of the log security check is turned off.
6. An artificial intelligence-based log printing device, characterized in that, The device includes: A parsing module, configured to parse the received log printing request to obtain the dependency package of the log to be printed, including: parsing the received log printing request to obtain message information; extracting the log object to be printed from the message information, and obtaining the dependency package of the log to be printed based on the log object to be printed, where the dependency package contains a class object and the log to be printed; A judgment module, configured to judge whether the total switch of the log security check is turned on; An obtaining module, configured to, when the total switch of the log security check is turned on, obtain the log to be printed from the dependency package and determine that security processing needs to be performed on the log to be printed; A security processing module, configured to perform security processing on the log to be printed to obtain a target printed log, including: identifying the parameter type of the parameter to be printed in the log to be printed; when the parameter type of the parameter to be printed in the log to be printed is a common string type, identifying the special characters in the log to be printed and deleting the special characters from the log to be printed to obtain a target printed log; or when the parameter type of the parameter to be printed in the log to be printed is a non-common string type, serializing the log to be printed to obtain a target printed log, and the serializing the log to be printed includes: serializing the log to be printed according to a preset first method; when the serialization of the log to be printed is successful, determining the serialized log to be printed as the target printed log; or when the serialization of the log to be printed fails, processing the log to be printed by using a preset second method and determining the processed log to be printed as the target printed log; A log printing module, configured to perform log printing on the target printed log according to the log printing method corresponding to the log printing request.
7. An electronic device, characterized in that, The electronic device includes a processor and a memory, and the processor is configured to implement the artificial intelligence-based log printing method according to any one of claims 1 to 5 when executing the computer program stored in the memory.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that, The computer program, when executed by the processor, implements the artificial intelligence-based log printing method according to any one of claims 1 to 5.
Citation Information
Patent Citations
Voice data processing method, electronic equipment and computer readable storage medium
CN113033191A
Log file processing method and device
CN113468613A