A log control method, device, electronic device and storage medium
By regenerating and loading the attribute configuration file of the log frame in memory, the problem of restarting the system when the log frame attribute modification needs to be modified, and dynamic update of attribute configuration and continuous availability of services are achieved.
Patent Information
- Application Number
- CN202111193001.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-10-13
- Publication Date
- 2025-07-25
- Estimated Expiration
- 2041-10-13
AI Technical Summary
In the prior art, modifying the log framework attribute configuration file requires restarting the system or service, resulting in service interruption and affecting the user experience.
By regenerating the attribute configuration file of the log framework in memory and loading it directly, avoiding restarting the server and realizing dynamic update of attribute configuration.
It realizes flexible modification of log framework properties, avoids server restarts, ensures continuous service availability, and improves user experience.
Smart Images

Figure CN114020714B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular, to a log control method, apparatus, electronic device, and storage medium. Background Art
[0002] When a system or service is put into operation, it is usually in a black box state, and it is unknown what exactly happens during the operation. Generally, the running state can be monitored, the running track can be recorded, and the running details can be understood by means of Log logs, so as to assist in problem discovery and for program debugging and problem solving, etc. Log logs, that is, system and service programs, etc., will generate an event record called log during operation, and each line of the log records descriptions of related operations such as date, time, user, and actions.
[0003] In the related art, if the log does not meet the requirements, it is necessary to modify the property configuration file of the log framework. Since the existing system or service will only load the modified property configuration file when starting up, at this time, it is necessary to temporarily stop the operation of the system or service and restart it to reload the modified property configuration file, resulting in the temporary unavailability of the system or service. Summary of the Invention
[0004] Embodiments of the present invention provide a log control method, apparatus, electronic device, and storage medium to solve the problems in the related art.
[0005] The object of the present invention is achieved through the following technical solutions:
[0006] In a first aspect, embodiments of the present invention provide a log control method, including:
[0007] Determine the current properties of the log framework according to the user's property modification operation for the log framework;
[0008] Regenerate the property configuration file of the log framework in memory according to the current properties of the log framework;
[0009] Call the log framework to load the regenerated property configuration file from the memory to reconfigure the properties of the log framework based on the regenerated property configuration file.
[0010] In a possible implementation manner, it further includes:
[0011] Replace the original property configuration file of the log framework saved in the external memory with the regenerated property configuration file, so that when restarting next time, the log framework is called to load the regenerated property configuration file from the external memory.
[0012] In a possible implementation, replacing the original property configuration file of the log framework saved in the external memory with the regenerated property configuration file includes:
[0013] In response to the user's save modification operation, replacing the original property configuration file of the log framework saved in the external memory with the regenerated property configuration file.
[0014] In a possible implementation, the property modification operation includes at least one of the following:
[0015] An operation of adding a logger;
[0016] An operation of deleting a logger;
[0017] An operation of adding an output target corresponding to a logger;
[0018] An operation of deleting an output target corresponding to a logger;
[0019] An operation of modifying an output target corresponding to a logger;
[0020] An operation of adding, deleting, or modifying the log output format corresponding to the output target corresponding to a logger.
[0021] In a possible implementation, it further includes:
[0022] Determining the modified log level of at least one logger according to the user's log level modification operation for at least one logger in the log framework;
[0023] Modifying the original log level of the at least one logger to the determined log level.
[0024] In a second aspect, an embodiment of the present invention provides a log control device, including:
[0025] A first determination module, configured to determine the current properties of the log framework according to the user's property modification operation for the log framework;
[0026] A configuration generation module, configured to regenerate a property configuration file of the log framework in the memory according to the current properties of the log framework;
[0027] A loading and updating module, configured to call the log framework to load the regenerated property configuration file from the memory to reconfigure the properties of the log framework based on the regenerated property configuration file.
[0028] In a possible implementation, it further includes:
[0029] Configure a replacement module to replace the original property configuration file of the log framework saved in the external memory with the regenerated property configuration file, so that when restarted next time, the log framework is called to load the regenerated property configuration file from the external memory.
[0030] In a possible implementation manner, the configuration replacement module is specifically configured to, in response to a user's save modification operation, replace the original property configuration file of the log framework saved in the external memory with the regenerated property configuration file.
[0031] In a possible implementation manner, the property modification operation includes at least one of the following:
[0032] An operation of adding a logger;
[0033] An operation of deleting a logger;
[0034] An operation of adding an output target corresponding to a logger;
[0035] An operation of deleting an output target corresponding to a logger;
[0036] An operation of modifying an output target corresponding to a logger;
[0037] An operation of adding, deleting, or modifying the log output format corresponding to the output target corresponding to a logger.
[0038] In a possible implementation manner, it further includes:
[0039] A second determination module, configured to determine the log level of at least one logger after modification according to a user's log level modification operation for at least one logger in the log framework;
[0040] A level modification module, configured to modify the original log level of the at least one logger to the determined log level.
[0041] In a third aspect, an embodiment of the present invention provides an electronic device, including: a processor, a memory, and a computer program stored on the memory and executable on the processor. When the computer program is executed by the processor, the steps of the log control method described in any item of the first aspect are implemented.
[0042] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the log control method described in any item of the first aspect are implemented.
[0043] The advantages or beneficial effects in the above technical solutions at least include: Users can modify the properties of the logging framework through property modification operations. After determining the current properties of the logging framework according to the users' property modification operations, based on this, in memory, a property configuration file of the logging framework is regenerated. At this time, the logging framework can be called to directly load the regenerated property configuration file from memory, thereby reconfiguring the properties of the entire logging framework, realizing the modification of the properties of the entire logging framework through the users' property modification operations. In this way, when the users' requirements for logs change, the properties of the entire logging framework can be modified through property modification operations to meet the users' requirements for logs. Since the regenerated property configuration file is directly generated in memory, the logging framework can be directly loaded without restarting the server, avoiding service interruption of the server and making the service continuously available, thereby improving the user experience.
[0044] The above summary is only for the purpose of the specification and is not intended to be limiting in any way. In addition to the illustrative aspects, embodiments, and features described above, further aspects, embodiments, and features of the present invention will be readily apparent by reference to the drawings and the following detailed description. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following will briefly introduce the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings in the following description are only some embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other drawings can be obtained based on these drawings.
[0046] Figure 1 It is a flowchart of an exemplary logging control method provided by an embodiment of the present invention;
[0047] Figure 2 It is a schematic structural diagram of an exemplary logging control device provided by an embodiment of the present invention;
[0048] Figure 3 It is a schematic structural diagram of an exemplary electronic device for implementing the logging control method provided by an embodiment of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0049] The following will clearly and completely describe the technical solutions in the embodiments of the present invention with reference to the drawings in the embodiments of the present invention. Obviously, the described embodiments are some, but not all, of the embodiments of the present invention. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts fall within the protection scope of the present invention.
[0050] Figure 1 This is a flowchart of an exemplary log control method provided by an embodiment of the present invention. As Figure 1 shown, this log control method can be applied to a server and at least includes the following steps:
[0051] Step 101: Determine the current attributes of the log framework according to the user's attribute modification operation on the log framework.
[0052] The log framework is used to record the logs during the operation of the server. In practical applications, the server can provide an accessible operation page for the user. The user can access the operation page provided by the server through a terminal device such as a computer, and then perform an attribute modification operation through this operation page. This attribute modification operation is used to modify the attributes of the log framework. The current attributes of the log framework are the latest attributes of the log framework after the attribute modification operation.
[0053] Step 102: In the memory, regenerate the attribute configuration file of the log framework according to the current attributes of the log framework.
[0054] The memory here can be the memory of the server running the log framework.
[0055] Step 103: Call the log framework to load the regenerated attribute configuration file from the memory to reconfigure the attributes of the log framework based on the regenerated attribute configuration file.
[0056] The log framework itself has a loading function. By calling the application programming interface (API) of the log framework, the log framework can be made to load the regenerated attribute configuration file from the memory, thereby reconfiguring the attributes of the log framework.
[0057] In this embodiment, the user can modify the attributes of the log framework through an attribute modification operation. After determining the current attributes of the log framework according to the user's attribute modification operation, based on this, in the memory, the attribute configuration file of the log framework is regenerated. At this time, the log framework can be called to directly load the regenerated attribute configuration file from the memory, thereby reconfiguring the attributes of the entire log framework, realizing the modification of the attributes of the entire log framework through the user's attribute modification operation. In this way, when the user's requirements for logs change, the attributes of the entire log framework can be modified through an attribute modification operation to meet the user's requirements for logs. Since the regenerated attribute configuration file is directly generated in the memory, the log framework can be directly loaded without restarting the server, avoiding service interruption of the server and making the service continuously available, thereby improving the user experience.
[0058] In an exemplary embodiment, the above-mentioned log control method may further include: replacing the original property configuration file of the log framework saved in the external memory with the regenerated property configuration file, so that when restarted next time, the log framework is called to load the regenerated property configuration file from the external memory.
[0059] External memory generally refers to external storage devices, that is, storage devices other than memory and cache. Data can still be saved after power-off. In practical applications, the property configuration file of the log framework is saved in the external memory. When the server is restarted, during the initialization process, the log framework is called to load the property configuration file saved in the external memory into the memory to configure the properties of the log framework.
[0060] In the above embodiment, although the property configuration file in the memory is modified, after the server is restarted, since the data in the memory will be cleared, the property configuration file saved in the external memory will still be loaded, resulting in the modification being invalid. To avoid the modified property configuration file from becoming invalid after restart, in this embodiment, the regenerated property configuration file can be saved to the external memory to replace the original property configuration file saved in the external memory. After restart, the regenerated property configuration file is loaded from the external memory, making it take effect permanently.
[0061] In a possible implementation manner, the replacing the original property configuration file of the log framework saved in the external memory with the regenerated property configuration file may specifically be implemented as follows: in response to the user's save modification operation, the original property configuration file of the log framework saved in the external memory is replaced with the regenerated property configuration file.
[0062] In practical applications, the user can perform a save modification operation through the above operation page. In response to this save modification operation, the server replaces the original property configuration file of the log framework saved in the external memory with the regenerated property configuration file. In this way, the user can flexibly choose whether to save the property configuration file according to needs to make it take effect permanently.
[0063] In an exemplary embodiment, the above-mentioned log framework may be Log4j2, etc. Log4j2, that is, Log For Java, is an open-source project of Apache and is a powerful log component that provides convenient logging. The log framework may include three components: Logger (log recorder), Appender (log output destination, that is, output target), and Layout (log formatting). Among them, the number of Loggers can be at least one. One Logger can correspond to multiple Appenders, and one Appender can correspond to one Layout.
[0064] Among them, Logger is used to collect and process log records. Appender is responsible for the output of logs, that is, where to output. Layout is used to format the output logs, that is, output the logs according to a certain log output format.
[0065] Based on this, the above property modification operations include at least one of the following:
[0066] The operation of adding a logger;
[0067] The operation of deleting a logger;
[0068] The operation of adding an output target corresponding to a logger;
[0069] The operation of deleting an output target corresponding to a logger;
[0070] The operation of modifying an output target corresponding to a logger;
[0071] The operation of adding, deleting, or modifying the log output format corresponding to the output target corresponding to a logger.
[0072] In practical applications, if it is necessary to increase the output of logs for certain method functions, loggers, output targets, and corresponding log output formats can be newly added.
[0073] If you want to cancel the output of logs for certain method functions, you can delete the corresponding loggers, output targets, and corresponding log output formats, etc. At this time, since the loggers, output targets, and corresponding log output formats, etc. have all been deleted, no logs will be recorded for these method functions anymore. In this way, the subsequent log recording and output can be completely stopped. Compared with this method, modifying the log level can only reduce the log information.
[0074] If it is necessary to modify the log output format, the log output format can also be modified separately.
[0075] Among them, in the operation of adding an output target, the output target can be configured as a specified file or a specified database. For the specified database, the connection of the database, information such as the IP port, account password, and interaction protocol of the database need to be configured. If it is necessary to modify the output target, it can also be modified according to the requirements.
[0076] For the operation of modifying the log output format, information such as the id (identity identifier), name, etc. of the Logger for outputting logs, the id and name of the thread, and the output format of the time can be modified.
[0077] In this embodiment, the property modification operation of the log framework can be flexibly performed according to the needs to meet the user's requirements for logs.
[0078] In an exemplary embodiment, the above-mentioned log control method may further include: determining the modified log level of at least one logger in the log framework according to the user's log level modification operation for at least one logger in the log framework; modifying the original log level of the at least one logger to the determined log level.
[0079] In practical applications, the user can perform a log level modification operation through the above operation page to modify the log level for certain loggers. That is, in addition to being able to modify the attributes of the entire log framework, local modifications such as the log level of loggers can also be made. The modification method is more flexible. This kind of modification is simple to operate and has a high usage frequency. For example, when there is a function exception, it is necessary to modify the log level to view the log details of different levels.
[0080] The log levels may include OFF (off), FATAL (fatal), ERROR (error), WARN (warning), INFO (information), DEBUG (debug), ALL (all).
[0081] If the recorded logs are too detailed, a large amount of log data will occupy and consume server resources, which will have a certain impact on performance; if the recorded logs are too concise, the log information is too simple to clearly and completely record the details of the program running, making it difficult to troubleshoot problems, taking too long, and difficult to locate the cause, etc.
[0082] For example, if there is a problem with an online project and it is necessary to view the logs, but the online logs are at the INFO level and detailed log information cannot be queried. It is necessary to modify the log level to DEBUG. The logger will record more detailed log information. After troubleshooting the problem, modify the log level back to INFO, and the logger will record a small amount of key log information.
[0083] Based on this, the determined log level is higher than the original log level; or, the determined log level is lower than the original log level. In this way, it is convenient for the user to adjust the log level of the logger as needed.
[0084] Exemplarily, during the traffic flat peak, the logger can be made to only output a small amount of key logs at the INFO level; when encountering problems, the logger can output detailed logs at the DEBUG level to quickly locate and solve the problems; during the traffic peak period, the INFO level logs can be turned off, and only the ERROR level logs are retained to improve the load capacity of the core service to ensure the availability of the core service.
[0085] In practical applications, a package contains at least one class, and a class contains at least one method function. Each class can set at least one logger to record the logs of the contained method functions. For example, a class can set one logger to record the logs of all the method functions it contains, or multiple loggers can be used to separately record the logs of multiple method functions. Then, the above-mentioned at least one logger can include a logger corresponding to at least one package, or a logger corresponding to at least one class, or a logger corresponding to at least one method function. That is to say, the scope of the logger targeted by the level modification operation can be different. One can choose to modify the log levels of all loggers corresponding to the global (i.e., all method functions), or choose to modify the log levels of the loggers corresponding to certain packages, or choose to modify the log levels of the loggers corresponding to certain classes, or choose to modify the log levels of the loggers corresponding to certain method functions, and so on.
[0086] In an exemplary embodiment, the log control method provided by the embodiments of the present invention can be encapsulated into an SDK plugin. This SDK plugin is installed on the server. Taking a specific application scenario as an example below, the specific implementation process of the SDK plugin will be described.
[0087] In this embodiment, the SDK plugin includes a management background and a log controller.
[0088] Among them, the management background provides an entry for the modification operation through an operation page. A user can log in to the operation page provided by the management background through a terminal device such as a computer. After the user performs an attribute modification operation on the operation page provided by the management background, the management background interface will call the log controller in the server. At this time, the log controller will perform corresponding processing.
[0089] Specifically, the log controller determines the current attributes of the log framework according to the user's attribute modification operation. According to the current attributes of the log framework, it dynamically generates an attribute configuration file of the log framework in xml format in memory. The log controller calls the log framework to reload the regenerated attribute configuration file, thereby dynamically changing the attribute configuration of the log framework in the service.
[0090] At the same time, if it is selected to save the attribute configuration file, the log controller will write the regenerated attribute configuration file to the external memory of the server, overwriting the original attribute configuration file in the external memory, which can be the attribute configuration file at initialization or the attribute configuration file generated subsequently. Even if the server is restarted, the regenerated attribute configuration file can still take effect permanently.
[0091] In this way, the properties of the entire logging framework can be modified dynamically, achieving more powerful and flexible configuration, supporting the custom modification of multiple properties, and being applicable to complex and special usage scenarios. For example, it is required that the logging configuration takes effect permanently, or it is necessary to output the logs of a certain functional module or a certain time period to a specified database or file, such as dynamically adding and deleting Loggers.
[0092] In addition, the operation page provided by the management background is also used to view the modified log level in real time and perform operations to modify the log level. The log controller is used to modify the original log level of the logger to a determined log level.
[0093] When the server starts, during the initialization process, the log controller will be initialized to scan the log levels of all packages, classes, and method functions, and generate corresponding callback functions. The management background can call the log controller through the callback function so that the log controller responds to the operations on the operation page and performs corresponding processing.
[0094] Through the list page for viewing logs provided by the management background, the log levels in various dimensions of packages, classes, and method functions can be viewed, and through the detailed modification page provided by the management background, the log levels, output time, output style, etc. of at least one logger can be modified, thereby completing the operation of modifying the log level. Based on the user's operation of modifying the log level, the management background calls the log controller, and the log controller can then modify the log level. In this way, without restarting the server and going online, the log level can be dynamically modified to output logs of different levels.
[0095] Figure 2 It is a schematic structural diagram of an exemplary log control device according to an embodiment of the present invention. As Figure 2 shown, the log control device includes:
[0096] A first determination module 201, configured to determine the current properties of the log framework according to the user's property modification operation on the log framework;
[0097] A configuration generation module 202, configured to regenerate a property configuration file of the log framework in memory according to the current properties of the log framework;
[0098] A loading and updating module 203, configured to call the log framework to load the regenerated property configuration file from the memory to reconfigure the properties of the log framework based on the regenerated property configuration file.
[0099] In this embodiment, the user can modify the attributes of the logging framework through an attribute modification operation. After determining the current attributes of the logging framework according to the user's attribute modification operation, based on this, in memory, a new attribute configuration file for the logging framework is regenerated. At this time, the logging framework can be called to directly load the regenerated attribute configuration file from memory, thereby reconfiguring the attributes of the entire logging framework, achieving the modification of the attributes of the entire logging framework through the user's attribute modification operation. In this way, when the user's requirements for logging change, the attributes of the entire logging framework can be modified through the attribute modification operation to meet the user's logging requirements. Since the regenerated attribute configuration file is directly generated in memory, it can be directly loaded without restarting the server, avoiding service interruption of the server and making the service continuously available, thus improving the user experience.
[0100] In one possible implementation, it further includes:
[0101] A configuration replacement module, configured to replace the original attribute configuration file of the logging framework saved in the external storage with the regenerated attribute configuration file, so that when restarting next time, the logging framework is called to load the regenerated attribute configuration file from the external storage.
[0102] In one possible implementation, the configuration replacement module is specifically configured to, in response to the user's save modification operation, replace the original attribute configuration file of the logging framework saved in the external storage with the regenerated attribute configuration file.
[0103] In one possible implementation, the attribute modification operation includes at least one of the following:
[0104] An operation of adding a logger;
[0105] An operation of deleting a logger;
[0106] An operation of adding an output target corresponding to a logger;
[0107] An operation of deleting an output target corresponding to a logger;
[0108] An operation of modifying an output target corresponding to a logger;
[0109] An operation of adding, deleting, or modifying the log output format corresponding to the output target corresponding to a logger.
[0110] In one possible implementation, it further includes:
[0111] A second determination module, configured to determine the modified log level of the at least one logger according to the user's operation of modifying the log level of at least one logger in the log framework;
[0112] A level modification module, configured to modify the original log level of the at least one logger to the determined log level.
[0113] For the functions of the modules in each device of the embodiments of the present invention, reference may be made to the corresponding descriptions in the embodiments of the above-mentioned log control method, which will not be elaborated herein.
[0114] Preferably, an embodiment of the present invention further provides an electronic device, including: a processor, a memory, and a computer program stored on the memory and executable on the processor. When the computer program is executed by the processor, it implements each process of the above-mentioned log control method embodiment and can achieve the same technical effect. To avoid repetition, it will not be elaborated here.
[0115] Figure 3 is a schematic structural diagram of an exemplary electronic device for implementing the log control method provided by an embodiment of the present invention. As Figure 3 shown, the electronic device may include: a processor 301, a communication interface 302, a memory 303, and a communication bus 304. Among them, the processor 301, the communication interface 302, and the memory 303 communicate with each other through the communication bus 304. The processor 301 may call the computer program in the memory 303 to execute the log control method in any of the above embodiments.
[0116] An embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, it implements each process of the above-mentioned log control method embodiment and can achieve the same technical effect. To avoid repetition, it will not be elaborated here. Among them, the computer-readable storage medium is, for example, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disc, etc.
[0117] It should be noted that in this article, the terms "include", "comprise" or any other variant thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements not only includes those elements, but also includes other elements not expressly listed, or further includes elements inherent to such process, method, article or device. Without further limitation, an element defined by the statement "including one..." does not exclude the existence of additional identical elements in the process, method, article or device including the element.
[0118] Through the description of the above embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus a necessary general hardware platform. Of course, they can also be implemented by hardware. However, in many cases, the former is a better implementation method. Based on such an understanding, the technical solution of the present invention, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions for causing a terminal (which can be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in various embodiments of the present invention.
[0119] The embodiments of the present invention have been described above in conjunction with the accompanying drawings. However, the present invention is not limited to the above specific implementation manners. The above specific implementation manners are merely illustrative and not restrictive. Under the inspiration of the present invention, those of ordinary skill in the art can also make many forms without departing from the purpose of the present invention and the scope protected by the claims, and all of them belong to the protection scope of the present invention.
[0120] Those of ordinary skill in the art can realize that the units and algorithm steps of each example described in combination with the embodiments disclosed in the embodiments of the present invention can be implemented by electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are executed in a hardware or software manner depends on the specific application and design constraint conditions of the technical solution. Professional technicians can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of the present invention.
[0121] Those skilled in the art can clearly understand that for the convenience and brevity of description, the specific working processes of the systems, devices, and units described above can refer to the corresponding processes in the foregoing method embodiments and will not be repeated here.
[0122] In the embodiments provided by the present invention, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of the units is only a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed mutual coupling or direct coupling or communication connection can be through some interfaces. The indirect coupling or communication connection of the devices or units can be in an electrical, mechanical, or other form.
[0123] The unit described as a separation component may or may not be physically separated. The component displayed as a unit may or may not be a physical unit, that is, it may be located in one place or distributed to multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0124] In addition, in each embodiment of the present invention, each functional unit may be integrated in a processing unit, may exist physically alone for each unit, or two or more units may be integrated in one unit.
[0125] If the above functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or a part of this technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in each embodiment of the present invention. The foregoing storage medium includes: various media such as USB flash drives, mobile hard disks, ROM, RAM, magnetic disks, or optical discs that can store program codes.
[0126] The above is only the specific implementation manner of the present invention, but the protection scope of the present invention is not limited thereto. Any person skilled in the art within the technical scope disclosed by the present invention can easily think of changes or substitutions, which should all be covered by the protection scope of the present invention. Therefore, the protection scope of the present invention should be subject to the protection scope of the claims.
Claims
1. A log control method, characterized in that, Including: Determine the current properties of the log framework according to the user's property modification operation on the log framework; The property modification operation includes at least one of the following: an addition operation of a logger; A deletion operation of a logger; an addition operation of an output target corresponding to a logger; a deletion operation of an output target corresponding to a logger; a modification operation of an output target corresponding to a logger; an addition, deletion, or modification operation of a log output format corresponding to an output target corresponding to a logger; In memory, regenerate the property configuration file of the log framework according to the current properties of the log framework; Call the log framework to load the regenerated property configuration file from the memory to reconfigure the properties of the log framework based on the regenerated property configuration file.
2. The method according to claim 1, characterized in that, Also including: Replace the original property configuration file of the log framework saved in the external memory with the regenerated property configuration file so that when restarted next time, call the log framework to load the regenerated property configuration file from the external memory.
3. The method according to claim 2, wherein The replacing the original property configuration file of the log framework saved in the external memory with the regenerated property configuration file includes: In response to the user's save modification operation, replace the original property configuration file of the log framework saved in the external memory with the regenerated property configuration file.
4. The method according to any one of claims 1 to 3, characterized in that Also including: Determine the modified log level of at least one logger according to the user's log level modification operation on at least one logger in the log framework; Modify the original log level of the at least one logger to the determined log level.
5. A log control device, characterized in that, Including: A first determination module for determining the current properties of the log framework according to the user's property modification operation on the log framework; The property modification operation includes at least one of the following: an addition operation of a logger; a deletion operation of a logger; an addition operation of an output target corresponding to a logger; a deletion operation of an output target corresponding to a logger; a modification operation of an output target corresponding to a logger; an addition, deletion, or modification operation of a log output format corresponding to an output target corresponding to a logger; A configuration generation module for regenerating the property configuration file of the log framework in memory according to the current properties of the log framework; A loading and updating module for calling the log framework to load the regenerated property configuration file from the memory to reconfigure the properties of the log framework based on the regenerated property configuration file.
6. The device according to claim 5, characterized in that Also including: A configuration replacement module for replacing the original property configuration file of the log framework saved in the external memory with the regenerated property configuration file so that when restarted next time, call the log framework to load the regenerated property configuration file from the external memory.
7. The device according to claim 6, characterized in that, The configuration replacement module is specifically configured to, in response to the user's save modification operation, replace the original property configuration file of the log framework saved in the external memory with the regenerated property configuration file.
8. The device according to any one of claims 5 to 7, characterized in that, Also including: A second determination module, configured to determine the modified log level of the at least one logger according to the user's operation of modifying the log level of at least one logger in the log framework; A level modification module, configured to modify the original log level of the at least one logger to the determined log level.
9. An electronic device, characterized in that, Comprising: A processor, a memory, and a computer program stored on the memory and executable on the processor, where the computer program, when executed by the processor, implements the steps of the log control method according to any one of claims 1 to 4.
10. A computer-readable storage medium, characterized in that, A computer program is stored on the computer-readable storage medium, and when the computer program is executed by a processor, it implements the steps of the log control method according to any one of claims 1 to 4.
Citation Information
Patent Citations
Method and device for changing log levels
CN105843822A