Disclosure of Invention
The invention aims to provide an intelligent log output method, an intelligent log output device, computer equipment and a storage medium, and aims to solve the problems of poor adaptability, large maintenance workload and the like of a log output method in the prior art.
The embodiment of the invention provides an intelligent log output method based on a service interface, which comprises the following steps:
importing the log tool class under the root path of each module of the target item;
when a module is started, calling a log tool class under a root path of the module and executing the log tool class;
automatically reading a path of the module, and creating a log file under the same-level path according to the path of the module;
recording the generated log of the log tool class into the log file;
and when receiving a call request of the log file, returning the log file.
Preferably, the importing the log tool class into the root path of each module of the target item includes:
when a log import request is received, analyzing the log import request to acquire information of a module of a target item to be imported;
searching a root path of a module in the target item according to the information of the module of the target item;
and calling the log tool class and importing the log tool class into the root path of the module of the target item.
Preferably, the automatically reading the path of the module, and creating a log file under the peer path according to the path of the module, includes:
reading the path of the module in the target item and taking the path as the path of the module;
creating a log file with a name containing the module name under the same-level path of the path where the module is located.
Preferably, the path where the module is located is the root path of the target item.
Preferably, the method further comprises:
and merging log files of all the modules at fixed time to generate the log file of the target item.
Preferably, the step of merging log files of each module at the timing to generate the log file of the target item includes:
the log files of all modules in the same period are combined;
and merging the log files after merging the periods again according to the time sequence to generate the log file of the target item.
Preferably, the merging the log files of each module in the same period includes:
and merging log files of each module in the same-level path in the same period.
The embodiment of the invention provides an intelligent log output device based on a service interface, which comprises the following components:
an importing unit, configured to import the log tool class under a root path of each module of the target item;
the calling unit is used for calling the log tool class under the root path of the module and executing the log tool class when a module is started;
the creating unit is used for automatically reading the path of the module and creating a log file under the same-level path according to the path of the module;
a recording unit, configured to record a generated log of the logging tool class into the log file;
and the output unit is used for returning the log file when receiving the call request of the log file.
The embodiment of the invention provides a computer device, which comprises a memory, a processor and a computer program stored on the memory and capable of running on the processor, wherein the processor realizes the intelligent log output method based on the service interface when executing the computer program.
Embodiments of the present invention provide a computer readable storage medium having a computer program stored thereon, which when executed by a processor implements a business interface-based intelligent log output method as described above.
The embodiment of the invention provides an intelligent log output method, an intelligent log output device, computer equipment and a storage medium, wherein the method comprises the following steps: importing the log tool class under the root path of each module of the target item; when a module is started, calling a log tool class under a root path of the module and executing the log tool class; automatically reading a path of the module, and creating a log file under the same-level path according to the path of the module; recording the generated log of the log tool class into the log file; and when receiving a call request of the log file, returning the log file. According to the method, the log objects are not required to be independently created or configured, the corresponding log files can be automatically created by introducing the universal log objects, the decoupling is light, the automatic management of the newly added interface is effectively supported, and the log is not required to be independently maintained.
Detailed Description
For the purpose of making the objects, technical solutions and advantages of the embodiments of the present invention more apparent, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention, and it is apparent that the described embodiments are some embodiments of the present invention, but not all embodiments of the present invention. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
It is to be understood that the terminology used in the description of the invention herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention. As used in this specification and the appended claims, the singular forms "a," "an," and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise.
It should be further understood that the term "and/or" as used in the present specification and the appended claims refers to any and all possible combinations of one or more of the associated listed items, and includes such combinations.
Referring to fig. 1, fig. 1 is a flow chart of an intelligent log output method based on a service interface according to an embodiment of the present invention, where the method may include steps S101 to S105:
s101, importing a log tool class under a root path of each module of a target item;
different from the traditional log processing mode, the embodiment of the invention automatically divides the logs based on the service interface, and does not lead all the logs to be intensively output to one log file. To achieve the purpose, the embodiment of the invention introduces the log tool class under the root path of each module of the target item, and logs are recorded by using the log tool class independently, and the business interface logs can be automatically created by only introducing a general log object (namely the log tool class) without independently creating or configuring log objects, and decoupling among the logs. When the interface is newly added, only the log tool class is needed to be imported, so that automatic management is realized, and independent log maintenance is not needed.
According to the embodiment of the invention, the logging tool class can be imported into any target item needing logging according to the requirement, and can be further imported into the root path of each module of the target item for any module of the target item.
In one embodiment, the step S101 includes:
when a log import request is received, analyzing the log import request to acquire information of a module of a target item to be imported;
searching a root path of a module in the target item according to the information of the module of the target item;
and calling the log tool class and importing the log tool class into the root path of the module of the target item.
In this embodiment, when the log import request is received, the log import request is first parsed, so as to obtain information of the module of the target item therein. That is, it is necessary to confirm which target item or items are imported, and further, which module of the target item is imported. The information of the specific module of the target item includes the target item to which the module belongs and the name of the module.
And searching the root path of the module in the target item according to the information of the module of the target item, and finally calling a log tool class to import the log tool class into the root path of the searched module of the target item. The introduction of the generic log object into the module is achieved.
S102, when a module is started, calling a log tool class under a root path of the module and executing the log tool class;
when a module is started, the log tool class under the root path of the corresponding module can be called and executed so as to execute log output. In particular, the logging tool class may be executed using a startup procedure of the module.
S103, automatically reading a path of the module, and creating a log file under the same-level path according to the path of the module;
when the logging tool class is called for the first time, a single log file can be automatically created according to the path of the current module. The location of the log file is the same path as the module. I.e., the logging tool class automatically matches according to the path of the current module. In the embodiment of the invention, the log file is created under the same-level path of the path where the module is located by default. Of course, the user may also select a custom path to create the log file.
In one embodiment, the step S103 includes:
reading the path of the module in the target item and taking the path as the path of the module;
creating a log file with a name containing the module name under the same-level path of the path where the module is located.
In this embodiment, the path of the module in the target item is taken as the path where the module is located, and then the log file is created under the target path according to the peer path of the path where the module is located as the target path. The name of the log file contains the name of the module, so that the repetition of names among different log files can be avoided. In order to better distinguish the names of different log files, the log file creation time can be added to the name of the log file.
In one embodiment, the path along which the module resides is the root path of the target item. I.e. the module is under the root path of the target item, the log file can be created directly under the root path of the target item.
S104, recording the generated log of the log tool class into the log file;
during execution of the logging tool class, the log generated by the logging tool class is recorded into a log file for trace back.
S105, when a call request of the log file is received, returning the log file.
And finally, when the user needs to call the log file, a call request can be sent, and when the call request is received, the corresponding log file can be returned.
In an embodiment, the service interface-based intelligent log output method further includes:
and merging log files of all the modules at fixed time to generate the log file of the target item.
In the embodiment of the invention, the log tool class can be automatically imported for any one module, the independent log file can be automatically created, and the log file corresponding to any one module can be returned when needed. However, if the user wishes to view log files of a plurality of modules at the same time, it is necessary to request the log files one by one and view the log files one by one, and it is obvious that such an operation is time-consuming and cumbersome. Therefore, in order to solve the problem, the embodiment of the invention can combine the log files of each module at regular time to generate the log file of the target item. Therefore, the user can check the log files of each module of the target item, and the request efficiency and the check efficiency are improved.
In an embodiment, the step of merging log files of each module at the timing to generate the log file of the target item includes:
the log files of all modules in the same period are combined;
and merging the log files after merging the periods again according to the time sequence to generate the log file of the target item.
In the embodiment of the invention, the log files can be classified according to the period, for example, the period is a day, and then the log files of each day can be obtained by classifying the log files according to the day, and then the log files of each module in the same day can be combined, and of course, the log files of each module in a plurality of the same days can also be combined.
The log files after the merging of the respective periods may then be merged again in time sequence, for example, the log files of each of the days 10 months 21 to 10 months 25 have been merged before, and then the log files of the 5 days may be merged again in time sequence finally, thereby generating the log file of the target item at the 5 days.
It should be noted that, in the embodiment of the present invention, it is not limited to merge all the log files of all the modules under the target item, but it is also possible to select log files of a plurality of specified modules under the target item and merge the log files of the specified modules. Of course, each module under the target item may be classified, and then the log files of the modules under different types may be combined, so that a plurality of types of log files under the target item may be generated. The scheme improves the flexibility of the log file and can be suitable for different scenes and different user requirements.
In an embodiment, the merging the log files of each module in the same period includes:
and merging log files of each module in the same-level path in the same period.
Because the path levels of the modules may be completely different, even a sub-module is arranged under one module, the sub-module also has the log files thereof, so that if the log files of all the modules are simply combined, the confusion of the combined log files is obviously caused. Of course, the log files of each module under other same-level paths can be combined, so that the user can check the log files conveniently.
In addition, when the log files of the modules in the same level path in the same period are combined, the log files of the modules can be combined according to a certain sequence, for example, the modules are sequenced in advance, and then the log files of the modules are combined according to the sequence of the modules. The sorting principle can be to sort modules according to the importance of the modules, wherein the modules with high importance are arranged at the front, the modules with low importance are arranged at the rear. Of course, the principle of sorting may also be to sort according to the size of the log files, for example, the larger the log files, the earlier the sorting, the smaller the log files, and the later the sorting. In addition, the log files may be sorted according to the creation time, and the earlier the log files are created, and the later the log files are created, the later the log files are ordered.
By adopting the method of the embodiment of the invention, the log files can be created under a plurality of modules of a plurality of target items, and even the log files can be created under the submodules of different levels under the modules, so that the level and the number of the log files are very large, and the embodiment of the invention improves the situation. Specifically, the intelligent log output method based on the service interface further comprises the following steps:
creating a log file catalog in advance;
when the creation of the log file is detected, the path of the log file is acquired, and the path of the log file is written into the log file directory.
That is, in the embodiment of the present invention, when a new log file is created, the log file directory is updated to write the path of the new log file under the log file directory. When the original log file is deleted, the log file directory can be updated to delete the path of the original log file from the log file directory.
In this way, each log file is managed by the log file directory statistics, and when a call request of the log file is received, only a path of the corresponding log file is searched in the log file directory, the corresponding log file is obtained according to the searched path, and the log file is returned to the caller.
The paths of the log files in the log file directory are recorded in a tree form, and a user can open the log file directory at any time and check the condition of the log files, such as how many log files are under a certain target item, and the like.
In addition, in the embodiment of the present invention, a selection button and an output button may be set in the log file directory, where the selection button is used to select a path of a log file, and the output button is used to automatically output a corresponding log file according to the selected path of the log file.
Specifically, the selection button is a multi-selection button, a user can directly open the log file catalog and select a corresponding path of the log file, the number of selections can be one or more, then the output button is clicked, and a call request of the log file can be automatically sent, and then the log file of the selected path is output based on the call request.
In addition, in the embodiment of the present invention, a merge output button may be further disposed in the log file directory, where the merge output button is used to merge and output the corresponding log files according to the paths of the selected multiple log files. The merging at this time is real-time merging, and because the operation is performed according to the path of the log file currently selected by the user, the merging operation is more flexible, and any path of the log file can be selected and then merged and output.
In addition, in the embodiment of the present invention, an expansion button may be further disposed in the log file directory, where the expansion button is used to expand paths of all log files in the same level below the log file directory, so as to facilitate user's viewing. When the user opens the log file directory, in an initial state, the content in the log file directory is in an undeployed state, namely, only one total directory can be seen, and when the user clicks the expanding button, the paths of all log files in the root path of the total directory can be expanded, and when the user selects the path of the log file of one module, the paths of the log files of the sub-modules of the module can be further expanded.
In the embodiment of the invention, when the path with the new log file written in the log file directory is detected, or the path with the log file is deleted or modified, a prompt is sent to the user so as to prompt the user that the log file directory has new change, so that the user can confirm the change condition of the log file directory in time. In addition, the log file directory may be sent to the user terminal, so that the user can check the log file directory anytime and anywhere and output the log file directory as required, for example, the log file directory may be sent to the user terminal at regular time, or the log file directory may be sent to the user terminal when it is detected that the log file directory is updated.
Referring to fig. 2, fig. 2 is a schematic block diagram of an intelligent log output device based on a service interface according to an embodiment of the present invention, where thedevice 200 may include:
an importingunit 201 for importing the logging tool class under the root path of each module of the target item;
acalling unit 202, configured to call a log tool class under a root path of a module and execute the log tool class when the module is started;
a creatingunit 203, configured to automatically read a path where the module is located, and create a log file under a peer path according to the path where the module is located;
arecording unit 204, configured to record the generated log of the logging tool class into the log file;
and theoutput unit 205 is used for returning the log file when receiving the call request of the log file.
In an embodiment, the importingunit 201 includes:
the analysis unit is used for analyzing the log import request when receiving the log import request and acquiring the information of the module of the target item to be imported;
the searching unit is used for searching a root path of the module in the target item according to the information of the module of the target item;
and the importing unit is used for calling the log tool class and importing the log tool class under the root path of the module of the target item.
In an embodiment, the creatingunit 203 includes:
the reading unit is used for reading the path of the module in the target item and taking the path as the path of the module;
and the log file creation unit is used for creating a log file with the name containing the module name under the same-level path of the path where the module is located.
In one embodiment, the path along which the module resides is the root path of the target item.
In an embodiment, the intelligent log output device further comprises:
and the timing unit is used for merging the log files of each module at fixed time to generate the log file of the target item.
In an embodiment, the timing unit comprises:
the first merging unit is used for merging log files of all modules in the same period;
and the second merging unit is used for merging the log files after the merging of the periods again according to the time sequence to generate the log file of the target item.
In an embodiment, the first merging unit includes:
and the same-level merging unit is used for merging log files of each module in the same-level path in the same period.
The embodiment of the invention also provides computer equipment, which comprises a memory, a processor and a computer program stored in the memory and capable of running on the processor, wherein the processor realizes the intelligent log output method based on the service interface when executing the computer program.
The embodiment of the invention also provides a computer readable storage medium, wherein the computer readable storage medium is stored with a computer program, and the computer program realizes the intelligent log output method based on the service interface when being executed by a processor.
In the description, each embodiment is described in a progressive manner, and each embodiment is mainly described by the differences from other embodiments, so that the same similar parts among the embodiments are mutually referred. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant points refer to the description of the method section. It should be noted that it will be apparent to those skilled in the art that various modifications and adaptations of the invention can be made without departing from the principles of the invention and these modifications and adaptations are intended to be within the scope of the invention as defined in the following claims.
It should also be noted that in this specification, relational terms such as first and second, and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Moreover, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.