CN113468029A - Log management method and device, electronic equipment and readable storage medium - Google Patents

Log management method and device, electronic equipment and readable storage medium Download PDF

Info

Publication number
CN113468029A
CN113468029A CN202111035619.2A CN202111035619A CN113468029A CN 113468029 A CN113468029 A CN 113468029A CN 202111035619 A CN202111035619 A CN 202111035619A CN 113468029 A CN113468029 A CN 113468029A
Authority
CN
China
Prior art keywords
log
log information
information
program
memory
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202111035619.2A
Other languages
Chinese (zh)
Inventor
不公告发明人
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Chengdu Shuzhilian Technology Co Ltd
Original Assignee
Chengdu Shuzhilian Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Chengdu Shuzhilian Technology Co Ltd filed Critical Chengdu Shuzhilian Technology Co Ltd
Priority to CN202111035619.2A priority Critical patent/CN113468029A/en
Publication of CN113468029A publication Critical patent/CN113468029A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/30Monitoring
    • G06F11/3003Monitoring arrangements specially adapted to the computing system or computing system component being monitored
    • G06F11/302Monitoring arrangements specially adapted to the computing system or computing system component being monitored where the computing system component is a software system
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/30Monitoring
    • G06F11/3065Monitoring arrangements determined by the means or processing involved in reporting the monitored data
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/18File system types
    • G06F16/1805Append-only file systems, e.g. using logs or journals to store data
    • G06F16/1815Journaling file systems

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computing Systems (AREA)
  • Quality & Reliability (AREA)
  • Mathematical Physics (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The application provides a log management method, a log management device, an electronic device and a readable storage medium. If the program operation is not abnormal, extracting the log information of the preset level in the memory and writing the log information into a log file. Therefore, when the program is abnormal, the log information of all levels can be recorded into the log file, the smooth execution of the subsequent abnormal investigation is ensured, and when the program is not abnormal, only the log information of the preset level is written into the log file, so that the redundancy of the log information in the log file can be avoided, and the occupation of excessive storage resources is avoided.

Description

Log management method and device, electronic equipment and readable storage medium
Technical Field
The present application relates to the technical field of electronic devices, and in particular, to a log management method and apparatus, an electronic device, and a readable storage medium.
Background
One non-functional index of a software system is maintainability, which needs to be designed from aspects of system operation monitoring, alarming, early warning, abnormal positioning, recovery and the like, and an important means for realizing maintainability is to record system operation logs. The logs can be divided into normal logs and abnormal logs from the perspective of system state, and can be divided into error logs, running logs, debugging logs, tracing logs and the like from the detail degree of log contents. When the system runs abnormally, the log plays an important role in quickly positioning the position of the abnormal occurrence, analyzing the abnormal reason and the like.
In the existing log management mode, when a system runs, a log level is generally set to be a fixed level, and log information recorded in the running process of the system is the log information of the fixed level. However, in this way, if the system runs abnormally, due to lack of log information records beyond a fixed level, subsequent abnormal troubleshooting is hindered. If log information of all levels is recorded in the log file, log information redundancy is caused and storage resources are wasted under the condition that the system is not abnormal in operation.
Disclosure of Invention
The application aims to provide a log management method, a log management device, an electronic device and a readable storage medium, which can guarantee accurate troubleshooting of abnormal reasons and avoid redundancy of log information.
The embodiment of the application can be realized as follows:
in a first aspect, the present application provides a log management method, including:
collecting log information of all levels and recording the log information in a memory in the process of starting and running a program;
if the program runs abnormally, extracting all levels of log information recorded in the memory to write the log information into a log file;
and if the program does not have abnormality in operation, extracting the log information of the preset level recorded in the memory to write the log information into a log file.
In the embodiment, when the abnormality occurs, the log information of all levels is written into the log file, so that the accurate investigation of the subsequent abnormality reason is facilitated, and when the abnormality does not occur, only the log information of the preset level is extracted and written into the log file, so that the problem of log redundancy caused by writing the whole amount of log information can be avoided.
In an optional implementation manner, after the step of extracting the log information of the preset level recorded in the memory to write into the log file, the method further includes:
and deleting the log information of other levels except the preset level recorded in the memory.
In this embodiment, under the condition that no exception occurs, the memory can be prevented from being occupied by log information of other levels except the preset level.
In an optional embodiment, when the program runs abnormally, the method further comprises:
judging whether the current abnormity occurring in the program operation is the first abnormity, if not, obtaining abnormity statistical information based on the current abnormity, and writing the abnormity statistical information into a log file;
and if the current abnormality is the first abnormality, executing the step of extracting all levels of log information recorded in the memory to write the log information into a log file.
In this embodiment, by determining whether the current abnormality is the first abnormality, the same log information can be prevented from being repeatedly written in the log file, and the waste of the disk space is avoided.
In an optional embodiment, the step of determining whether the current exception occurring during the program operation is a first exception includes:
acquiring the current abnormal generation reason and the link information called by the program;
determining a target abnormality type to which the current abnormality belongs according to the abnormality generation reason and the link information;
and detecting whether log information of the target abnormal type exists in the log file, and if so, judging that the current abnormality is not the first abnormality.
In this embodiment, the exception category to which the program belongs can be accurately determined by combining the exception generation cause and the link information called by the program, so as to facilitate the determination of whether the current exception is the first exception.
In an alternative embodiment, the execution of the program involves a plurality of functional levels;
if the program runs abnormally, extracting log information of all levels recorded in the memory to write the log information into a log file, wherein the step comprises the following steps:
if the program runs abnormally, stopping the program running, and positioning the abnormal function level from the plurality of function levels;
and extracting all levels of log information of the abnormal function level recorded in the memory to write the log information into a log file.
In the embodiment, the abnormity can be positioned to a specific function level, and the directivity of follow-up abnormity troubleshooting is improved.
In an optional implementation manner, the step of extracting log information of all levels recorded in the memory to write the log information into the log file if the program runs abnormally further includes:
extracting the log information of the preset level of the function level without the abnormality recorded in the memory aiming at the function level without the abnormality in the plurality of function levels, and writing the log information into a log file;
and deleting the log information of other levels of the function level without the exception, which is recorded in the memory.
In this embodiment, only the log information of the preset level is extracted and written into the log file for the function level where no abnormality occurs, so that the occupation of the disk space can be further reduced.
In an alternative embodiment, the step of locating the function level from among the plurality of function levels where the abnormality occurs includes:
acquiring abnormal information captured when the program runs abnormally;
and positioning the function level with the exception according to the stack information in the exception information.
In this embodiment, the specific program code of the step in which the program runs abnormally in the stack information can accurately locate the abnormal function level.
In an optional embodiment, the step of extracting log information at a preset level recorded in a memory to write the log information into a log file if the program operation is not abnormal includes:
if the program is not abnormal in operation, determining log information corresponding to each function level respectively according to the logic level information of each log information recorded by a memory after the program is finished in operation;
and extracting the log information at a preset level in the log information aiming at the log information corresponding to each function level so as to write the log information into a log file.
In this embodiment, the log information corresponding to each function level is distinguished, which can facilitate extraction and writing of the log information at a preset level in the execution process.
In a second aspect, the present application provides a log management apparatus, the apparatus comprising:
the collection module is used for collecting log information of all levels and recording the log information in a memory in the process of starting and running the program;
the first extraction module is used for extracting all levels of log information recorded in the memory to write the log information into a log file when the program operation is abnormal;
and the second extraction module is used for extracting the log information of the preset level recorded in the memory to write the log information into the log file when the program operation is not abnormal.
In a third aspect, the present application provides an electronic device comprising one or more storage media and one or more processors in communication with the storage media, the one or more storage media storing processor-executable machine-executable instructions that, when executed by the electronic device, are executed by the processors to perform the method steps of any one of the preceding embodiments.
In a fourth aspect, the present application provides a computer-readable storage medium having stored thereon machine-executable instructions which, when executed, implement the method steps of any one of the preceding embodiments.
The beneficial effects of the embodiment of the application include, for example:
the application provides a log management method, a log management device, an electronic device and a readable storage medium. If the program operation is not abnormal, extracting the log information of the preset level in the memory and writing the log information into a log file. Therefore, when the program is abnormal, the log information of all levels can be recorded into the log file, the smooth execution of the subsequent abnormal investigation is ensured, and when the program is not abnormal, only the log information of the preset level is written into the log file, so that the redundancy of the log information in the log file can be avoided, and the occupation of excessive storage resources is avoided.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings that are required to be used in the embodiments will be briefly described below, it should be understood that the following drawings only illustrate some embodiments of the present application and therefore should not be considered as limiting the scope, and for those skilled in the art, other related drawings can be obtained from the drawings without inventive effort.
Fig. 1 is a flowchart of a log management method according to an embodiment of the present application;
fig. 2 is a flowchart of a determining method in the log management method according to the embodiment of the present application;
FIG. 3 is a flowchart of sub-steps included in step S210 of FIG. 2;
FIG. 4 is a flowchart of sub-steps included in step S120 of FIG. 1;
FIG. 5 is another flowchart of the sub-steps included in step S120 of FIG. 1;
FIG. 6 is a flowchart of sub-steps included in step S130 of FIG. 1;
fig. 7 is a block diagram of an electronic device according to an embodiment of the present disclosure;
fig. 8 is a functional block diagram of a log management device according to an embodiment of the present application.
Icon: 110-a memory; 120-a processor; 130-power supply components; 140-a communication component; 150-input/output interface; 160-log management means; 161-a collection module; 162-a first extraction module; 163-second extraction module.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are some embodiments of the present application, but not all embodiments. The components of the embodiments of the present application, generally described and illustrated in the figures herein, can be arranged and designed in a wide variety of different configurations.
Thus, the following detailed description of the embodiments of the present application, presented in the accompanying drawings, is not intended to limit the scope of the claimed application, but is merely representative of selected embodiments of the application. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
It should be noted that: like reference numbers and letters refer to like items in the following figures, and thus, once an item is defined in one figure, it need not be further defined and explained in subsequent figures.
In the description of the present application, it should be noted that the features in the embodiments of the present application may be combined with each other without conflict.
The log level is a general scheme in the Java programming language, and log frameworks such as log4j/logback/slf4j adopt the scheme, and the log level is used for representing the importance of log contents. For example, the common log levels include error logs, info run logs, debug logs, trace logs, and the like, and decrease sequentially from left to right, and accordingly decrease sequentially in importance. When the program is coded, the log can be recorded by adopting different levels according to different importance. When the program runs, according to the log level set by the system, the system records the log with the currently set log level and the log with the higher importance level. For example: the log level is set to INFO, and the system record log comprises an INFO level log and an ERROR level log; the log level is set to DEBUG, and the system records logs including the logs of the DEBUG level, the INFO level and the ERROR level.
When the log level is set to be the INFO level, and the system runs abnormally, the reason may not be checked only according to the ERROR level log and the INFO level log, and a specific reason needs to be acquired from the DEBUG level log. At this time, the DEBUG level log is lost, so that the timely troubleshooting cannot be performed. In this case, the log level may be manually adjusted to DEBUG, which is beneficial to the troubleshooting of the cause of the abnormality, but may cause the following problems: when the log level is set to the DEBUG level and the system runs normally, the log at the DEBUG level is also recorded, so that the content of the log is redundant and resources are wasted.
Therefore, in the existing log management mode, after the log level is set to a fixed value during the operation of the system, log redundancy or log loss may be caused, and the occurrence of the two situations cannot be avoided at the same time.
Based on the research and analysis, the log management scheme provided by the application can adaptively write in log information, is not restricted by log level setting during system operation, but adaptively adjusts according to system operation conditions, so that complete log information can be written in under the condition of abnormal program operation, subsequent quick reading and accurate abnormal investigation are facilitated, and the log information at a preset level can be written in under the condition of no abnormal program operation, so that the redundancy of the log information is avoided.
Referring to fig. 1, a flowchart of a log management method according to an embodiment of the present application is shown, where method steps defined by a flow related to the log management method may be implemented by an electronic device related to log management. The specific process shown in FIG. 1 will be described in detail below.
Step S110, in the process of starting and running the program, collecting log information of all levels and recording the log information in the memory.
Step S120, if the program runs abnormally, extracting all levels of log information recorded in the memory to write into the log file.
In step S130, if the program operation is not abnormal, the log information at the preset level recorded in the memory is extracted to be written into the log file.
In order to know the operating condition of the electronic device, the electronic device may be configured with a function of recording log information generated during the operation of the program. The log information can be used for the user to analyze the program operation, including information query, analysis, tracking and positioning and other analysis processes.
In this embodiment, the electronic device may be a smart phone, a tablet computer, a personal computer, or the like. The targeted program may be any program that can be run on the electronic device, and may also refer to an operating system of the electronic device. Log management of an application installed on the electronic device and an operating system of the electronic device may be performed.
The logs recorded in the electronic device can be classified into error logs, info running logs, debug logs, trace logs and the like according to the detail degree of the log contents. The log level is sequentially trace log, debug log, info log and error log from low to high.
the trace log is used for tracking the running of the program, and a trace output is correspondingly provided when the program is pushed. debug logs can be used to indicate fine-grained information events, and this level of log information is typically used in the debugging process of an analysis program. The info log is used to indicate coarse-grained information events, and this level of log information typically highlights the running process of the program. The error log is used to indicate that an error event has occurred, which may be an event that does not affect the continued operation of the program or that causes the program to exit.
In this embodiment, in the process of starting and starting the program, log information of all levels related to the program operation is recorded in the memory first, but is not written in the log file. Since the program may run normally while running, an exception may also occur. When the program is not run and is finished, the specific content of the log file to be recorded cannot be determined. Log information of all levels is recorded in the memory, and the full amount of log information can be reserved.
When the program is abnormal, the log information of all recorded levels is written into the log file, so that the detailed log information can be taken out when the program is abnormal, and the problem of useful log information loss can be avoided.
And under the condition that the program is not abnormal, the log information of the preset level recorded in the memory can be written into the log file. In this embodiment, the log information of the preset level may include an info log and an error log.
In the log management scheme provided by this embodiment, the writing of the log file is no longer constrained by the log level setting during the operation of the system, and can be adaptively adjusted according to the program operation condition. Therefore, when the program runs abnormally, accurate examination of the reason of the abnormality can be helped based on detailed log information of all levels in the log file. And under the condition that the program operation is not abnormal, only the log information of the preset level is written into the log file, so that the problem of log redundancy existing in the process of writing the full amount of log information is avoided.
In one implementation, if no exception occurs during program operation, after extracting log information at a preset level recorded in the memory and writing the log information into a log file, the log information at other levels except the preset level recorded in the memory may be deleted. So as to avoid the occupation of other levels of log information on the memory.
Taking the above as an example, the other levels of log information may include trace log and debug log, for example.
In this embodiment, considering that the program operation is always continuous, the same abnormal phenomenon may occur repeatedly in the program operation process. If each time an abnormality occurs, all log information is directly written into the log file, repeated log information may be stored in the log file, and the redundancy of the log information will also be caused.
Based on the above consideration, please refer to fig. 2, in a possible implementation manner, in the log management method provided in this embodiment, when an exception occurs in the program operation, the method may further include the following steps:
step S210, determining whether the current exception occurring during program operation is a first exception, if not, executing the following step S220, and if the current exception is the first exception, executing the step S120 of extracting all levels of log information recorded in the memory to write the log information into the log file.
Step S220, obtaining abnormal statistical information based on the current abnormality, and writing the abnormal statistical information into a log file.
In this embodiment, in the process of running the program, all log information related to the running of the program is recorded in the memory regardless of whether the program is abnormal. If the program runs abnormally, whether the current abnormality is the first abnormality or not can be judged firstly. The determination as to whether or not the abnormality is a first abnormality may be a determination as to whether or not the abnormality is a first abnormality in an abnormality category to which the current abnormality belongs. When the current abnormality is the first abnormality of the abnormality category to which the current abnormality belongs, the fact that the same abnormality does not occur before is indicated, and corresponding log information is not stored in the log file. Therefore, it is necessary to write the currently abnormal log information into the log file.
If the current exception is not the first exception in the exception category to which the current exception belongs, the exception information of the first exception is written into the log file, which indicates that the exception information in the exception category is stored in the current log file. And the abnormal information under the same abnormal category can be needed for subsequent abnormal investigation, so that in this case, the abnormal statistical information can be obtained only based on the current abnormality and written into the log file. All current abnormal log information does not need to be written into the log file, so that the problem of information redundancy caused by excessive repeated log information in the log file is avoided.
In this embodiment, the abnormal statistical information may include error codes, reasons for generating the abnormal conditions, time of occurrence of the abnormal conditions, and frequency of occurrence of the abnormal conditions. And writing the brief abnormal statistical information into a log file, so as to facilitate the subsequent global analysis of the abnormality.
By the above-mentioned judgment of whether the current abnormality is the first abnormality or not, the same log information can be prevented from being repeatedly written in the log file, and the waste of the disk space can be avoided.
Referring to fig. 3, in the present embodiment, when determining whether the current abnormality occurring in the program operation is the first abnormality in step S210, the method may be implemented as follows:
step S211, obtaining the exception generation reason of the current exception and the link information called by the program.
Step S212, determining the target abnormal category to which the current abnormality belongs according to the abnormality generation reason and the link information.
Step S213 detects whether log information of the target abnormality type exists in the log file, and if so, executes the following step S214, and if not, executes the following step S215.
Step S214, judging that the current abnormity is not the first abnormity.
In step S215, it is determined that the current abnormality is a first abnormality.
In this embodiment, the exceptions may be classified in advance by combining different exception generation causes and different program call link information, and the exception generation causes and the program call link information may be associated with different exception categories. Exceptions with the same exception generation cause and link information for the same procedure call may be classified as the same type of exception. The link information called by the program includes the sequence of program execution and the specific program code of each step in the sequence.
In implementation, the target exception category to which the current exception belongs may be determined based on the exception generation cause of the current exception and the link information called by the program.
In one implementation, whether the log file has the abnormality information corresponding to the target abnormality category may be detected, and if so, the current abnormality is represented as not being the first abnormality.
In another implementation, each time an exception is recorded, the category to which the exception belongs may be recorded. And subsequently, directly inquiring the recorded category information to judge whether the current abnormity is the first abnormity.
In this embodiment, the exception category to which the program belongs can be accurately determined by combining the exception generation cause and the link information called by the program, so as to facilitate the determination of whether the current exception is the first exception.
In this embodiment, the running of the program involves multiple function levels, and when an exception occurs during the running of the program and the current exception is a first exception, the log information can be extracted and written in the following manner, please refer to fig. 4 in combination:
and step S121, if the program runs abnormally, terminating the program running and positioning the abnormal function level from the plurality of function levels.
Step S122, extracting log information of all levels of the abnormal function level recorded in the memory to write the log information into a log file.
In this embodiment, the processing logic of the program may be divided into an interface service functional layer, a service logic functional layer, a data access functional layer, and an external interface access functional layer according to the functional decoupling.
The interface service function layer is used for providing called interfaces for other system calls. The business logic function layer is used for carrying the interface service function layer upwards and butting the data access function layer downwards, and the processing of the business logic is also in the function layer. And the data access functional layer is used for carrying the service logic functional layer upwards and carrying out data interaction with various storage systems downwards. The storage system comprises a relational database, a non-relational database, a file system and the like.
The external interface access functional layer is used for upwards bearing the business logic functional layer, downwards butting various external systems and carrying out data interaction with the external systems in an interface mode.
According to the division of the function layers, correspondingly, the log information in the program running process is also divided into an interface service log, a service logic log, a data access log and an external interface access log. The program can record corresponding logs according to the level of the code.
In this embodiment, the various types of log information may include log time, logic layer, log level, method, and service log. The log time is the time of log recording, and the logic layer can record the logic level of the program of the log. The log level is the log level used when logging. The method may record the method name, package name, and code line number of the log. The service log can represent log information recorded according to different purposes when the code is developed.
When the program runs abnormally, it may be that some function level in the execution process is abnormal, and other function levels are not abnormal. Therefore, it is possible to locate to the function level where the abnormality occurs, and extract and write log information of all levels of the function level where the abnormality occurs to the log file.
In the embodiment, the abnormity can be positioned to a specific function level, and the directivity of follow-up abnormity troubleshooting is improved.
In this embodiment, the exception information captured when the program runs abnormally may be acquired, and the function level where the exception occurs may be located according to stack information in the exception information. As can be seen from the above description, the exception information includes link information for program invocation, and based on the link information, the execution sequence of the program and the specific program code of each step in the sequence can be determined. Specific program code may be stored in a stack, and the program code may point to a corresponding functional level. Thus, the function level at which the exception occurred can be located based on the stack information.
In this embodiment, the specific program code of the step in which the program runs abnormally in the stack information can accurately locate the abnormal function level.
In addition, referring to fig. 5, the step S120 may further include the following steps:
step S123, extracting, for a function level where no abnormality occurs in the plurality of function levels, log information of a preset level of the function level where no abnormality occurs, which is recorded in the memory, and writing the log information into a log file.
Step S124, delete the log information of other levels of the function hierarchy recorded in the memory and not subjected to the abnormality.
When the program is abnormal, the function levels which are not abnormal do not need to be subjected to abnormal examination in the subsequent execution process of the function levels, so that only the log information of the preset levels of the function levels can be written into the log file, and the log information of other levels in the memory can be deleted.
In this embodiment, only the log information of the preset level is extracted and written into the log file for the function level where no abnormality occurs, so that the occupation of the disk space can be further reduced.
In this embodiment, if no exception occurs until the program runs to the end, the step of extracting the log information at the preset level and writing the log information into the log file in step S130 may be implemented in the following manner, please refer to fig. 6:
step S131, if the program operation is not abnormal, determining the log information corresponding to each function level according to the logical level information of each log information recorded in the memory after the program operation is finished.
Step S132, for the log information corresponding to each function level, extracting the log information at a preset level from the log information to write the log information into a log file.
In this embodiment, as can be seen from the above, each type of log information includes logic layer information, where the logic layer information is used to record a logic level where a program of the log is located, and according to the logic layer information, log information corresponding to each function level can be determined in all logs in which the program runs.
In this way, during execution, the log information of each function level can be extracted from the log information of each function level respectively, and the log information of the preset level can be written into the log file.
In this way, the log information corresponding to each function level is distinguished, and the extraction and writing of the log information of the preset level in the execution process can be facilitated.
Referring to fig. 7, an electronic device is further provided in an embodiment of the present application. FIG. 7 is a block diagram illustrating an electronic device in accordance with an example embodiment. For example, the electronic device may be provided as a smart phone, personal computer, tablet computer, or the like. Referring to fig. 7, the electronic device includes a processor 120, which may be one or more in number, and a memory 110 for storing computer programs executable by the processor 120. The computer program stored in memory 110 may include one or more modules that each correspond to a set of instructions. Further, the processor 120 may be configured to execute the computer program to perform the log management method described above.
Additionally, the electronic device may also include a power component 130 and a communication component 140, the power component 130 may be configured to perform power management of the electronic device, and the communication component 140 may be configured to enable communication of the electronic device, e.g., wired or wireless communication. In addition, the electronic device may also include an input/output interface 150. The electronic device may operate based on an operating system stored in memory 110, such as Windows Server, Mac OS XTM, UnixTM, Linux, and the like.
Referring to fig. 8, an embodiment of the present application further provides a log management apparatus 160, where the log management apparatus 160 may be understood as the electronic device or the processor 120 of the electronic device, or may be understood as a software functional module that is independent of the electronic device or the processor 120 and implements the log management method under the control of the electronic device.
As shown in fig. 8, the log management device 160 may include a collection module 161, a first extraction module 162, and a second extraction module 163. The functions of the functional modules of the log management device 160 will be described in detail below.
The collecting module 161 is configured to collect log information of all levels and record the log information in a memory in a process of starting and running a program;
it is understood that the collecting module 161 can be used to execute the step S110, and for the detailed implementation of the collecting module 161, reference can be made to the above-mentioned contents related to the step S110.
The first extraction module 162 is configured to, when the program operation is abnormal, extract log information at all levels recorded in the memory to write the log information into a log file;
it is understood that the first extraction module 162 can be used to perform the step S120, and for the detailed implementation of the first extraction module 162, reference can be made to the above description of the step S120.
The second extracting module 163 is configured to, when no exception occurs in the program operation, extract the log information at the preset level recorded in the memory to write the log information into the log file.
It is understood that the second extraction module 163 can be used to execute the step S130, and for the detailed implementation of the second extraction module 163, reference can be made to the contents related to the step S130.
In a possible implementation manner, the second extraction module 163 may further be configured to:
and deleting the log information of other levels except the preset level recorded in the memory.
In a possible implementation manner, the log management apparatus 160 may further include a determining module, and the determining module may be specifically configured to:
when the program runs abnormally, judging whether the current abnormality of the program running is the first abnormality or not, if not, obtaining abnormal statistical information based on the current abnormality, and writing the abnormal statistical information into a log file;
and if the current abnormality is the first abnormality, executing the step of extracting all levels of log information recorded in the memory to write the log information into a log file.
In a possible implementation manner, the determining module may be specifically configured to:
acquiring the current abnormal generation reason and the link information called by the program;
determining a target abnormality type to which the current abnormality belongs according to the abnormality generation reason and the link information;
and detecting whether log information of the target abnormal type exists in the log file, and if so, judging that the current abnormality is not the first abnormality.
In one possible implementation, the execution of the program involves a plurality of functional levels; the first extraction module 162 may specifically be configured to:
if the program runs abnormally, stopping the program running, and positioning the abnormal function level from the plurality of function levels;
and extracting all levels of log information of the abnormal function level recorded in the memory to write the log information into a log file.
In a possible implementation manner, the first extraction module 162 may be further specifically configured to:
extracting the log information of the preset level of the function level without the abnormality recorded in the memory aiming at the function level without the abnormality in the plurality of function levels, and writing the log information into a log file;
and deleting the log information of other levels of the function level without the exception, which is recorded in the memory.
In a possible implementation manner, the first extraction module 162 may specifically be configured to:
acquiring abnormal information captured when the program runs abnormally;
and positioning the function level with the exception according to the stack information in the exception information.
In a possible implementation manner, the second extraction module 163 may specifically be configured to:
if the program is not abnormal in operation, determining log information corresponding to each function level respectively according to the logic level information of each log information recorded by a memory after the program is finished in operation;
and extracting the log information at a preset level in the log information aiming at the log information corresponding to each function level so as to write the log information into a log file.
The description of the processing flow of each module in the device and the interaction flow between the modules may refer to the related description in the above method embodiments, and will not be described in detail here.
In another exemplary embodiment, a computer readable storage medium comprising program instructions, such as the memory 110 comprising program instructions, executable by the processor 120 of the electronic device to perform the log management method described above is also provided.
Specifically, the computer readable storage medium can be a general storage medium, such as a removable disk, a hard disk, and the like, and when executed, the computer program on the computer readable storage medium can execute the log management method. With regard to the processes involved when the executable instructions in the computer-readable storage medium are executed, reference may be made to the related descriptions in the above method embodiments, which are not described in detail herein.
To sum up, in the log management method and apparatus, the electronic device, and the readable storage medium provided in the embodiments of the present application, in the process of starting and running the program, the log information of all levels is recorded in the memory first, and if the program runs abnormally, the log information of all levels in the memory is written into the log file. If the program operation is not abnormal, extracting the log information of the preset level in the memory and writing the log information into a log file. Therefore, when the program is abnormal, the log information of all levels can be recorded into the log file, the smooth execution of the subsequent abnormal investigation is ensured, and when the program is not abnormal, only the log information of the preset level is written into the log file, so that the redundancy of the log information in the log file can be avoided, and the occupation of excessive storage resources is avoided.
The above description is only for the specific embodiments of the present application, but the scope of the present application is not limited thereto, and any changes or substitutions that can be easily conceived by those skilled in the art within the technical scope of the present application should be covered within the scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.

Claims (11)

1. A method of log management, the method comprising:
collecting log information of all levels and recording the log information in a memory in the process of starting and running a program;
if the program runs abnormally, extracting all levels of log information recorded in the memory to write the log information into a log file;
and if the program does not have abnormality in operation, extracting the log information of the preset level recorded in the memory to write the log information into a log file.
2. The log management method according to claim 1, wherein after the step of extracting the log information of the preset level recorded in the memory to write into the log file, the method further comprises:
and deleting the log information of other levels except the preset level recorded in the memory.
3. The log management method according to claim 1, wherein, when an abnormality occurs in the running of the program, the method further comprises:
judging whether the current abnormity occurring in the program operation is the first abnormity, if not, obtaining abnormity statistical information based on the current abnormity, and writing the abnormity statistical information into a log file;
and if the current abnormality is the first abnormality, executing the step of extracting all levels of log information recorded in the memory to write the log information into a log file.
4. The log management method according to claim 3, wherein the step of determining whether the current exception occurred during the program running is a first exception comprises:
acquiring the current abnormal generation reason and the link information called by the program;
determining a target abnormality type to which the current abnormality belongs according to the abnormality generation reason and the link information;
and detecting whether log information of the target abnormal type exists in the log file, and if so, judging that the current abnormality is not the first abnormality.
5. The log management method of claim 1, wherein the execution of the program involves a plurality of functional levels;
if the program runs abnormally, extracting log information of all levels recorded in the memory to write the log information into a log file, wherein the step comprises the following steps:
if the program runs abnormally, stopping the program running, and positioning the abnormal function level from the plurality of function levels;
and extracting all levels of log information of the abnormal function level recorded in the memory to write the log information into a log file.
6. The log management method according to claim 5, wherein the step of extracting all levels of log information recorded in the memory to write the log information into the log file if the program runs abnormally further comprises:
extracting the log information of the preset level of the function level without the abnormality recorded in the memory aiming at the function level without the abnormality in the plurality of function levels, and writing the log information into a log file;
and deleting the log information of other levels of the function level without the exception, which is recorded in the memory.
7. The log management method of claim 5, wherein said step of locating a functional level from among said plurality of functional levels at which an exception occurs comprises:
acquiring abnormal information captured when the program runs abnormally;
and positioning the function level with the exception according to the stack information in the exception information.
8. The log management method according to claim 5, wherein the step of extracting log information of a preset level recorded in the memory to write the log information into the log file if the program operation is not abnormal includes:
if the program is not abnormal in operation, determining log information corresponding to each function level respectively according to the logic level information of each log information recorded by a memory after the program is finished in operation;
and extracting the log information at a preset level in the log information aiming at the log information corresponding to each function level so as to write the log information into a log file.
9. An apparatus for log management, the apparatus comprising:
the collection module is used for collecting log information of all levels and recording the log information in a memory in the process of starting and running the program;
the first extraction module is used for extracting all levels of log information recorded in the memory to write the log information into a log file when the program operation is abnormal;
and the second extraction module is used for extracting the log information of the preset level recorded in the memory to write the log information into the log file when the program operation is not abnormal.
10. An electronic device comprising one or more storage media and one or more processors in communication with the storage media, the one or more storage media storing processor-executable machine-executable instructions that, when executed by the electronic device, are executed by the processors to perform the method steps of any of claims 1-8.
11. A computer-readable storage medium, characterized in that it stores machine-executable instructions which, when executed, implement the method steps of any one of claims 1-8.
CN202111035619.2A 2021-09-06 2021-09-06 Log management method and device, electronic equipment and readable storage medium Pending CN113468029A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111035619.2A CN113468029A (en) 2021-09-06 2021-09-06 Log management method and device, electronic equipment and readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111035619.2A CN113468029A (en) 2021-09-06 2021-09-06 Log management method and device, electronic equipment and readable storage medium

Publications (1)

Publication Number Publication Date
CN113468029A true CN113468029A (en) 2021-10-01

Family

ID=77867485

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111035619.2A Pending CN113468029A (en) 2021-09-06 2021-09-06 Log management method and device, electronic equipment and readable storage medium

Country Status (1)

Country Link
CN (1) CN113468029A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117130824A (en) * 2023-01-10 2023-11-28 荣耀终端有限公司 Method for processing exception, electronic equipment and storage medium

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20090228745A1 (en) * 2008-03-10 2009-09-10 Fujitsu Limited Error backup method
CN110932910A (en) * 2019-12-05 2020-03-27 锐捷网络股份有限公司 Method and device for recording logs of software faults
CN111124727A (en) * 2019-12-12 2020-05-08 京信通信系统(中国)有限公司 Log processing method, device, equipment and storage medium

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20090228745A1 (en) * 2008-03-10 2009-09-10 Fujitsu Limited Error backup method
CN110932910A (en) * 2019-12-05 2020-03-27 锐捷网络股份有限公司 Method and device for recording logs of software faults
CN111124727A (en) * 2019-12-12 2020-05-08 京信通信系统(中国)有限公司 Log processing method, device, equipment and storage medium

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
张育军 等: "《上海证券交易所联合研究报告 2011 证券信息前沿技术专集》", 30 November 2012, 上海人民出版社 *
恒逸资讯 等: "《SQL Server 2000数据转换服务》", 31 January 2003, 中国铁道出版社 *

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117130824A (en) * 2023-01-10 2023-11-28 荣耀终端有限公司 Method for processing exception, electronic equipment and storage medium

Similar Documents

Publication Publication Date Title
CN109284269B (en) Abnormal log analysis method and device, storage medium and server
US10102113B2 (en) Software test automation systems and methods
US8448138B2 (en) Recording user-driven events within a computing system
CN113708986B (en) Server monitoring apparatus, method and computer-readable storage medium
CN111897696A (en) Server cluster hard disk state detection method and device, electronic equipment and storage medium
CN111143103A (en) Incidence relation determining method, device, equipment and readable storage medium
CN112988503A (en) Analysis method, analysis device, electronic device, and storage medium
CN112650613B (en) Error information processing method and device, electronic equipment and storage medium
CN113468029A (en) Log management method and device, electronic equipment and readable storage medium
CN113590405A (en) Hard disk error detection method and device, storage medium and electronic device
CN111784176A (en) Data processing method, device, server and medium
CN114500249A (en) Root cause positioning method and device
CN115757138A (en) Method and device for determining script abnormal reason, storage medium and electronic equipment
CN115168124A (en) Stability test method and device for concurrently executing multiple files on hard disk, computer equipment and medium
CN115098378A (en) Method and device for classifying and aggregating log fragments based on abnormal breakpoints
CN112162954B (en) User operation log generation and path positioning method, device, equipment and medium
CN112114987B (en) Abnormality detection method and device for operation environment, intelligent terminal and storage medium
CN112860469A (en) Method, device, equipment and storage medium for collecting information of katon log
CN112631929A (en) Test case generation method and device, storage medium and electronic equipment
CN111813695A (en) Code detection method, device, medium and electronic equipment
CN113760696A (en) Program problem positioning method and device, electronic equipment and storage medium
CN117407207B (en) Memory fault processing method and device, electronic equipment and storage medium
CN112286804B (en) System debugging method, device, equipment and medium
CN114884807B (en) Link log generation method and device, internet of things platform and storage medium
CN117742897B (en) Method for realizing automatic repair of vulnerability based on container mirror image

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
RJ01 Rejection of invention patent application after publication
RJ01 Rejection of invention patent application after publication

Application publication date: 20211001