Method and apparatus for adjusting and printing log level of a running system

By dynamically adjusting log levels using matching rules in the runtime system, the problem of not being able to adjust log levels by transaction dimension in existing technologies is solved, enabling flexible configuration and fine-grained management, and reducing system overhead.

CN114218180BActive Publication Date: 2025-10-28CHINA CITIC BANK CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111512114.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-07
Publication Date
2025-10-28
Estimated Expiration
2041-12-07

AI Technical Summary

Technical Problem

Existing technologies cannot dynamically adjust log levels based on transaction dimensions or business characteristics.

Method used

This paper provides a method for adjusting and printing log levels in a runtime system. By obtaining the program type and runtime characteristics, the log level is dynamically adjusted using matching rule information, and feature matching and corresponding operations are performed during program runtime.

Benefits of technology

It enables flexible log level adjustment based on transaction dimensions, provides concrete management, reduces system overhead, and offers granular log printing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114218180B_ABST
    Figure CN114218180B_ABST
Patent Text Reader

Abstract

This invention discloses a method and apparatus for adjusting and printing log levels in a running system. The method involves obtaining the program type and, based on the program type, obtaining first matching rule information. This first matching rule information is a set of rules for adjusting log levels and / or allowing log printing, and includes pre-run matching rules and post-run matching rules. When the program runs, the method obtains the runtime state of the program's runtime characteristics, which are attributes used for rule matching. Feature matching is performed on the program's runtime characteristics according to the first matching rule information. When a match is successful, a first execution instruction is obtained to perform corresponding operations on the program's logs according to the first matching rule information. This solves the technical problem of not being able to dynamically adjust log levels based on transaction dimensions or transaction business characteristics. It achieves the technical effect of dynamically adjusting the application log levels of a running system using matching rules and printing logs in a targeted manner, providing flexible configuration.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer technology, and in particular to a method and apparatus for adjusting and printing log levels in a running system. Background Technology

[0002] Commonly used logging frameworks in the industry include Logback and Log4j. Log4j is an open-source Java-based logging library managed by the Apache Software Foundation. Logback is an open-source Java-based logging library released by Quality Open Software. Both can dynamically modify the global or class-specific log levels at runtime, but they cannot dynamically adjust log levels based on transaction dimensions, nor do they support automatic adjustment of log levels based on transaction business characteristics.

[0003] However, in the process of implementing the inventive technical solution in the embodiments of this application, the inventors of this application discovered that the above-mentioned technology has at least the following technical problems:

[0004] Existing technologies have a technical problem that they cannot dynamically adjust log levels based on transaction dimensions or business characteristics. Summary of the Invention

[0005] This application provides a method and apparatus for adjusting and printing log levels in a runtime system, solving the technical problem in the prior art where log levels cannot be dynamically adjusted according to transaction dimensions or business characteristics. It achieves the technical effect of dynamically adjusting application log levels in a runtime system using matching rules, printing logs in a targeted manner, providing flexible configuration, enabling refined and concrete management of application logs, and significantly reducing the system overhead of enabling all logs.

[0006] In view of the above problems, this application proposes a method and apparatus for adjusting and printing the log level of a running system.

[0007] In a first aspect, embodiments of this application provide a method for adjusting and printing log levels in a running system. The method includes: obtaining a program type, wherein the program is an application in the running system; obtaining first matching rule information based on the program type, wherein the first matching rule information is a set of rules for adjusting log levels and / or allowing log printing, and the first matching rule information includes pre-run matching rules and post-run matching rules; obtaining program runtime features when the program is running, wherein the program runtime features are the runtime states of attributes used for rule matching in the program; performing feature matching on the program runtime features according to the first matching rule information; and obtaining a first execution instruction when a match is successful, wherein the first execution instruction is to perform corresponding operations on the program's logs according to the first matching rule information.

[0008] Preferably, before performing feature matching on the program runtime features according to the first matching rule information, the method includes: obtaining the running range according to the first matching rule information; and loading the first matching rule information into the corresponding storage space for management according to the running range.

[0009] Preferably, the method includes: obtaining system layering information; setting log gatekeepers at each layer, wherein the log gatekeepers can control the operation of the matching rule information; obtaining incoming data; performing data matching on the incoming data according to the matching rule information; and when the matching is successful, obtaining a second execution instruction, wherein the second execution instruction is to adjust the corresponding thread-level log level to the desired level at each layer entry point and restore the thread-level log level at the exit point.

[0010] Preferably, the log gatekeeper has an alarm interface connected to an alarm control center. The method includes: obtaining a program exception event; obtaining first alarm information based on the program exception event, wherein the first alarm information is used to report the program exception location and entry data to the alarm control center via the alarm interface and store them in an alarm record; analyzing the alarm record through the alarm control center to obtain a first data feature value; sending the first data feature value to the log gatekeeper for feature value update; obtaining a second matching rule based on the first data feature value; and obtaining a third execution instruction based on the second matching rule, wherein the third execution instruction is used to automatically adjust the corresponding log level to the expected log level when matching the first data feature value.

[0011] Preferably, in this embodiment of the application, the log gatekeepers of the same level share an externally configurable feature matcher. The log gatekeepers call the feature matcher in sequence. The method includes: obtaining the incoming data; the feature matcher extracting features from the incoming data to obtain a second data feature value; performing feature value matching according to the second data feature value and the second matching rule; when the second data feature value satisfies the second matching rule, obtaining a fourth execution instruction, the fourth execution instruction being used to modify the relevant log level to the expected log level according to the matching result.

[0012] Preferably, the method includes: obtaining a predetermined number of matches; when the number of times the specific data value matches the matching rule successfully reaches the predetermined number of matches, obtaining a first cancellation instruction, wherein the first cancellation instruction is used to automatically cancel the feature matcher.

[0013] Preferably, the method includes: obtaining the status of the log gatekeeper; when the log gatekeeper is enabled, determining whether the current program type enables the log gatekeeper; when the current program type enables the log gatekeeper, obtaining a first matching instruction, the first matching instruction being used to match the matching rule in the system according to the current program type; obtaining a third matching rule according to the first matching instruction, the third matching rule being all pre-run matching rules corresponding to the current program type; performing feature matching on the program runtime features according to the third matching rule to obtain a third matching result; when the third matching result is a successful match, obtaining a fifth execution instruction, the fifth execution... The instructions are as follows: Adjust the log level of the current program execution thread to the expected level, and cache the logs that meet the expected level and those that do not meet the global default log level in memory. When the third matching result is a mismatch, a sixth execution instruction is obtained. This sixth execution instruction determines whether the characteristics of the program's execution result match the post-run matching rules of the current program type after the current program finishes running. Based on the sixth execution instruction, a fourth matching result is obtained. Based on the fourth matching result, a seventh execution instruction is obtained. This seventh execution instruction prints the program's cached logs when the fourth matching result is a successful match, and clears the current program's cached logs when the fourth matching result is a mismatch.

[0014] Prior to this, when the third matching result is a successful match, after obtaining the fifth execution instruction, the process includes: executing the sixth execution instruction before the current program finishes running; obtaining a first recovery instruction based on the sixth execution instruction, wherein the first recovery instruction is used to restore the current program execution thread to its original log level after the sixth execution instruction is completed.

[0015] On the other hand, this application also provides an apparatus for adjusting and printing the log level of a running system, the apparatus comprising:

[0016] The first obtaining unit is used to obtain the program type, wherein the program is an application program in the running system.

[0017] The second obtaining unit is configured to obtain first matching rule information according to the program type, wherein the first matching rule information is a set of rules for adjusting the log level and / or allowing log printing, and the first matching rule information includes pre-run matching rules and post-run matching rules;

[0018] The third obtaining unit is used to obtain program runtime features when the program is running, wherein the program runtime features are the runtime states of attributes used for rule matching in the program.

[0019] A first matching unit is configured to perform feature matching on the program runtime features according to the first matching rule information;

[0020] The fourth obtaining unit is used to obtain a first execution instruction when a match is successful. The first execution instruction is to perform corresponding operations on the program's log according to the first matching rule information.

[0021] Preferably, the device further includes:

[0022] The fifth obtaining unit is used to obtain the operating range based on the first matching rule information;

[0023] The first execution unit is configured to load the first matching rule information into the corresponding storage space for management according to the operating range.

[0024] Preferably, the device further includes:

[0025] The sixth obtaining unit is used to obtain system layer information and set log gatekeepers at each layer. The log gatekeepers can control the operation of the matching rule information.

[0026] The seventh obtaining unit is used to obtain the incoming data;

[0027] The second matching unit is used to perform data matching on the incoming data according to the matching rule information;

[0028] The eighth obtaining unit is used to obtain a second execution instruction when a match is successful. The second execution instruction is to adjust the corresponding thread-level log level to the desired level at each layer entry point and restore the thread-level log level at the exit point.

[0029] Preferably, the device further includes:

[0030] The ninth obtaining unit is used to obtain program exception events;

[0031] The tenth obtaining unit is used to obtain first alarm information based on the program abnormal event. The first alarm information is used to report the program abnormal location and entry data to the alarm control center and save it in the alarm record through the alarm interface connection.

[0032] The eleventh obtaining unit is used to analyze the alarm record through the alarm control center to obtain the first data feature value;

[0033] The second execution unit is used to send the first data feature value to the log gatekeeper for feature value update, and obtain the second matching rule based on the first data feature value;

[0034] The twelfth obtaining unit is used to obtain a third execution instruction according to the second matching rule. The third execution instruction is used to automatically adjust the corresponding log level to the expected log level when matching the first data feature value.

[0035] Preferably, the device further includes:

[0036] The thirteenth obtaining unit is used to obtain the incoming data;

[0037] The fourteenth obtaining unit is used by the feature matcher to extract features from the incoming data and obtain a second data feature value;

[0038] The third matching unit is used to perform feature value matching based on the second data feature value and the second matching rule;

[0039] The fifteenth obtaining unit is used to obtain a fourth execution instruction when the second data feature value satisfies the second matching rule. The fourth execution instruction is used to modify the relevant log level to the expected log level according to the matching result.

[0040] Preferably, the device further includes:

[0041] The sixteenth obtaining unit is used to obtain a predetermined number of matches;

[0042] The seventeenth obtaining unit is used to obtain a first cancellation instruction when the number of times the specific value of the data matches the matching rule successfully reaches the predetermined number of matches. The first cancellation instruction is used to automatically cancel the feature matcher.

[0043] Preferably, the device further includes:

[0044] The eighteenth obtaining unit is used to obtain the status of the log gatekeeper;

[0045] The first judgment unit is used to determine whether the log gatekeeper is enabled in the current program type when the log gatekeeper is enabled.

[0046] The nineteenth obtaining unit is used to obtain a first matching instruction when the current program type enables the log gatekeeper. The first matching instruction is used to match the matching rule in the system according to the current program type.

[0047] The twentieth obtaining unit is used to obtain a third matching rule according to the first matching instruction. The third matching rule is all the pre-run matching rules corresponding to the current program type.

[0048] The 21st obtaining unit is used to perform feature matching on the program runtime features according to the third matching rule and obtain the third matching result.

[0049] The 22nd obtaining unit is used to obtain a fifth execution instruction when the third matching result is a successful match. The fifth execution instruction is to adjust the log level of the current program execution thread to the expected level and cache the logs that meet the expected level and do not meet the global default log level in memory during program execution.

[0050] The 23rd obtaining unit is used to obtain a sixth execution instruction when the third matching result is a mismatch. The sixth execution instruction is to determine whether the program running result characteristics match the running matching rules of the current program type after the current program runs.

[0051] The 24th obtaining unit is used to obtain the fourth matching result according to the sixth execution instruction;

[0052] The 25th obtaining unit is used to obtain a 7th execution instruction based on the 4th matching result. The 7th execution instruction is to print the program's cache log when the 4th matching result is a successful match, and to clear the current program's cache log when the 4th matching result is a mismatch.

[0053] Preferably, the device further includes:

[0054] The third execution unit is used to execute the sixth execution instruction before the current program finishes running;

[0055] The 26th obtaining unit is used to obtain a first recovery instruction according to the sixth execution instruction. The first recovery instruction is used to restore the current program execution thread to the original log level after the sixth execution instruction is completed.

[0056] Thirdly, the present invention provides an apparatus for adjusting and printing log levels of a running system, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the steps of the method described in any of the first aspects.

[0057] One or more technical solutions provided in the embodiments of this application have at least the following technical effects or advantages:

[0058] This application provides a method and apparatus for adjusting and printing log levels in a running system. The method involves obtaining a program type, where the program is an application in the running system; obtaining first matching rule information based on the program type, wherein the first matching rule information is a set of rules for adjusting log levels and / or allowing log printing, and includes pre-run matching rules and post-run matching rules; obtaining program runtime characteristics when the program is running, where the program runtime characteristics are the runtime states of attributes used for rule matching in the program; performing feature matching on the program runtime characteristics according to the first matching rule information; and obtaining a first execution instruction when a match is successful, whereby the first execution instruction performs corresponding operations on the program's logs according to the first matching rule information. This method achieves dynamic adjustment of application log levels in a running system using matching rules and targeted log printing, offering flexible configuration, refined and concrete management of application logs, and significantly reducing the system overhead of enabling all logs. This solves the technical problem in the prior art where log levels cannot be dynamically adjusted according to transaction dimensions or business characteristics of transactions.

[0059] The above description is only an overview of the technical solution of this application. In order to better understand the technical means of this application and to implement it in accordance with the contents of the specification, and to make the above and other objects, features and advantages of this application more obvious and understandable, the following are specific embodiments of this application. Attached Figure Description

[0060] Figure 1 This is a flowchart illustrating a method for adjusting and printing log levels in a running system according to an embodiment of this application.

[0061] Figure 2 This is a schematic diagram of a device for adjusting and printing log levels in a running system, according to an embodiment of this application.

[0062] Figure 3 This is a schematic diagram of the structure of an exemplary electronic device according to an embodiment of this application.

[0063] Explanation of reference numerals in the attached drawings: First obtaining unit 11, Second obtaining unit 12, Third obtaining unit 13, First matching unit 14, Fourth obtaining unit 15, Bus 300, Receiver 301, Processor 302, Transmitter 303, Memory 304, Bus interface 306. Detailed Implementation

[0064] This application provides a method and apparatus for adjusting and printing log levels in a runtime system, solving the technical problem in the prior art where log levels cannot be dynamically adjusted according to transaction dimensions or business characteristics. It achieves the technical effect of dynamically adjusting application log levels in a runtime system using matching rules, printing logs in a targeted manner, providing flexible configuration, enabling refined and concrete management of application logs, and significantly reducing the system overhead of enabling all logs.

[0065] The following describes in detail exemplary embodiments according to the present application with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of the present application, and not all of the embodiments of the present application. It should be understood that the present application is not limited to the exemplary embodiments described herein.

[0066] Application Overview

[0067] Commonly used logging frameworks in the industry include Logback and Log4j. Log4j is an open-source Java-based logging library managed by the Apache Software Foundation. Logback is an open-source Java-based logging library released by Quality Open Software. Both can dynamically modify the global or class-specific log levels at runtime, but they cannot dynamically adjust log levels based on transaction dimensions, nor do they support automatic adjustment of log levels based on transaction business characteristics.

[0068] To address the aforementioned technical problems, the overall approach of the technical solution provided in this application is as follows:

[0069] This application provides a method for adjusting and printing log levels in a running system. The method involves obtaining a program type, where the program is an application in the running system; obtaining first matching rule information based on the program type, wherein the first matching rule information is a set of rules for adjusting log levels and / or allowing log printing, and includes pre-run matching rules and post-run matching rules; obtaining program runtime characteristics when the program is running, where the program runtime characteristics are the runtime states of attributes used for rule matching in the program; performing feature matching on the program runtime characteristics according to the first matching rule information; and obtaining a first execution instruction when a match is successful, whereby the first execution instruction performs corresponding operations on the program's logs according to the first matching rule information. This method achieves the technical effect of dynamically adjusting the application log level of the running system using matching rules, and printing logs in a targeted manner. It offers flexible configuration, enables refined and concrete management of application logs, and significantly reduces the system overhead of enabling all logs.

[0070] After introducing the basic principles of this application, various non-limiting embodiments of this application will be described in detail below with reference to the accompanying drawings.

[0071] Example 1

[0072] Figure 1 This is a flowchart illustrating a method for adjusting and printing log levels in a running system according to an embodiment of this application. Figure 1 As shown in the embodiment of this application, a method for adjusting and printing the log level of a running system is provided, the method including:

[0073] Step 100: Obtain the program type, where the program is an application program in the running system.

[0074] Step 200: Based on the program type, obtain first matching rule information, wherein the first matching rule information is a set of rules for adjusting the log level and / or allowing log printing, and the first matching rule information includes pre-run matching rules and post-run matching rules.

[0075] Specifically, the program type refers to a certain type of application. A set of matching rules is pre-defined based on the program type and its state characteristics. These matching rules can be based on the business characteristics of runtime transactions, targeting specific users, transactions, times, and operational rules. Rules are set according to application characteristics within the matching rules. When a matching characteristic is found, the corresponding log level is dynamically adjusted or targeted logs are printed according to the matching rules. For example, when a certain type of program encounters a certain type of runtime error, the corresponding error output details its location and the program's runtime log are printed. Matching rules can be set with trigger rules based on business rules. Once a rule matches, the transaction log level can be dynamically adjusted. Matching rules can also be flexibly configured according to rule execution cycles and scopes, different transaction characteristics, and custom rules can also be defined. Furthermore, matching rules include pre-run matching rules and post-run matching rules. The rules corresponding to dynamically adjusting log levels are runtime matching rules, as they are performed before the program runs. The matching rules for log alerts and targeted log printing are post-run matching rules, as they are performed after the program runs. In this embodiment, the first matching rule information is a set of rules that allow logging. For example, it could be periodic logging or logging at a specified time interval; it could also be a filtering rule for attribute values ​​during program execution; or it could be the timing of rule execution, such as matching rules before, after, or both before and after program execution.

[0076] Step 300: When the program is running, obtain the program runtime features, which are the runtime states of the attributes used for rule matching in the program.

[0077] Step 400: Perform feature matching on the program runtime features according to the first matching rule information.

[0078] Step 500: When a match is successful, obtain the first execution instruction, which is to perform corresponding operations on the program's log according to the first matching rule information.

[0079] Specifically, the system determines whether the program's runtime characteristics match the matching rules corresponding to the program type. If they do not match, the program executes normally. If they match, the system performs corresponding operations according to the matching rule information. For example, it adjusts the log level of the executing thread to the desired level, or prints the required information when a specified printing rule is matched, or outputs the context characteristics and prints the program's runtime log when a runtime error occurs in a program of a specified type. This targeted printing provides the location and characteristics of the error context, facilitating developers' analysis and troubleshooting. Furthermore, it eliminates the need to restore and print all program or runtime logs for the entire runtime period, significantly reducing system output and saving system overhead. This application's embodiment achieves dynamic adjustment of runtime system application log levels using matching rules and targeted log printing. It offers flexible configuration, refined and concrete management of application logs, and significantly reduces the system overhead of enabling all logs. This solves the technical problem in existing technologies where log levels cannot be dynamically adjusted based on transaction dimensions or business characteristics.

[0080] Furthermore, before performing feature matching on the program runtime features based on the first matching rule information, the embodiments of this application include:

[0081] Step 610: Obtain the operating range based on the first matching rule information;

[0082] Step 620: Based on the operating range, load the first matching rule information into the corresponding storage space for management.

[0083] Specifically, a program type can have multiple matching rules. At system startup, these predefined matching rules can be loaded into local memory or other storage (such as a database or Redis) for management, based on the rule's scope (e.g., local or cluster). During system runtime, the corresponding matching rules are queried and retrieved from the storage space according to the program type.

[0084] Furthermore, embodiments of this application also include:

[0085] Step 710: Obtain system layer information, set log gatekeepers at each layer, and the log gatekeepers can control the operation of the matching rule information;

[0086] Step 720: Obtain entry data;

[0087] Step 730: Perform data matching on the incoming data according to the matching rule information;

[0088] Step 740: When a match is successful, a second execution instruction is obtained. The second execution instruction is to adjust the corresponding thread-level log level to the desired level at each layer entry point and restore the thread-level log level at the exit point.

[0089] Specifically, depending on the layering of the application system, log gatekeepers can be set at each level. The portal saves the incoming data in the context. Once the matching rules are defined and enabled, the incoming data must be matched by the gatekeeper's rules. At the entry point of each level, the corresponding thread-level log level is adjusted according to the matching results, and at the exit point, the corresponding thread-level log level is restored.

[0090] Furthermore, the log gatekeeper has an alarm interface, which is connected to an alarm control center. This application embodiment includes:

[0091] Step 810: Obtain program exception events;

[0092] Step 820: Based on the program abnormal event, obtain the first alarm information. The first alarm information is used to report the program abnormal location and entry data to the alarm control center through the alarm interface and save it in the alarm record.

[0093] Step 830: The alarm control center analyzes the alarm records to obtain the first data feature value;

[0094] Step 840: Send the first data feature value to the log gatekeeper for feature value update, and obtain the second matching rule based on the first data feature value;

[0095] Step 850: According to the second matching rule, obtain a third execution instruction, which is used to automatically adjust the corresponding log level to the expected log level when matching the first data feature value.

[0096] Specifically, each level of gatekeeper is registered and managed by a global gatekeeper manager, which also provides a full-stack alarm interface. Each gatekeeper provides an alarm interface; once a specified program error (abnormal event) occurs, the gatekeeper reports the error location and entry data to a centralized alarm control center. The alarm control center records and analyzes the alarm data, automatically analyzing historical alarm data online to extract characteristic values ​​(such as a request originating from a specific client, a specific transaction code, or a specific customer number), and then sending these values ​​back to the log gatekeeper as the second matching rule. Subsequently, when matching this characteristic value, the gatekeeper automatically adjusts the corresponding transaction log level to the expected log level.

[0097] Furthermore, log gatekeepers at the same level share an externally configurable feature matcher, and the log gatekeepers call the feature matcher sequentially. This application embodiment includes:

[0098] Step 910: Obtain the entry data;

[0099] Step 920: The feature matcher extracts features from the incoming data to obtain second data feature values;

[0100] Step 930: Perform feature value matching based on the second data feature value and the second matching rule;

[0101] Step 940: When the second data feature value satisfies the second matching rule, a fourth execution instruction is obtained. The fourth execution instruction is used to modify the relevant log level to the expected log level according to the matching result.

[0102] Furthermore, embodiments of this application include:

[0103] Step 1010: Obtain the predetermined number of matches;

[0104] Step 1020: When the number of times the specific value of the data successfully matches the matching rule reaches the predetermined number of matches, a first cancellation instruction is obtained. The first cancellation instruction is used to automatically cancel the feature matcher.

[0105] Specifically, guards at the same level share a set of externally configurable feature matchers. Guards will sequentially call the interfaces of the feature matchers configured for their level. The feature matchers extract feature values ​​from the entry data, and when a match is found, the relevant log level (e.g., changed to Debug level) is modified to the expected log level. Feature matchers can be set by operations administrators via commands or automatically by the alarm analysis / control center. Regardless of whether the feature matcher is set automatically by the alarm analysis / control center or by operations administrators via commands, it will automatically deregister after a specified number of feature matches (feature logs captured) to avoid excessive log printing.

[0106] Furthermore, embodiments of this application include:

[0107] Step 1110: Obtain the status of the log gatekeeper;

[0108] Step 1120: When the log gatekeeper is enabled, determine whether the current program type enables the log gatekeeper;

[0109] Step 1130: When the current program type enables the log gatekeeper, a first matching instruction is obtained. The first matching instruction is used to match the matching rule in the system according to the current program type.

[0110] Step 1140: Obtain a third matching rule according to the first matching instruction, wherein the third matching rule is all pre-run matching rules corresponding to the current program type;

[0111] Step 1150: Perform feature matching on the program runtime features according to the third matching rule to obtain the third matching result;

[0112] Step 1160: When the third matching result is a successful match, a fifth execution instruction is obtained. The fifth execution instruction is to adjust the log level of the current program execution thread to the expected level and cache the logs that meet the expected level and do not meet the global default log level in memory.

[0113] Step 1170: When the third matching result is a mismatch, a sixth execution instruction is obtained. The sixth execution instruction is to determine whether the program execution result characteristics match the running matching rules of the current program type after the current program has finished running.

[0114] Step 1180: Obtain the fourth matching result according to the sixth execution instruction;

[0115] Step 1190: Based on the fourth matching result, obtain the seventh execution instruction. The seventh execution instruction is to print the program's cache log when the fourth matching result is a successful match, and to clear the current program's cache log when the fourth matching result is a mismatch.

[0116] Furthermore, in step 1160 of this application embodiment: after obtaining the fifth execution instruction when the third matching result is a successful match, it includes:

[0117] Step 1200: Before the current program finishes running, execute the sixth execution instruction;

[0118] Step 1210: Obtain a first recovery instruction according to the sixth execution instruction. The first recovery instruction is used to restore the current program execution thread to the original log level after the sixth execution instruction is completed.

[0119] Specifically, during runtime, the log gatekeeper processing flow is roughly as follows: Step 1: Check if the log gatekeeper is enabled globally; Step 2: Check if the log gatekeeper is enabled for the current program type; Step 3: Query the matching rules in the local and remote systems for the current program type, and determine whether the program's runtime characteristics match all pre-run matching rules corresponding to the program type. If not, execute the program normally, and execute Step 6 before the end of execution; if a match is found, jump to Step 4; Step 4: Adjust the log level of the execution thread to the desired level; Step 5: Cache all logs that meet the desired level and those that do not meet the global default log level in memory during program runtime; Step 6: After the program finishes running, determine whether the runtime result characteristics match all post-run matching rules for the program type. If not, clear the program's cached logs; if a match is found, and the log gatekeeper was already enabled in Step 3, print the program's cached logs; otherwise, call the alarm interface and automatically set the feature matcher for the current transaction type. Step 7: Restore the original log level of the execution thread.

[0120] Furthermore, an example of the usage scenario of this application embodiment is provided: Error program outputs debug logs: For example, if the program matching rule is: "Transaction code: {rule: AAQRABL, matching before program execution: yes}, username: {rule: All, matching before program execution: yes}, error code: {rule: SCRC807, matching before program execution: no}, maximum number of prints: 2, number of prints already: 0," then at runtime, only programs with transaction code AAQRABL can have their execution thread's log level adjusted by the log gatekeeper; when the program execution ends, only when an execution exception occurs and the error code is SCRC807 can the cached log be output, and the number of prints for the matching rule be updated to 1; finally, the use of the matching rule is disabled through the log gatekeeper. After the number of prints increases to 2, when a program with the same running characteristics appears for the third time, the log gatekeeper will no longer adjust the log level. Through this rule, the fault program can output the scene characteristics more completely, providing convenience for developers to locate the cause of the fault.

[0121] Other common usage scenarios for the matching rules provided in this application's embodiments are as follows:

[0122] 1. A slow transaction trigger debug log will be printed at most once per hour for each transaction;

[0123] 2. All programs print their debug logs every 6 hours;

[0124] In addition, this application also provides support for runtime management of matching rules.

[0125] The matching rule management tool provides the following key interface designs:

[0126] enableRule(matching rule): Sets the on / off flag of the matching rule to true.

[0127] disableRule(matching rule): Sets the on / off flag of the matching rule to false.

[0128] At runtime, if the rule matching switch flag is false during rule matching, the matching will fail.

[0129] addRule(matching rule): Adds a matching rule to the local or remote system.

[0130] deleteRule(matching rule): Clears the matching rule registered on the local or remote system.

[0131] switchOn(program type): Disables the matching rules for the program type.

[0132] switchOff(program type): Enables the matching rules corresponding to the program type.

[0133] At runtime, the switch flag for the program type is managed through the map. If the switch flag for the program type corresponding to the runtime program is off during rule matching, the matching will fail.

[0134] In summary, the core idea of ​​this application's embodiments is to pre-define a set of matching rules for program types and program state characteristics, and then dynamically adjust the log level and print targeted logs for programs that meet the matching rules during system operation.

[0135] To implement the matching rules, we propose designs related to program type, matching rules, log gatekeepers, and program runtime characteristics. Based on the matching rules, we dynamically adjust the runtime system application log level and print logs selectively, enabling flexible configuration and refined, concrete management of application logs, significantly reducing the system overhead of enabling all logging. The design concept of this invention is not limited by programming languages ​​or logging tools. It has the following technical effects:

[0136] 1. Supports dynamic restoration of log printing at the time of registration program execution. For example, the program's execution log is only printed when a certain type of program encounters a certain type of runtime error, outputting the context characteristics to facilitate developers in analyzing and locating the cause of the fault; without having to restore the printing of the execution logs of all programs or the entire runtime, thus greatly reducing system I / O.

[0137] 2. Trigger rules can be set according to business rules, and the transaction log level can be dynamically adjusted once the rules are matched.

[0138] 3. Matching rules can be configured according to the rule's operating cycle and range, with different transaction characteristics flexibly configured, and custom rules can also be defined.

[0139] 4. Supports dynamic adjustment of rules and online application during system runtime, without requiring process restart.

[0140] This solves the technical problems of existing technologies being unable to dynamically adjust log levels based on a specific transaction request or to automatically and dynamically adjust log levels according to configurable business rules.

[0141] Example 2

[0142] Based on the same inventive concept as the method for adjusting and printing log levels in a running system described in the foregoing embodiments, this invention also provides an apparatus for adjusting and printing log levels in a running system, such as... Figure 2 As shown, the device includes:

[0143] The first obtaining unit 11 is used to obtain the program type, wherein the program is an application program in the running system.

[0144] The second obtaining unit 12 is used to obtain first matching rule information according to the program type, wherein the first matching rule information is a set of rules for adjusting the log level and / or allowing log printing, and the first matching rule information includes pre-run matching rules and post-run matching rules.

[0145] The third obtaining unit 13 is used to obtain program runtime features when the program is running, wherein the program runtime features are the runtime states of attributes used for rule matching in the program.

[0146] The first matching unit 14 is used to perform feature matching on the program runtime features according to the first matching rule information;

[0147] The fourth obtaining unit 15 is used to obtain a first execution instruction when a match is successful. The first execution instruction is to perform corresponding operations on the program's log according to the first matching rule information.

[0148] Furthermore, the device also includes:

[0149] The fifth obtaining unit is used to obtain the operating range based on the first matching rule information;

[0150] The first execution unit is configured to load the first matching rule information into the corresponding storage space for management according to the operating range.

[0151] Furthermore, the device also includes:

[0152] The sixth obtaining unit is used to obtain system layer information and set log gatekeepers at each layer. The log gatekeepers can control the operation of the matching rule information.

[0153] The seventh obtaining unit is used to obtain the incoming data;

[0154] The second matching unit is used to perform data matching on the incoming data according to the matching rule information;

[0155] The eighth obtaining unit is used to obtain a second execution instruction when a match is successful. The second execution instruction is to adjust the corresponding thread-level log level to the desired level at each layer entry point and restore the thread-level log level at the exit point.

[0156] Furthermore, the device also includes:

[0157] The ninth obtaining unit is used to obtain program exception events;

[0158] The tenth obtaining unit is used to obtain first alarm information based on the program abnormal event. The first alarm information is used to report the program abnormal location and entry data to the alarm control center and save it in the alarm record through the alarm interface connection.

[0159] The eleventh obtaining unit is used to analyze the alarm record through the alarm control center to obtain the first data feature value;

[0160] The second execution unit is used to send the first data feature value to the log gatekeeper for feature value update, and obtain the second matching rule based on the first data feature value;

[0161] The twelfth obtaining unit is used to obtain a third execution instruction according to the second matching rule. The third execution instruction is used to automatically adjust the corresponding log level to the expected log level when matching the first data feature value.

[0162] Furthermore, the device also includes:

[0163] The thirteenth obtaining unit is used to obtain the incoming data;

[0164] The fourteenth obtaining unit is used by the feature matcher to extract features from the incoming data and obtain a second data feature value;

[0165] The third matching unit is used to perform feature value matching based on the second data feature value and the second matching rule;

[0166] The fifteenth obtaining unit is used to obtain a fourth execution instruction when the second data feature value satisfies the second matching rule. The fourth execution instruction is used to modify the relevant log level to the expected log level according to the matching result.

[0167] Furthermore, the device also includes:

[0168] The sixteenth obtaining unit is used to obtain a predetermined number of matches;

[0169] The seventeenth obtaining unit is used to obtain a first cancellation instruction when the number of times the specific value of the data matches the matching rule successfully reaches the predetermined number of matches. The first cancellation instruction is used to automatically cancel the feature matcher.

[0170] Furthermore, the device also includes:

[0171] The eighteenth obtaining unit is used to obtain the status of the log gatekeeper;

[0172] The first judgment unit is used to determine whether the log gatekeeper is enabled in the current program type when the log gatekeeper is enabled.

[0173] The nineteenth obtaining unit is used to obtain a first matching instruction when the current program type enables the log gatekeeper. The first matching instruction is used to match the matching rule in the system according to the current program type.

[0174] The twentieth obtaining unit is used to obtain a third matching rule according to the first matching instruction. The third matching rule is all the pre-run matching rules corresponding to the current program type.

[0175] The 21st obtaining unit is used to perform feature matching on the program runtime features according to the third matching rule and obtain the third matching result.

[0176] The 22nd obtaining unit is used to obtain a fifth execution instruction when the third matching result is a successful match. The fifth execution instruction is to adjust the log level of the current program execution thread to the expected level and cache the logs that meet the expected level and do not meet the global default log level in memory during program execution.

[0177] The 23rd obtaining unit is used to obtain a sixth execution instruction when the third matching result is a mismatch. The sixth execution instruction is to determine whether the program running result characteristics match the running matching rules of the current program type after the current program runs.

[0178] The 24th obtaining unit is used to obtain the fourth matching result according to the sixth execution instruction;

[0179] The 25th obtaining unit is used to obtain a 7th execution instruction based on the 4th matching result. The 7th execution instruction is to print the program's cache log when the 4th matching result is a successful match, and to clear the current program's cache log when the 4th matching result is a mismatch.

[0180] Furthermore, the device also includes:

[0181] The third execution unit is used to execute the sixth execution instruction before the current program finishes running;

[0182] The 26th obtaining unit is used to obtain a first recovery instruction according to the sixth execution instruction. The first recovery instruction is used to restore the current program execution thread to the original log level after the sixth execution instruction is completed.

[0183] The foregoing Figure 1 The various variations and specific examples of the method for adjusting and printing the log level of a running system in Embodiment 1 are also applicable to the apparatus for adjusting and printing the log level of a running system in this embodiment. Through the foregoing detailed description of the method for adjusting and printing the log level of a running system, those skilled in the art can clearly understand the implementation method of the apparatus for adjusting and printing the log level of a running system in this embodiment. Therefore, for the sake of brevity, it will not be described in detail here.

[0184] Exemplary electronic devices

[0185] The following is for reference. Figure 3 The electronic device described in the embodiments of this application is used to illustrate this application.

[0186] Figure 3 The figure shows a schematic diagram of the structure of an electronic device according to an embodiment of the present application.

[0187] Based on the inventive concept of the method for adjusting and printing the log level of a running system in the foregoing embodiments, the present invention also provides an apparatus for adjusting and printing the log level of a running system, which stores a computer program that, when executed by a processor, implements the steps of any of the methods of the aforementioned method for adjusting and printing the log level of a running system.

[0188] Among them, Figure 3In this document, a bus architecture (represented by bus 300) is used. Bus 300 may include any number of interconnected buses and bridges, linking various circuits including one or more processors represented by processor 302 and memory represented by memory 304. Bus 300 may also link various other circuits such as peripheral devices, voltage regulators, and power management circuits, which are well known in the art and therefore will not be described further herein. Bus interface 306 provides an interface between bus 300 and receiver 301 and transmitter 303. Receiver 301 and transmitter 303 may be the same element, i.e., a transceiver, providing a unit for communicating with various other systems over a transmission medium.

[0189] The processor 302 is responsible for managing the bus 300 and general processing, while the memory 304 can be used to store the data used by the processor 302 when performing operations.

[0190] The above-described one or more technical solutions in the embodiments of this application have at least one or more of the following technical effects:

[0191] This application provides a method and apparatus for adjusting and printing log levels in a running system. The method involves obtaining a program type, where the program is an application in the running system; obtaining first matching rule information based on the program type, wherein the first matching rule information is a set of rules for adjusting log levels and / or allowing log printing, and includes pre-run matching rules and post-run matching rules; obtaining program runtime characteristics when the program is running, where the program runtime characteristics are the runtime states of attributes used for rule matching in the program; performing feature matching on the program runtime characteristics according to the first matching rule information; and obtaining a first execution instruction when a match is successful, whereby the first execution instruction performs corresponding operations on the program's logs according to the first matching rule information. This method achieves dynamic adjustment of application log levels in a running system using matching rules and targeted log printing, offering flexible configuration, refined and concrete management of application logs, and significantly reducing the system overhead of enabling all logs. This solves the technical problem in the prior art where log levels cannot be dynamically adjusted according to transaction dimensions or business characteristics of transactions.

[0192] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0193] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A system that specifies functions in one or more boxes.

[0194] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0195] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the functions specified in one or more boxes. Although preferred embodiments of the invention have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments as well as all changes and modifications falling within the scope of the invention.

[0196] Obviously, those skilled in the art can make various modifications and variations to this invention without departing from its spirit and scope. Therefore, if these modifications and variations fall within the scope of the claims of this invention and their equivalents, this invention also intends to include these modifications and variations.

Claims

1. A method for adjusting and printing log levels in a running system, wherein, The method includes: Obtain the program type, where the program is an application in a running system; According to the program type, first matching rule information is obtained, wherein the first matching rule information is a set of rules for adjusting the log level and / or allowing log printing, and the first matching rule information includes pre-run matching rules and post-run matching rules. In addition, multiple matching rules will be formulated for one program type. When the program runs, the runtime characteristics of the program are obtained, which are the runtime states of the attributes used for rule matching in the program. The program runtime features are matched according to the first matching rule information; When a match is successful, a first execution instruction is obtained, which is to perform corresponding operations on the program's logs according to the first matching rule information; before performing feature matching on the program's runtime features according to the first matching rule information, the process includes: Based on the first matching rule information, the operating range is obtained; According to the operating range, the first matching rule information is loaded into the corresponding storage space for management; The method further includes obtaining system layer information and setting log gatekeepers at each layer, wherein the log gatekeepers can control the operation of the matching rule information.

2. The method as described in claim 1, wherein, The method includes: Obtain entry data; The incoming data is matched according to the matching rule information; When a match is successful, a second execution instruction is obtained, which is to adjust the corresponding thread-level log level to the desired level at each layer entry point and restore the thread-level log level at the exit point.

3. The method as described in claim 2, wherein, The log guard has an alarm interface, which is connected to an alarm control center. The method includes: Obtain program exception events; Based on the program abnormal event, a first alarm information is obtained. The first alarm information is used to report the program abnormal location and entry data to the alarm control center through the alarm interface and save them in the alarm record. The alarm control center analyzes the alarm records to obtain the first data feature value; The first data feature value is sent to the log gatekeeper for feature value update, and the second matching rule is obtained based on the first data feature value; According to the second matching rule, a third execution instruction is obtained, which is used to automatically adjust the corresponding log level to the expected log level when matching the first data feature value.

4. The method of claim 3, wherein, Log gatekeepers at the same level share an externally configurable feature matcher, and the log gatekeepers call the feature matcher sequentially. The method includes: Obtain the entry data; The feature matcher extracts features from the incoming data to obtain second data feature values; Based on the second data feature value and the second matching rule, feature value matching is performed; When the second data feature value satisfies the second matching rule, a fourth execution instruction is obtained. The fourth execution instruction is used to modify the relevant log level to the expected log level according to the matching result.

5. The method of claim 4, wherein, The method includes: Obtain the predetermined number of matches; When the number of times the second data feature value successfully matches the matching rule reaches the predetermined number of matches, a first cancellation instruction is obtained. The first cancellation instruction is used to automatically cancel the feature matcher.

6. The method of claim 4, wherein, The method includes: Obtain the status of the log guard; When the log gatekeeper is enabled, determine whether the current program type enables the log gatekeeper; When the current program type enables the log gatekeeper, a first matching instruction is obtained. The first matching instruction is used to match the matching rule in the system according to the current program type. Based on the first matching instruction, a third matching rule is obtained, wherein the third matching rule is all pre-run matching rules corresponding to the current program type; The program runtime features are matched according to the third matching rule to obtain the third matching result; When the third matching result is a successful match, a fifth execution instruction is obtained. The fifth execution instruction is to adjust the log level of the current program execution thread to the expected level, and to cache the logs that meet the expected level and do not meet the global default log level in memory. When the third matching result is a mismatch, a sixth execution instruction is obtained. The sixth execution instruction is to determine whether the program execution result characteristics match the running matching rules of the current program type after the current program has finished running. According to the sixth execution instruction, the fourth matching result is obtained; Based on the fourth matching result, a seventh execution instruction is obtained. The seventh execution instruction is to print the program's cache log when the fourth matching result is a successful match, and to clear the current program's cache log when the fourth matching result is a mismatch.

7. The method of claim 6, wherein, When the third matching result is a successful match, after obtaining the fifth execution instruction, the process includes: The sixth execution instruction is executed before the current program finishes running; According to the sixth execution instruction, a first recovery instruction is obtained. The first recovery instruction is used to restore the current program execution thread to the original log level after the sixth execution instruction is completed.

8. A device for adjusting and printing log levels in a running system, wherein, The device includes: The first obtaining unit is used to obtain the program type, wherein the program is an application program in the running system. The second obtaining unit is configured to obtain first matching rule information according to the program type, wherein the first matching rule information is a set of rules for adjusting the log level and / or allowing log printing, and the first matching rule information includes pre-run matching rules and post-run matching rules. In addition, multiple matching rules will be formulated for one program type. The third obtaining unit is used to obtain program runtime features when the program is running, wherein the program runtime features are the runtime states of attributes used for rule matching in the program. A first matching unit is configured to perform feature matching on the program runtime features according to the first matching rule information; The fourth obtaining unit is used to obtain a first execution instruction when a match is successful. The first execution instruction is to perform corresponding operations on the program's log according to the first matching rule information. The device further includes: a fifth obtaining unit, the fifth obtaining unit being used to obtain the operating range based on the first matching rule information; The first execution unit is configured to load the first matching rule information into the corresponding storage space for management according to the operating range; The device further includes a sixth obtaining unit, which is used to obtain system hierarchical information and set log gatekeepers at each layer. The log gatekeepers can control the operation of the matching rule information.

9. An apparatus for adjusting and printing log levels in a running system, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein, When the processor executes the program, it implements the steps of the method according to any one of claims 1-7.

Citation Information

Patent Citations

  • Log printing method and device and log printing system

    CN106909325A

  • Log printing method and device, electronic equipment and storage medium

    CN112130781A