Log printing method and related equipment
By identifying the business scenario identifier at the application entrance and determining the dynamic debugging component configuration in the processing channel, the problem of the log library being unable to accurately output logs in the existing technology is solved, accurate log printing in specific scenarios is achieved, and system resource utilization and operating efficiency are improved.
Patent Information
- Application Number
- CN202211243195.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-10-11
- Publication Date
- 2025-09-16
- Estimated Expiration
- 2042-10-11
AI Technical Summary
Existing open source log library components are unable to accurately output logs in specific business scenarios in application systems, resulting in waste of system resources and reduced operating efficiency.
By identifying the business scenario identifier at the application entrance and determining whether to configure the dynamic debugging component in the unified processing channel, combined with the dynamic debugging flag and information response log printing request, accurate log output for specific scenarios can be achieved.
It realizes the ability to accurately output the required logs in specific scenarios, reduces system resource consumption and the risk of log printing blockage, and improves system resource utilization and operating efficiency.
Smart Images

Figure CN115543234B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a log printing method and related equipment. Background Art
[0002] Application system log printing is a crucial way to record information about system operations. It's used to observe system operations and troubleshoot and locate faults, making it a crucial tool for system maintenance. Common logging methods include simple file output or the use of mature open-source logging libraries. Open-source logging libraries offer a wide range of logging capabilities, and are typically implemented by invoking a logger.
[0003] However, while open-source logging library components support the naming of loggers and the adjustment and filtering of log levels, these functions are coarse-grained. For example, during the invocation of an application system, some common code will appear repeatedly in multiple business scenarios. When a problem occurs in an application system, the application system may be abnormal in a specific business scenario but normal in other business scenarios. In this case, traditional coarse-grained logging methods require enabling all logging functions of this common code, and are unable to enable the logger in a specific business scenario. In the case of very high business volume, enabling the logging function will instantly generate a large number of log records in the system, resulting in a waste of system resources and, in severe cases, even a significant decrease in system operating efficiency. Summary of the Invention
[0004] In view of this, the present application proposes a log printing method and related equipment, which can realize the ability to accurately output the logs required for a specific scenario, thereby achieving the purpose of printing specific scenario logs at a lower cost of system resource consumption. By dynamically debugging and processing log printing, the risk of log printing blockage is reduced, and the utilization rate and operation efficiency of system resources are improved.
[0005] According to one aspect of the present application, a log printing method is provided, the method comprising: receiving a log printing request; identifying each business scenario corresponding to the input data at the application entry, and obtaining multiple business scenario identifiers corresponding to each business scenario; inputting the multiple business scenario identifiers into a unified processing channel, and respectively judging whether each of the business scenario identifiers is configured with a dynamic debugging component, wherein: if the business scenario identifier is configured with a dynamic debugging component, setting a first dynamic debugging flag corresponding to the business scenario identifier; if the business scenario identifier is configured without a dynamic debugging component, detecting whether the input data is configured with dynamic debugging information; and responding to the log printing request based on the first dynamic debugging flag and / or the dynamic debugging information.
[0006] Furthermore, each business scenario corresponding to the input data is identified at the application entrance, and multiple business scenario identifiers corresponding to each business scenario are obtained, including: obtaining multiple business parameters corresponding to all business scenarios, and pre-storing the multiple business parameters in a database; identifying the current business scenarios based on at least one of the business parameters in the input data; and obtaining multiple business scenario identifiers corresponding to the current business scenarios at the application entrance.
[0007] Furthermore, the dynamic debugging component is arranged in the processing channel, and the multiple business scenario identifiers are input into a unified processing channel, and it is judged whether each of the business scenario identifiers is configured with a corresponding dynamic debugging component, including: obtaining multiple functional components corresponding to each of the business scenario identifiers; judging whether each of the functional components accesses the relevant attributes of the processing channel, wherein: if the functional component accesses the relevant attributes of the processing channel, then when the processing channel calls the functional component, the functional component is correspondingly configured with a dynamic debugging component; if the functional component cannot access the relevant attributes of the processing channel, then when the processing channel calls the functional component, the functional component is correspondingly configured without a dynamic debugging component.
[0008] Furthermore, the processing channel entrance is provided with a dynamic debugging switch. If the business scenario identifier corresponds to a configuration without a dynamic debugging component, the input data is detected as to whether dynamic debugging information is provided correspondingly, including: judging whether to turn on the dynamic debugging switch based on the input data, wherein: when the dynamic debugging switch is turned on, the input data is provided with dynamic debugging information correspondingly; when the dynamic debugging switch is turned off, the input data is provided with no dynamic debugging information correspondingly.
[0009] Furthermore, responding to the log printing request based on the first dynamic debugging flag and / or the dynamic debugging information includes: determining whether the first dynamic debugging flag is equal to a preset first dynamic debugging flag threshold, wherein: if the first dynamic debugging flag is equal to the preset first dynamic debugging flag threshold, printing the business scenario log corresponding to the first dynamic debugging flag; if the first dynamic debugging flag is not equal to the preset first dynamic debugging flag threshold, executing the next step code of the application.
[0010] Furthermore, responding to the log printing request based on the first dynamic debugging flag and / or the dynamic debugging information also includes: judging whether the input data corresponds to dynamic debugging information, wherein: if the input data corresponds to no dynamic debugging information, setting a second dynamic debugging flag corresponding to the input data; if the input data corresponds to dynamic debugging information, setting the first dynamic debugging flag; in the case of setting the second dynamic debugging flag corresponding to the input data, judging whether the second dynamic debugging flag is equal to a preset second dynamic debugging flag threshold, wherein: if the second dynamic debugging flag is equal to the preset second dynamic debugging flag threshold, printing the business scenario log corresponding to the second dynamic debugging flag; if the second dynamic debugging flag is not equal to the preset second dynamic debugging flag threshold, executing the next step code of the application.
[0011] Furthermore, the log printing method further includes: acquiring a log framework corresponding to the application; and calling the log framework based on the first dynamic debugging flag and / or the dynamic debugging information to print a target business scenario log.
[0012] According to another aspect of the present application, a log printing device is provided, which includes: a receiving module for receiving a log printing request; an identification acquisition module for identifying each business scenario corresponding to the input data at the application entrance, and obtaining multiple business scenario identifications corresponding to each business scenario; a judgment module for inputting the multiple business scenario identifications into a unified processing channel, and respectively judging whether each of the business scenario identifications is configured with a dynamic debugging component, wherein: if the business scenario identification is configured with a dynamic debugging component, a first dynamic debugging flag corresponding to the business scenario identification is set; if the business scenario identification is configured without a dynamic debugging component, it is detected whether the input data is set with dynamic debugging information; a printing module for responding to the log printing request based on the first dynamic debugging flag and / or the dynamic debugging information.
[0013] According to another aspect of the present application, a computer-readable medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the log printing method is implemented.
[0014] According to another aspect of the present application, an electronic device is provided, comprising: one or more processors; a storage device for storing one or more programs, which, when executed by the one or more processors, enables the one or more processors to implement the log printing method.
[0015] By identifying the business scenarios corresponding to the input data at the application entrance, multiple business scenario identifiers corresponding to the business scenarios are obtained, and the multiple business scenario identifiers are input into a unified processing channel. It is judged whether each of the business scenario identifiers is configured with a dynamic debugging component. When the business scenario identifier is configured with a dynamic debugging component, a first dynamic debugging flag corresponding to the business scenario identifier is set. When the business scenario identifier is configured without a dynamic debugging component, it is detected whether the input data is configured with dynamic debugging information. Finally, based on the first dynamic debugging flag and / or the dynamic debugging information, the log printing request is responded to. According to various aspects of the present application, the ability to accurately output the log required for a specific scenario can be achieved, thereby achieving the purpose of printing a specific scenario log at a lower cost of system resource consumption. By dynamically debugging the log printing, the risk of log printing blockage is reduced, and the utilization rate and operation efficiency of system resources are improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] The following detailed description of the specific embodiments of the present application in conjunction with the accompanying drawings will make the technical solutions and other beneficial effects of the present application apparent.
[0017] Figure 1 A flow chart showing a log printing method according to an embodiment of the present application is shown.
[0018] Figure 2 A schematic diagram illustrating a log printing method according to an embodiment of the present application.
[0019] Figure 3 A block diagram showing a log printing device according to an embodiment of the present application.
[0020] Figure 4 A schematic structural diagram of an electronic device according to an embodiment of the present application is shown. DETAILED DESCRIPTION
[0021] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the embodiments described are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without making creative efforts are within the scope of protection of this application.
[0022] In the description of the present application, it should be understood that the terms "center", "longitudinal", "lateral", "length", "width", "thickness", "up", "down", "front", "back", "left", "right", "vertical", "horizontal", "top", "bottom", "inside", "outside", "clockwise", "counterclockwise" and the like indicate orientations or positional relationships based on the orientations or positional relationships shown in the accompanying drawings, and are only for the convenience of describing the present application and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as limiting the present application. In addition, the terms "first" and "second" are used for descriptive purposes only and cannot be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features defined as "first" and "second" may explicitly or implicitly include one or more of the said features. In the description of the present application, "multiple" means two or more, unless otherwise clearly and specifically defined.
[0023] In the description of this application, it should be noted that, unless otherwise expressly specified or limited, the terms "installed," "connected," and "connected" should be understood in a broad sense. For example, they can refer to fixed connections, detachable connections, or integral connections; they can refer to mechanical connections, electrical connections, or mutual communication; they can refer to direct connections or indirect connections through an intermediate medium; they can refer to internal communication between two components or the interaction between two components. Those skilled in the art will understand the specific meanings of the above terms in this application based on specific circumstances.
[0024] The disclosure below provides many different embodiments or examples for realizing different structures of the present application. In order to simplify the disclosure of the present application, the components and settings of specific examples are described below. Of course, they are merely examples and are not intended to limit the present application. In addition, the present application may repeat reference numbers and / or reference letters in different examples, and such repetition is for the purpose of simplicity and clarity and does not in itself indicate the relationship between the various embodiments and / or settings discussed. In addition, examples of various specific processes and materials are provided in the present application, but those of ordinary skill in the art will appreciate the application of other processes and / or the use of other materials. In some instances, methods, means, components and circuits well known to those skilled in the art are not described in detail in order to highlight the subject matter of the present application.
[0025] Figure 1 Flowchart showing the log printing method of the embodiment of the present application. Figure 1 As shown, the log printing method may include:
[0026] Step S1: receiving a log printing request;
[0027] Among them, the log printing request can be issued by the developer who wrote the application, or by the tester who tested the application. For example, the application written by the developer is first sent to the tester for testing. If the test result does not match the expected result, the tester can first print part of the application's log, and use this part of the log to check whether the test anomaly is caused by test-related factors such as the test itself. If the tester confirms that the test anomaly is caused by non-test factors, the developer can be introduced for further inspection. The developer can adjust the level of log output and locate the location of the program anomaly through more comprehensive log analysis, thereby providing support for solving the test anomaly problem.
[0028] In this application, log printing can occur in a variety of business scenarios. For example, some parameters in an application cannot be empty. When these parameters are empty, it indicates that the program has an exception. In this case, it is necessary to print logs related to these parameters to locate the exception. For another example, when debugging an application, it may be difficult to view console information. In this case, it is necessary to record the stack trace in the log so that when the application runs abnormally, the abnormal code can be quickly located.
[0029] Step S2: identifying each business scenario corresponding to the input data at the application entry, and obtaining multiple business scenario identifiers corresponding to each business scenario;
[0030] The application entry point can be the starting point of the application. Since the input data is not processed at the application entry point, the business scenarios corresponding to the input data are identified at the application entry point, making it easy to determine whether the original data input by the application meets expectations.
[0031] The input data may include parameters related to each business scenario, and these parameters can be used to characterize the specific business characteristics of the business scenario. For example, when stack information needs to be recorded in a log, if the input data contains a thread name or stack top related to the stack, it can be determined that one of the business scenarios corresponding to the input data is the location of the code exception. It should be noted that the input data can be a data set, including one or more business scenarios. For each business scenario, a business scenario identifier corresponding to the business scenario can be set to distinguish different business scenarios.
[0032] For example, the business scenario identifier may be a character sequence used to identify the business scenario corresponding to the business scenario identifier. For example, business scenario identifier 01 may correspond to a business scenario where the code abnormality position is determined, and business scenario identifier 02 may correspond to a business scenario where a parameter value error is transmitted.
[0033] Furthermore, each business scenario corresponding to the input data is identified at the application entry, and multiple business scenario identifiers corresponding to each business scenario are obtained, including:
[0034] Step S21: Acquire multiple business parameters corresponding to all business scenarios, and pre-store the multiple business parameters in a database;
[0035] In this application, multiple business parameters corresponding to all possible business scenarios can be collected first, and then the multiple business parameters can be pre-processed by methods such as data cleaning, deduplication, and filling in gaps. The pre-processed multiple business parameters can be pre-stored in the database according to the category of the business scenario. In this way, multiple business parameters can be cached in advance to speed up the reading and writing of data.
[0036] Step S22: identifying current business scenarios based on at least one business parameter in the input data;
[0037] Among them, one business scenario can correspond to one business parameter or multiple business parameters, that is, the business scenario of the embodiment of the present application can be characterized by one or more business parameters. It is understood that the present application does not limit the mapping relationship between the business parameters and the business scenarios.
[0038] Step S23: obtaining multiple business scenario identifiers corresponding to the current business scenarios at the application entry.
[0039] When identifying each current business scenario based on at least one business parameter in the input data, multiple business scenario identifiers corresponding to each current business scenario can be obtained based on the mapping relationship between the pre-set business scenario and the corresponding business scenario identifier. In this application, one business scenario corresponds to one business scenario identifier as an example for explanation.
[0040] Step S3: Input the multiple business scenario identifiers into a unified processing channel, and determine whether each business scenario identifier is configured with a corresponding dynamic debugging component, wherein: if the business scenario identifier is configured with a corresponding dynamic debugging component, set a first dynamic debugging flag corresponding to the business scenario identifier; if the business scenario identifier is not configured with a dynamic debugging component, detect whether the input data is configured with dynamic debugging information;
[0041] Among them, the dynamic debugging component can be set in the processing channel. The processing channel is a unified channel that can be used to centrally process the multiple business scenarios. For the present application, the dynamic debugging component can be pre-configured in the processing channel for each business scenario. Of course, for business scenarios that do not require printing, the dynamic debugging component may not be configured in the processing channel. It should be noted that in the present application, the configuration of the dynamic debugging component is dynamic, and whether to configure the dynamic debugging component can be determined according to actual needs. In one example, the dynamic debugging component can be a custom function.
[0042] After the multiple business scenario identifiers are input into a unified processing channel, it can be first determined whether each of the business scenario identifiers is configured with a corresponding dynamic debugging component. If the business scenario identifier is configured with a corresponding dynamic debugging component, it means that the business scenario corresponding to the business scenario identifier needs to be printed. At this time, the first dynamic debugging flag corresponding to the business scenario identifier can be set. The first dynamic debugging flag can be a fixed value. Furthermore, if the business scenario identifier is configured without a dynamic debugging component, it means that the business scenario corresponding to the business scenario identifier does not need to be printed. At this time, it can be further detected whether the input data is configured with dynamic debugging information.
[0043] Therefore, in this application, when dynamic logging needs to be turned on, dynamic logging can be enabled in two ways. The first way is based on the first dynamic debugging flag. Exemplarily, for the first way, the first dynamic debugging flag can be set in the operation management section of a specific business scenario, and all calls of the specific business scenario will print the required logs. The operation management section can be any processing stage in processing the specific business scenario. The second way is based on the dynamic debugging information. The dynamic debugging information is associated with the input data, so other flag bits can also be set in the external input data to enable dynamic logging.
[0044] Both of the above methods can be used to enable the dynamic debugging flag. Compared to the existing technology where the original log library cannot dynamically enable logs, the embodiment of the present application sets two different methods to enable dynamic logging, which can significantly reduce the number of logs printed and the consumption of the system, and achieve fine-grained log printing control.
[0045] Furthermore, the multiple business scenario identifiers are input into a unified processing channel, and it is determined whether each business scenario identifier is correspondingly configured with a dynamic debugging component, including:
[0046] Step S31: Acquire multiple functional components corresponding to each of the business scenario identifiers;
[0047] Step S32: Determine whether each functional component accesses the relevant attributes of the processing channel, wherein: if the functional component accesses the relevant attributes of the processing channel, then when the processing channel calls the functional component, the functional component is correspondingly configured with a dynamic debugging component; if the functional component cannot access the relevant attributes of the processing channel, then when the processing channel calls the functional component, the functional component is correspondingly configured without a dynamic debugging component.
[0048] The functional components are also referred to as functional components. The processing channel may include multiple functional components. When determining whether each business scenario identifier corresponds to a dynamic debugging component, the multiple functional components corresponding to each business scenario identifier may be first obtained, and then it may be determined whether each functional component has access to the relevant attributes of the processing channel. The relevant attributes of the processing channel may be characteristics associated with the processing channel, such as parameter values, content, etc.
[0049] Specifically, if the functional component accesses the relevant properties of the processing channel, it means that the functional component can normally access the relevant properties of the processing channel. At this time, when the processing channel calls the functional component, it can be determined that the functional component is correspondingly configured with a dynamic debugging component. In other words, when the processing channel calls the functional component, the dynamic debugging component can be automatically set on the functional component, so that the functional component can smoothly and automatically obtain the dynamic debugging component. If the functional component cannot access the relevant properties of the processing channel, it means that the functional component cannot access the relevant properties of the processing channel. Then, when the processing channel calls the functional component, it is determined that the functional component is correspondingly configured without a dynamic debugging component. In addition, the dynamic debugging flag of the present application is not passed through the thread context, but is passed through the processing channel and the dedicated properties of the functional component itself.
[0050] Furthermore, the processing channel entrance is provided with a dynamic debugging switch. If the business scenario identifier corresponds to a configuration without a dynamic debugging component, detecting whether the input data corresponds to dynamic debugging information includes:
[0051] Step S321: determining whether to turn on the dynamic debugging switch based on the input data, wherein: if the dynamic debugging switch is turned on, the input data is correspondingly provided with dynamic debugging information; if the dynamic debugging switch is turned off, the input data is correspondingly provided with no dynamic debugging information.
[0052] Specifically, at the configuration entry of the processing channel, the embodiment of the present application can set the logic of the dynamic debugging switch according to the specific business scenario. This facilitates further judgment on whether dynamic debugging is set in the input data when needed. Among them, when the dynamic debugging switch is turned on, it indicates that the input data corresponding to the current business scenario is set with dynamic debugging information; when the dynamic debugging switch is turned off, it indicates that the input data corresponding to the current business scenario is not set with dynamic debugging information.
[0053] Step S4: responding to the log printing request based on the first dynamic debugging flag and / or the dynamic debugging information.
[0054] In this application, responding to the log printing request based on the first dynamic debugging flag and responding to the log printing request based on the dynamic debugging information are two different log printing methods, which can be replaced with each other or performed simultaneously. It is worth noting that for responding to the log printing request based on the dynamic debugging information, further judgment can be made on the dynamic log.
[0055] Further, responding to the log printing request based on the first dynamic debugging flag and / or the dynamic debugging information includes:
[0056] Step S41: Determine whether the first dynamic debugging flag is equal to a preset first dynamic debugging flag threshold, wherein: if the first dynamic debugging flag is equal to the preset first dynamic debugging flag threshold, print the business scenario log corresponding to the first dynamic debugging flag; if the first dynamic debugging flag is not equal to the preset first dynamic debugging flag threshold, execute the next step code of the application.
[0057] The first dynamic debugging flag threshold can be pre-set to verify whether the first dynamic debugging flag corresponds to the first dynamic debugging flag of the target scenario that needs to be printed. Specifically, if the first dynamic debugging flag is equal to the preset first dynamic debugging flag threshold, it indicates that the business scenario corresponding to the first dynamic debugging flag needs to be printed, and the business scenario log corresponding to the first dynamic debugging flag is printed. If the first dynamic debugging flag is not equal to the preset first dynamic debugging flag threshold, it indicates that the business scenario corresponding to the first dynamic debugging flag does not need to be printed, and the application can jump to the next step of code.
[0058] Further, responding to the log printing request based on the first dynamic debugging flag and / or the dynamic debugging information further includes:
[0059] Step S42: determining whether the input data is set with dynamic debugging information, wherein: if the input data is not set with dynamic debugging information, setting a second dynamic debugging flag corresponding to the input data; if the input data is set with dynamic debugging information, setting the first dynamic debugging flag;
[0060] The second dynamic debugging flag can be set in the input data and identified by the code portion of the application. In the present application, determining whether the input data has corresponding dynamic debugging information can be a prerequisite for setting the corresponding second dynamic debugging flag. The second dynamic debugging flag corresponding to the input data is set only if the input data has no corresponding dynamic debugging information; otherwise, the first dynamic debugging flag is set.
[0061] Step S43: When a second dynamic debugging flag corresponding to the input data is set, it is determined whether the second dynamic debugging flag is equal to a preset second dynamic debugging flag threshold, wherein: if the second dynamic debugging flag is equal to the preset second dynamic debugging flag threshold, the business scenario log corresponding to the second dynamic debugging flag is printed; if the second dynamic debugging flag is not equal to the preset second dynamic debugging flag threshold, the next step code of the application is executed.
[0062] The processing of step S43 is similar to that of step S41, except that step S43 processes the second dynamic debugging flag. In practical applications, the log print request can be responded to based on the first dynamic debugging flag and / or the second dynamic debugging flag. The second dynamic debugging threshold can be equal to the first dynamic debugging threshold, or can be set as needed.
[0063] Step S52: calling the log framework based on the first dynamic debugging flag and / or the dynamic debugging information to print a target business scenario log.
[0064] Figure 2 A schematic diagram illustrating a log printing method according to an embodiment of the present application.
[0065] like Figure 2As shown, in one example, external input data can be received first, and then a business scenario identifier can be obtained based on the external input data, and then it can be detected whether the business scenario corresponding to the business scenario identifier is configured with dynamic debugging. Specifically, it can be determined whether the business scenario is configured with dynamic debugging by determining whether the business scenario identifier corresponds to a dynamic debugging component. In the case that the business scenario corresponding to the business scenario identifier is configured with dynamic debugging, a first dynamic debugging flag can be set, and then it can be determined whether the first dynamic debugging flag is equal to a preset threshold. If the first dynamic debugging flag is equal to the preset threshold, a log is recorded; if the first dynamic debugging flag is equal to the preset threshold, other function codes are executed.
[0066] If the business scenario corresponding to the business scenario identifier does not have dynamic debugging configured, the process can jump to another branch to determine whether the input information includes a dynamic debugging flag. Specifically, the process can determine whether the input information includes a dynamic debugging flag by determining whether the input data is configured with dynamic debugging information. If the input information includes a dynamic debugging flag, the dynamic debugging flag is compared with a preset threshold. If the input information does not include a dynamic debugging flag, a second dynamic debugging flag is set and compared with a preset threshold. The preset threshold here can be either the first dynamic debugging flag threshold or the second dynamic debugging flag threshold.
[0067] Furthermore, the log printing method further includes:
[0068] Step S51: Obtain the log framework corresponding to the application;
[0069] Exemplarily, the logging framework may be the Log4j logging framework. The Log4j logging framework may be used to control the destination of log information output, such as a console or file, and may also be used to control the output format of each log entry. Parameters such as the destination and output format of log information output may be flexibly configured via a log configuration file without modifying the application software code. The Log4j logging framework may include components such as a logger, an outputter, and a formatter.
[0070] Loggers are used to control the output level of logs. In one example, the output levels of logs can be ranked from high to low as follows: OFF, FATAL, ERROR, WARN, INFO, DEBUG, TRACE, ALL. OFF is the highest level, which means turning off all log recording switches; FATAL means outputting fatal errors; ERROR means outputting error information; WARN means outputting warning information; INFO means outputting prompt information; DEBUG means outputting debugging information; TRACE means outputting tracing information; ALL is the lowest level, which means turning on all log recording switches. In actual applications, in order to streamline the printed content of the log, the output level of the log can also be set to level five or level four. It can be understood that this application does not limit the output level of the log.
[0071] Appenders are used to write log information to a target destination. For example, a console appender writes log information to the console, a file appender writes log information to a specified file, a split file appender writes log information to multiple files, and a database appender writes log information to a database table.
[0072] A formatter (Layout) receives log information output by an outputter and formats it into a target style. For example, a simple formatter can output log information in a simple format, such as INFO level messages; a custom formatter can return formatted log information based on a custom conversion pattern.
[0073] Furthermore, through the above-mentioned fine-grained log printing control method, the application system can flexibly enable logs in specific business scenarios after it goes online. Taking into account the basic capabilities provided by the log library, the embodiment of the present application can also achieve multiple levels of log content and range control. Specifically, the embodiment of the present application can adjust the log level of a specific logger, thereby recording all logs within the influence range of the logger; it can also turn on the dynamic debugging switch of a specific business scenario in the business scenario configuration, and all subsequent calls to this business scenario will record relevant logs. In the application system, general configuration switches can take effect dynamically, which means that after the switch takes effect, if there are multiple transactions in this business scenario, the processing of each business will record the relevant process log.
[0074] For example, during a specific business call, if the initiator modifies a preset identifiable flag in the input information and sets it to a state that enables dynamic logging, the application system will then record relevant logs when processing that business transaction. In this case, only the log for one transaction is recorded, and it will not be associated with subsequent business processing. If the input information for the next business transaction does not include the specific flag, the logging behavior will not occur. This allows for dynamic debugging of log processing solutions, combined with the log level adjustment capabilities of the logger in the future open source log library, to achieve dynamic log adjustment capabilities at multiple levels, accurately enable logging capabilities for a single business processing process, and perform more refined and fine-grained log printing, thereby increasing flexibility.
[0075] In summary, compared to the low efficiency of common log recording methods in the prior art, the log printing method proposed in this application can support coarse-grained solutions such as log level adjustment of conventional loggers while also supporting fine-grained log printing control. Specifically, the log printing method proposed in this application can achieve the ability to accurately output the logs required for a specific scenario for that specific scenario, thereby achieving the purpose of printing logs for specific scenarios at a lower cost of system resource consumption without having to enable a wide range of log recording functions. By dynamically debugging log printing, the risk of log printing blockage is reduced, and the utilization rate and operational efficiency of system resources are improved.
[0076] Figure 3 A block diagram showing a log printing device according to an embodiment of the present application.
[0077] like Figure 3 As shown, the log printing device 30 of the embodiment of the present application may include:
[0078] Receiving module 31, used for receiving log printing request;
[0079] An identification acquisition module 32 is used to identify each business scenario corresponding to the input data at the application entrance and obtain multiple business scenario identifications corresponding to each business scenario;
[0080] The judgment module 33 is configured to input the multiple business scenario identifiers into a unified processing channel and respectively judge whether each business scenario identifier is configured with a corresponding dynamic debugging component, wherein: if the business scenario identifier is configured with a corresponding dynamic debugging component, a first dynamic debugging flag corresponding to the business scenario identifier is set; if the business scenario identifier is not configured with a dynamic debugging component, the first dynamic debugging flag corresponding to the business scenario identifier is detected.
[0081] The printing module 34 is configured to respond to the log printing request based on the first dynamic debugging flag and / or the dynamic debugging information.
[0082] In addition, the present application provides a computer-readable medium having a computer program stored thereon, and the computer program implements the log printing method when executed by a processor.
[0083] Furthermore, the present application also provides an electronic device, comprising: one or more processors; a storage device for storing one or more programs, which, when executed by the one or more processors, enables the one or more processors to implement the log printing method.
[0084] Figure 4 A schematic structural diagram of an electronic device according to an embodiment of the present application is shown.
[0085] like Figure 4 As shown, the electronic device can be used to implement the test method based on the business code. Specifically, the electronic device can include a computer system. It should be noted that, Figure 3 The electronic device shown is only an example and should not limit the functions and scope of use of the embodiments of the present application.
[0086] like Figure 4 As shown, the computer system includes a central processing unit (CPU) 1801, which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 1802 or the program loaded from the storage part 1808 into the random access memory (RAM) 1803, such as executing the method described in the above embodiment. Various programs and data required for system operation are also stored in the RAM 1803. The CPU 1801, ROM 1802 and RAM 1803 are connected to each other via a bus 1804. An input / output (I / O) interface 1805 is also connected to the bus 1804.
[0087] The following components are connected to the I / O interface 1805: an input section 1806 including a keyboard, a mouse, and the like; an output section 1807 including devices such as a cathode ray tube (CRT), a liquid crystal display (LCD), and speakers; a storage section 1808 including a hard disk; and a communication section 1809 including a network interface card such as a LAN (Local Area Network) card or a modem. The communication section 1809 performs communication processing via a network such as the Internet. A drive 1810 is also connected to the I / O interface 1805 as needed. Removable media 1811, such as a magnetic disk, an optical disk, a magneto-optical disk, or a semiconductor memory, is installed in the drive 1810 as needed, so that computer programs read from the removable media can be installed in the storage section 1808 as needed.
[0088] In particular, according to an embodiment of the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present application includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a computer program for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network via the communication section 1809, and / or installed from a removable medium 1811. When the computer program is executed by the central processing unit (CPU) 1801, the various functions defined in the system of the present application are executed.
[0089] It should be noted that the computer-readable medium shown in the embodiments of the present application may be a computer-readable signal medium or a computer-readable storage medium or any combination of the two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or component, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM), a flash memory, an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present application, a computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, which carries a computer-readable computer program. Such propagated data signals may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium that can transmit, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. A computer program embodied on a computer-readable medium may be transmitted using any suitable medium, including but not limited to wireless, wired, or any suitable combination thereof.
[0090] The flowcharts and block diagrams in the accompanying drawings illustrate the possible implementation architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present application. Among them, each box in the flowchart or block diagram can represent a module, program segment, or part of the code, and the above-mentioned module, program segment, or part of the code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in an order different from that marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flowchart, and the combination of boxes in the block diagram or flowchart, can be implemented with a dedicated hardware-based system that performs the specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0091] The units involved in the embodiments described in this application may be implemented by software or hardware, and the units described may also be set in a processor. In some cases, the names of these units do not constitute limitations on the units themselves.
[0092] As another aspect, the present application further provides a computer-readable medium, which may be included in the electronic device described in the above embodiments, or may exist independently without being incorporated into the electronic device. The computer-readable medium carries one or more programs, and when the one or more programs are executed by the electronic device, the electronic device implements the method described in the above embodiments.
[0093] It should be noted that, although several modules or units of the device for action execution are mentioned in the above detailed description, this division is not mandatory. In fact, according to the embodiment of the application, the features and functions of two or more modules or units described above can be concretized in one module or unit. On the contrary, the features and functions of one module or unit described above can be further divided into multiple modules or units to be concretized.
[0094] Through the description of the above embodiments, it is easy for those skilled in the art to understand that the example embodiments described herein can be implemented by software or by combining software with necessary hardware. Therefore, the technical solution according to the embodiments of the present application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, and includes several instructions to enable a computing device (which can be a personal computer, a server, a touch terminal, or a network device, etc.) to execute the method according to the embodiments of the present application.
[0095] In the above embodiments, the description of each embodiment has its own focus. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0096] The above is a detailed introduction to the business code-based testing method and related equipment provided in the embodiments of the present application. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the technical solutions and core ideas of the present application; ordinary technicians in this field should understand that they can still modify the technical solutions recorded in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein; and these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present application.
Claims
1. A log printing method, characterized in that: The method comprises: Receive log printing request; Identify each business scenario corresponding to the input data at the application entrance, and obtain multiple business scenario identifiers corresponding to each business scenario; Input the multiple business scenario identifiers into a unified processing channel, and determine whether each of the business scenario identifiers is configured with a corresponding dynamic debugging component, wherein: if the business scenario identifier is configured with a corresponding dynamic debugging component, it means that the business scenario corresponding to the business scenario identifier needs to be printed, and a first dynamic debugging flag corresponding to the business scenario identifier is set; if the business scenario identifier is not configured with a dynamic debugging component, it means that the business scenario corresponding to the business scenario identifier does not need to be printed, and detect whether the input data is configured with dynamic debugging information; Responding to the log printing request based on the first dynamic debugging flag and / or the dynamic debugging information; determining whether the first dynamic debugging flag is equal to a preset first dynamic debugging flag threshold, wherein: if the first dynamic debugging flag is equal to the preset first dynamic debugging flag threshold, printing a business scenario log corresponding to the first dynamic debugging flag; and if the first dynamic debugging flag is not equal to the preset first dynamic debugging flag threshold, executing the next step code of the application; Determining whether the input data corresponds to dynamic debugging information, wherein: if the input data corresponds to no dynamic debugging information, setting a second dynamic debugging flag corresponding to the input data; if the input data corresponds to dynamic debugging information, setting the first dynamic debugging flag; When a second dynamic debugging flag corresponding to the input data is set, whether the second dynamic debugging flag is equal to a preset second dynamic debugging flag threshold is determined, wherein: if the second dynamic debugging flag is equal to the preset second dynamic debugging flag threshold, a business scenario log corresponding to the second dynamic debugging flag is printed; if the second dynamic debugging flag is not equal to the preset second dynamic debugging flag threshold, the next step code of the application is executed.
2. The log printing method according to claim 1, characterized in that: At the application entry point, the business scenarios corresponding to the input data are identified, and multiple business scenario identifiers corresponding to the business scenarios are obtained, including: Obtain multiple business parameters corresponding to all business scenarios, and pre-store the multiple business parameters in a database; identifying current business scenarios according to at least one business parameter in the input data; A plurality of business scenario identifiers corresponding to the current business scenarios are obtained at the application program entry.
3. The log printing method according to claim 1, wherein: The dynamic debugging component is set in the processing channel, the multiple business scenario identifiers are input into a unified processing channel, and each of the business scenario identifiers is judged to determine whether a dynamic debugging component is configured correspondingly, including: Obtain multiple functional components corresponding to each of the business scenario identifiers; Determine whether each of the functional components accesses the relevant properties of the processing channel, wherein: if the functional component accesses the relevant properties of the processing channel, then when the processing channel calls the functional component, the functional component is correspondingly configured with a dynamic debugging component; if the functional component cannot access the relevant properties of the processing channel, then when the processing channel calls the functional component, the functional component is correspondingly configured without a dynamic debugging component.
4. The log printing method according to claim 3, characterized in that: The processing channel entrance is provided with a dynamic debugging switch. If the business scenario identifier corresponds to a configuration without a dynamic debugging component, detecting whether the input data corresponds to dynamic debugging information includes: Determine whether to turn on the dynamic debugging switch according to the input data, wherein: when the dynamic debugging switch is turned on, the input data is correspondingly set with dynamic debugging information; when the dynamic debugging switch is turned off, the input data is correspondingly set without dynamic debugging information.
5. The log printing method according to claim 1, characterized in that: The log printing method further includes: Obtain the log framework corresponding to the application; The log framework is called based on the first dynamic debugging flag and / or the dynamic debugging information to print a target business scenario log.
6. A log printing device, characterized in that: The log printing device includes: Receiving module, used for receiving log printing request; An identification acquisition module is used to identify each business scenario corresponding to the input data at the application entrance and obtain multiple business scenario identifications corresponding to each business scenario; a judgment module, configured to input the multiple business scenario identifiers into a unified processing channel, and respectively judge whether each of the business scenario identifiers is configured with a corresponding dynamic debugging component, wherein: if the business scenario identifier is configured with a corresponding dynamic debugging component, it indicates that the business scenario corresponding to the business scenario identifier needs to be printed, and a first dynamic debugging flag corresponding to the business scenario identifier is set; if the business scenario identifier is not configured with a corresponding dynamic debugging component, it indicates that the business scenario corresponding to the business scenario identifier does not need to be printed, and detect whether the input data is configured with corresponding dynamic debugging information; a printing module, configured to determine whether the first dynamic debugging flag is equal to a preset first dynamic debugging flag threshold, wherein: if the first dynamic debugging flag is equal to the preset first dynamic debugging flag threshold, printing a business scenario log corresponding to the first dynamic debugging flag; and if the first dynamic debugging flag is not equal to the preset first dynamic debugging flag threshold, executing the next step code of the application; Determining whether the input data corresponds to dynamic debugging information, wherein: if the input data corresponds to no dynamic debugging information, setting a second dynamic debugging flag corresponding to the input data; if the input data corresponds to dynamic debugging information, setting the first dynamic debugging flag; When a second dynamic debugging flag corresponding to the input data is set, whether the second dynamic debugging flag is equal to a preset second dynamic debugging flag threshold is determined, wherein: if the second dynamic debugging flag is equal to the preset second dynamic debugging flag threshold, a business scenario log corresponding to the second dynamic debugging flag is printed; if the second dynamic debugging flag is not equal to the preset second dynamic debugging flag threshold, the next step code of the application is executed.
7. A computer-readable medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the log printing method according to any one of claims 1 to 5 is implemented.
8. An electronic device, characterized in that: include: one or more processors; A storage device is used to store one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors implement the log printing method according to any one of claims 1 to 5.
Citation Information
Patent Citations
Log management method, server and computer readable storage medium
CN109471845A
Log printing method and device
CN113778350A