Log collection method and device, terminal equipment and computer readable storage medium

By collecting log information for a specific duration after the device is initialized and dialed successfully, the problem of log information taking up a large storage space and low analysis efficiency is solved, and efficient network connection failure analysis and troubleshooting is achieved.

CN120498977APending Publication Date: 2025-08-15SHENZHEN STREAMING VIDEO TECH
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202510506931.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-22
Publication Date
2025-08-15

AI Technical Summary

Technical Problem

In the prior art, the log information generated by the network module occupies a large amount of storage space and the operation and maintenance personnel need to filter the effective information from the large amount of log information, resulting in inefficient network connection failure analysis and troubleshooting.

Method used

When the device is initialized successfully, the log information of the first preset duration before the current time is collected and stored; after the device is dialed successfully, the network detection is performed regularly; if the network connection is abnormal, the network abnormal time is determined and the log information of the second preset duration from the time is collected.

Benefits of technology

It significantly reduces unnecessary log information storage, saves storage resources, and improves the efficiency of network connection abnormality analysis and troubleshooting.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120498977A_ABST
    Figure CN120498977A_ABST
Patent Text Reader

Abstract

The invention provides a log collection method and device, terminal equipment and a computer readable storage medium, and the method comprises the steps: when the equipment is successfully initialized, executing an operation of collecting log information, and storing the log information of a first preset duration before the current moment; after equipment dialing succeeds, network detection is carried out regularly, and whether network connection is normal or not is determined; and if it is determined that the network connection is abnormal, determining a network abnormal moment, and collecting log information of a second preset duration from the network abnormal moment. According to the method, unnecessary log information storage can be remarkably reduced, and storage resources are saved; and the validity of the stored log information is improved, so that the fault analysis and troubleshooting efficiency of the network connection abnormity can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of network detection technology, and in particular to a log collection method, apparatus, terminal device, and computer-readable storage medium. Background Art

[0002] With the rapid development of network technology, network modules are widely used in the Internet of Things and Machine-to-Machine (M2M) fields. High-performance network modules generate a large amount of log information during actual operation. For example, in a real network environment, approximately 128MB of log information can be generated every 2 minutes.

[0003] In traditional technical solutions, network module log information is usually continuously captured to monitor its operating status. However, this method has obvious disadvantages: continuously capturing a large amount of log information not only takes up a lot of storage space, but also the operation and maintenance personnel often do not need the log information of normal operation. What is truly valuable is the log information when the network is abnormal. Therefore, the operation and maintenance personnel still need to filter out the valid log information from the large amount of log information, which makes the fault analysis and troubleshooting of network connection abnormalities based on log information inefficient.

[0004] Therefore, how to save storage resources and improve the efficiency of fault analysis and troubleshooting of network connection anomalies is a technical problem that those skilled in the art currently need to solve. Summary of the Invention

[0005] The purpose of this application is to provide a log collection method, apparatus, terminal device, computer-readable storage medium, and computer program product, aiming to save storage resources and improve the efficiency of fault analysis and troubleshooting of network connection anomalies.

[0006] In a first aspect, the present application provides a log collection method. The method comprises:

[0007] When the device is successfully initialized, the operation of collecting log information is performed, and the log information of the first preset time period before the current moment is stored;

[0008] After the device dials successfully, it will periodically perform network detection to determine whether the network connection is normal;

[0009] If it is determined that the network connection is abnormal, the time of the network abnormality is determined, and log information of a second preset time period from the time of the network abnormality is collected.

[0010] In one embodiment, when the device is successfully initialized, performing the operation of collecting log information includes:

[0011] When the device is successfully initialized, a preset number of log files is created; the preset number is determined according to the first preset duration;

[0012] The operation of collecting log information is performed, and the collected log information is stored in each of the log files in sequence according to the circular coverage strategy.

[0013] In one embodiment, the operation of collecting log information and sequentially storing the collected log information into each log file according to a circular overwriting strategy includes:

[0014] Determining a target log file from the preset number of log files;

[0015] Execute the operation of collecting log information and write the log information to the target log file;

[0016] When the target log file is full, re-determine the target log file from the empty log files, return to the step of executing the operation of collecting log information, and write the log information into the target log file;

[0017] If the preset number of log files are all full, the earliest full log file is re-determined as the target log file, the target log file is cleared, and the process returns to the step of executing the operation of collecting log information and writing the log information into the target log file.

[0018] In one embodiment, after the device successfully dials up, performing a network check at regular intervals to determine whether the network connection is normal includes:

[0019] After the device dials up successfully, it performs network detection at regular intervals and determines the network connection status corresponding to each network detection within a preset detection period; the preset detection period includes multiple network detections;

[0020] If the network connection status corresponding to each network detection in the preset detection period is disconnected, it is determined that the network connection is abnormal; otherwise, it is determined that the network connection is normal.

[0021] In one embodiment, after the device successfully dials up, performing a network check at regular intervals to determine whether the network connection is normal includes:

[0022] After the device dials up successfully, a TCP connection is established at a regular interval and the TCP connection is checked to see if it is normal.

[0023] In one embodiment, the method further comprises:

[0024] Determine whether the total amount of the currently stored log information has reached a preset memory limit;

[0025] If the preset memory limit is reached, the first specified number of log files that are filled up are deleted according to the time when each log file is filled up.

[0026] In one embodiment, the method further comprises:

[0027] When it is detected that the network connection is restored, the stored log information is uploaded to the target server.

[0028] In a second aspect, the present application further provides a log collection device. The device includes:

[0029] A first collection module is used to collect log information when the device is successfully initialized, and store the log information for a first preset time period before the current moment;

[0030] The judgment module is used to perform network detection at regular intervals after the device dials successfully to determine whether the network connection is normal;

[0031] The second collection module is used to determine the network abnormality time if it is determined that the network connection is abnormal, and collect log information of a second preset time period from the network abnormality time.

[0032] In a third aspect, the present application further provides a terminal device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the above method when executing the computer program.

[0033] In a fourth aspect, the present application further provides a computer-readable storage medium storing a computer program, which implements the steps of the above method when executed by a processor.

[0034] In a fifth aspect, the present application further provides a computer program product, wherein the computer program product comprises a computer program, and when the computer program is executed by a processor, the steps of the above method are implemented.

[0035] The present application provides a log collection method, which includes: when the device is successfully initialized, executing the operation of collecting log information and storing log information of the first preset time length before the current moment; after the device dials successfully, performing network detection at regular intervals to determine whether the network connection is normal; if it is determined that the network connection is abnormal, determining the time of the network abnormality, and collecting log information of the second preset time length from the time of the network abnormality. It can be seen that this method only stores log information of the first preset time length before the time of the network abnormality and log information of the second preset time length after the time of the network abnormality, thereby significantly reducing unnecessary log information storage and saving storage resources; further, because this method uses log information before and after the time of the network abnormality, it improves the effectiveness of the log information and further improves the efficiency of fault analysis and troubleshooting of network connection abnormalities.

[0036] It is understandable that the log collection device, terminal device, computer-readable storage medium, and computer program product provided in the embodiments of the present application have the same beneficial effects as the above-mentioned log collection method, and will not be described in detail here. BRIEF DESCRIPTION OF THE DRAWINGS

[0037] In order to more clearly illustrate the specific implementation methods of the present application or the technical solutions in the prior art, the following is a brief introduction to the drawings required for use in the specific implementation methods or the description of the prior art. Obviously, the drawings described below are some implementation methods of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.

[0038] Figure 1 A flow chart of a log collection method provided in an embodiment of the present application;

[0039] Figure 2 A schematic diagram of the structure of a log collection device provided in an embodiment of the present application;

[0040] Figure 3 A schematic diagram of the structure of a terminal device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0041] In the following description, specific details such as specific system structures and techniques are provided for purposes of illustration rather than limitation to facilitate a thorough understanding of the embodiments of the present application. However, it will be apparent to those skilled in the art that the present application may be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to avoid obscuring the description of the present application with unnecessary detail.

[0042] It should be understood that when used in the present specification and the appended claims, the term "comprising" indicates the presence of described features, integers, steps, operations, elements and / or components, but does not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or collections thereof.

[0043] It will also be understood that the term "and / or" used in this specification and the appended claims refers to and includes any and all possible combinations of one or more of the associated listed items.

[0044] As used in this specification and the appended claims, the term "if" can be interpreted as "when" or "upon" or "in response to determining" or "in response to detecting," depending on the context. Similarly, the phrase "if it is determined" or "if [described condition or event] is detected" can be interpreted as meaning "upon determination" or "in response to determining" or "upon detection of [described condition or event]" or "in response to detecting [described condition or event]," depending on the context.

[0045] In addition, in the description of the present application specification and the appended claims, the terms "first", "second", "third", etc. are only used to distinguish the descriptions and cannot be understood as indicating or implying relative importance.

[0046] References to "one embodiment" or "some embodiments" in this specification mean that one or more embodiments of the present application include a particular feature, structure, or characteristic described in conjunction with that embodiment. Thus, phrases such as "in one embodiment," "in some embodiments," "in other embodiments," and "in other embodiments" appearing in various places in this specification do not necessarily refer to the same embodiment, but rather mean "one or more but not all embodiments," unless otherwise specifically emphasized. The terms "including," "comprising," "having," and variations thereof all mean "including but not limited to," unless otherwise specifically emphasized. "Multiple" means "two or more."

[0047] An embodiment of the present application provides a log collection method that can be executed by a processor of a terminal device when running a corresponding computer program.

[0048] It should be noted that the terminal device in this embodiment includes a communication module, which is a hardware module with integrated communication functions, and is used to achieve connection and communication between the terminal device and the target network.

[0049] Figure 1This is a flow chart of a log collection method provided in an embodiment of the present application. For ease of illustration, only the portion relevant to this embodiment is shown. The method provided in this embodiment includes the following steps:

[0050] S100: When the device is successfully initialized, an operation of collecting log information is performed, and log information of a first preset time period before the current moment is stored.

[0051] The successful device initialization means that after the terminal device is successfully started or configured, it has completed a series of necessary initialization operations and is in a state where it can work normally.

[0052] In actual applications, when the device is successfully initialized, log capture tools are used to collect logs, i.e., collect log information. Log capture tools include but are not limited to Telegraf, Promtail, Logstash, Fluentd, and Graylog, etc., which are not limited in this embodiment.

[0053] The log information includes error logs, debugging information, and user operation records, etc. This embodiment does not limit the specific content of the log information.

[0054] In this embodiment, after collecting log information, log information of the first preset duration before the current time is stored, that is, the latest log information of the first preset duration is stored. The specific value of the first preset duration can be set according to actual needs, such as setting it to 1 minute, which is not limited in this embodiment. In actual applications, after each information collection, the log information within the corresponding time period to be stored can be determined based on the current time and the first preset duration.

[0055] S200: After the device dials up successfully, a network test is performed regularly to determine whether the network connection is normal.

[0056] Among them, the device dialing success means that the terminal device successfully establishes a network connection through the dialing operation, can normally access the network and perform data communication. The network connection in this embodiment can be a connection between the terminal device and a 4G network or a 5G network, which is not limited in this embodiment.

[0057] Specifically, the device dialing process usually includes:

[0058] Network registration: The terminal device sends a registration request to the target network (4G network or 5G network, etc.);

[0059] Authentication: The target network authenticates the terminal device to confirm whether the terminal device is legitimate;

[0060] Establishing a connection: If the identity authentication of the terminal device is successful, the target network will allocate network resources such as an IP address to the terminal device, and a network connection will be successfully established between the terminal device and the target network.

[0061] After the device dials up successfully, that is, after the terminal device establishes a network connection with the target network for the first time, a timer or loop mechanism is used to periodically perform network detection to achieve the purpose of continuously detecting the network status.

[0062] S300: If it is determined that the network connection is abnormal, the time of the network abnormality is determined, and log information of a second preset time period from the time of the network abnormality is collected.

[0063] It should be noted that if the network connection is determined to be normal, it means that the terminal device can communicate data with the target network. If the network connection is determined to be abnormal, it means that the terminal device cannot communicate data with the target network.

[0064] In this embodiment, since a method of periodic detection of the network status is adopted, the network status can be continuously detected. Therefore, once the network is abnormal, the time of the network abnormality can be determined more accurately. After the time of the network abnormality is determined, the countdown for the second preset time is started, and log information is continuously collected during the countdown of the second preset time. The specific value of the second preset time can be set according to actual needs. For example, if it is set to 1 minute, it means that the log information for 1 minute from the time of the network abnormality is continuously collected, and then the log information collection is stopped. In this way, the 1-2 minute log information collected before the time of the network abnormality is combined to obtain a total of 3 minutes of log information before and after the time of the network abnormality; so that the cause of the network connection abnormality can be analyzed based on the 3-minute log information, and the network connection abnormality can be troubleshooted.

[0065] The embodiment of the present application only stores log information for the first preset time period before the network anomaly moment and log information for the second preset time period after the network anomaly moment, thereby significantly reducing unnecessary log information storage and saving storage resources; further, since the present method uses log information before and after the network anomaly moment, the effectiveness of the log information is improved, further improving the efficiency of fault analysis and troubleshooting of network connection anomalies.

[0066] Based on the above embodiment, this embodiment further illustrates and optimizes the technical solution. Specifically, in this embodiment, step S100 (when the device is successfully initialized, performing the operation of collecting log information and storing log information for a first preset time period before the current moment) includes:

[0067] S110: When the device is successfully initialized, a preset number of log files is created; the preset number is determined according to a first preset duration.

[0068] The preset number can be 2, 4, or 6. This embodiment does not limit the preset number. The file memory quota of each log file and the preset number of log files can be set according to the storage space of the terminal device and the first preset duration of the log information to be stored. If log information needs to be stored for a longer period of time, the first preset duration can be increased by increasing the number of log files or increasing the maximum storage limit of the log files.

[0069] In the present embodiment, when the device is successfully initialized, a preset number of log files are first created. In addition, the log file names of the preset number of log files can be set according to the creation time.

[0070] S120: Execute the operation of collecting log information, and store the collected log information in each log file in sequence according to the circular coverage strategy, so as to store the log information of the first preset time period before the current moment.

[0071] After creating a preset number of log files, the operation of collecting log information is performed, and the collected log information is sequentially stored in each log file according to a circular overwriting strategy to store log information of the first preset time length before the current moment.

[0072] Specifically, for each log file, after the log file is filled with log information, the next log file is written; after all log files are filled, the earliest filled log file is cleared, and the collected log information continues to be stored in the log file.

[0073] Therefore, this method can ensure that the preset number of log files save the latest log information of the first preset time length, thereby ensuring the real-time and validity of the log information.

[0074] Based on the above embodiment, this embodiment further illustrates and optimizes the technical solution. Specifically, in this embodiment, step S120 (performing the operation of collecting log information and sequentially storing the collected log information in each log file according to the cyclic overwriting strategy) includes:

[0075] S121: Determine a target log file from a preset number of log files.

[0076] S122: Execute the operation of collecting log information and write the log information into the target log file.

[0077] In this embodiment, after creating a preset number of log files, the target log file is first determined from the preset number of log files, and the operation of collecting log information is performed, and the collected log information is written to the target log file; the target log file is the log file currently used to write log information.

[0078] S123: When the target log file is full, a new target log file is determined from the empty log files, and the process returns to step S122: performing the operation of collecting log information and writing the log information into the target log file;

[0079] S124: If the preset number of log files are all full, the earliest full log file is re-determined as the target log file, the target log file is cleared, and the process returns to execute the above step S122: executing the operation of collecting log information and writing the log information to the target log file.

[0080] In the process of writing log information to the target log file, determine whether the target log file is full, such as whether the target log file reaches the maximum storage limit; if the target log file is not full, that is, the target log file has not reached the maximum storage limit, continue to write the collected log information to the target log file; if the target log file is full, that is, the target log file reaches the maximum storage limit, then re-determine the target log file from each empty log file, that is, determine an empty log file as the target log file from a preset number of log files, and return to execute the above step S122: execute the operation of collecting log information, and write the log information to the updated target log file.

[0081] Then, determine whether the preset number of log files are all full; if the preset number of log files are all full, the log file that is filled earliest will be re-determined as the target log file, so the target log file is first cleared so that it can rewrite the log information, and then return to execute the above step S122: execute the operation of collecting log information and write the log information to the target log file.

[0082] For example, each time log capture is required, the log capture tool creates two log files, such as the first log file and the second log file, and assumes that the log file names of the first log file and the second log file are log1 and log2 respectively; the maximum storage limit of each log file is 128M, that is, each log file is only allowed to write 128M of log information, and 128M of log information is approximately 1-2 minutes of log information.

[0083] First, determine that the first log file log1 is the target log file; after collecting log information, write the log information to the target log file (first log file log1), and determine whether the written size of the first log file log1 reaches the corresponding maximum storage limit; if the maximum storage limit is not reached, continue to write log information to the first log file log1; if the maximum storage limit is reached, switch the target log file to the second log file log2, and subsequently write log information to the second log file log2.

[0084] After writing log information to the second log file log2, determine whether the written size of the second log file log2 reaches the corresponding maximum storage limit; if the maximum storage limit is not reached, continue to write log information to the second log file log2; if the maximum storage limit is reached, it is necessary to execute an overwrite strategy for the first log file log1: clear the log information in the first log file log1, switch the target log file to the first log file log1, and continue to write log information to the first log file log1; if it is detected again that the written size of the first log file log1 reaches the maximum storage limit, execute an overwrite strategy for the second log file log2: clear the log information in the second log file log2, switch the target log file to the second log file log2, and continue to write log information to the second log file log2.

[0085] According to the above cyclic overwriting strategy, it can be ensured that the first log file log1 and the second log file log2 always store log information of the first preset time period before the current moment.

[0086] In actual applications, if a network connection anomaly is detected, the log capture will be stopped after continuing to capture log information for the second preset time period and storing the corresponding log file; when log information needs to be collected again, the log capture tool will create a preset number of log files again and continue to perform log collection operations according to the above steps.

[0087] According to the method of this embodiment, log files can be recycled, the latest collected log information can be efficiently saved, and the validity of the log information can be guaranteed so that network connection abnormality fault analysis and troubleshooting can be performed subsequently based on the latest collected log information.

[0088] Based on the above embodiment, this embodiment further illustrates and optimizes the technical solution. Specifically, in this embodiment, step S200 (after the device successfully dials up, periodically performing network detection to determine whether the network connection is normal) includes:

[0089] After the device dials up successfully, it performs network detection at regular intervals and determines the network connection status corresponding to each network detection within a preset detection period; the preset detection period includes multiple network detections;

[0090] If the network connection status corresponding to each network detection in the preset detection period is disconnected, it is determined that the network connection is abnormal; otherwise, it is determined that the network connection is normal.

[0091] Specifically, a timer or loop mechanism can be used to implement scheduled network detection. This embodiment does not limit the timing duration, such as performing a network detection every 3 seconds or 5 seconds. The preset detection cycle includes multiple network detections, that is, the preset detection cycle includes multiple timing durations. For example, the preset detection cycle includes 5 network detections; if the timing duration is 3 seconds, the preset detection cycle includes 5 timing durations, that is, the preset detection cycle is 15 seconds.

[0092] Among them, network detection includes detecting the network connection status by sending heartbeat data, or determining the network connection status by attempting network reconnection; the network connection status includes connected and disconnected.

[0093] After performing network detection regularly within a preset detection period, the detection results corresponding to each network detection are determined, that is, whether each network detection is successful is determined; if each network detection within the preset detection period fails, the network connection is determined to be abnormal; otherwise, the network connection is determined to be normal.

[0094] In a specific embodiment, a network test is performed every 3 seconds, and the network connection status corresponding to the network test is determined; if the network connection status corresponding to any one of the 5 network tests within a preset test period of 15 seconds is connected, the network connection is determined to be normal; if the network connection status corresponding to the 5 network tests is disconnected, the network link is determined to be abnormal.

[0095] According to the method of this embodiment, whether the network connection is normal is determined based on each network detection in the preset detection cycle, which can more accurately determine the network connection abnormality, and then accurately determine the time of network abnormality, and collect more effective log information based on the time of network abnormality.

[0096] It should be noted that the heartbeat packet detection method periodically sends data packets on an established connection to detect the network connection status, but the heartbeat packet detection cannot identify abnormal scenarios where the core network rejects new connections. Based on the above embodiment, this embodiment further explains and optimizes the technical solution. Specifically, in this embodiment, after the device successfully dials up, it periodically performs network detection to determine whether the network connection is normal, including:

[0097] After the device dials successfully, it will periodically create a TCP connection and check whether the TCP connection is normal.

[0098] In this embodiment, after the device dials successfully, a timer or a loop mechanism is used to periodically establish a TCP (Transmission Control Protocol) connection. After the TCP connection is established, it is necessary to further detect whether the TCP connection is truly available to determine whether the TCP connection is normal. If the TCP connection is truly available, it indicates that the TCP connection is normal, and the network connection status is determined to be connected; otherwise, the TCP connection is unavailable, indicating that the TCP connection is abnormal, and the network connection status is determined to be disconnected.

[0099] In a specific embodiment, after the device dials successfully, it attempts to create a new TCP connection at intervals of 3 seconds; in each attempt, it creates a TCP socket and attempts to connect to the server; if any TCP connection is successful within the preset detection period of 15 seconds, the network connection is determined to be still normal; if the TCP connection fails for 5 consecutive times (i.e. within 15 seconds), the network connection is determined to be abnormal.

[0100] According to the method of this embodiment, by continuously destroying and re-creating TCP connections, abnormal scenarios in which the core network rejects new connections can be effectively identified, thereby accurately detecting abnormal network connections.

[0101] Based on the above embodiment, this embodiment further illustrates and optimizes the technical solution. Specifically, in this embodiment, the method further includes:

[0102] Determine whether the total amount of currently stored data information has reached the preset memory limit;

[0103] If the preset memory limit is reached, the system deletes the specified number of log files that are filled earliest based on the time when each log file is full.

[0104] Due to the storage space limitation of the terminal device, it is necessary to limit the total amount of stored log information. Specifically, the total amount of currently stored log information can be directly counted, and it can be determined whether the total amount of information reaches the preset memory limit; if the preset memory limit is reached, the log file needs to be deleted. Specifically, the log files here include files for recording log information of the first preset length before the current moment, and files for recording log information of the second preset length after the abnormal moment. According to the full time of each log file, the earliest full specified number of log files are deleted to meet the storage space limitation. If the preset memory limit is not reached, there is no need to delete the log file for the time being, and log information collection continues. This embodiment does not limit the specified number, which can be the same as the preset number of log files created when collecting log information.

[0105] In a specific embodiment, the preset file number threshold is determined based on the preset memory quota and the file size of each log file. When the preset memory quota is 512M, assuming that the maximum storage limit of each log file is 128M, the total number of log files that can be created is 4, that is, the preset file number threshold is 4.

[0106] Count the total number of full log files and determine whether the total number is greater than or equal to the preset file number threshold. If the total number is greater than or equal to the preset file number threshold, delete the specified number of log files that were filled the earliest to meet the storage space limit.

[0107] Assume that the number of log files created by a single log capture to record log information within the first preset time period before the current moment is 2, namely the first log file log1 and the second log file log2; after a network anomaly is detected, another log file (the third log file log3) is created to record log information for the second preset time period after the anomaly moment. Then, when the network is restored, log capture must be performed again to record log information for the first preset time period before the next anomaly, which requires the use of 2 log files. Since the memory is only enough to accommodate 4 log files, after creating the fourth log file log4, the first file log1 is deleted, and then the fifth log file log5 is created. The fourth log file log4 and the fifth log file log5 are used to record log information for the first preset time period before the current moment.

[0108] According to the method of this embodiment, the preset memory quota can be fully utilized to store the latest collected log information, thereby ensuring the validity of the log information.

[0109] Based on the above embodiment, this embodiment further illustrates and optimizes the technical solution. Specifically, in this embodiment, the method further includes:

[0110] When it is detected that the network connection is restored, the stored log information is uploaded to the target server.

[0111] In a specific example, if a network connection anomaly is detected, log capture will be stopped after continuing to capture log information for 1-2 minutes, and the corresponding log file (log information) will be cached locally. Then, the device will try to dial and the network connection status will be monitored in real time.

[0112] When the redial is successful, that is, when the network connection is detected to be restored, a log upload and prompt task is created to upload the cached log file (log information) and the corresponding network abnormality time to the target server, so as to prompt the operation and maintenance personnel to obtain relevant data for analysis and perform fault analysis and troubleshooting of the network connection abnormality based on the log information.

[0113] According to the method of this embodiment, log information can be uploaded to the target server in a timely manner, thereby improving the efficiency of fault analysis and troubleshooting of network connection anomalies.

[0114] It should be understood that the size of the serial numbers of the steps in the above embodiments does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application.

[0115] It should be noted that the information collection process (such as the facial image collection process, fingerprint information collection process, etc.) / feature extraction process involved in this application is performed with the user's knowledge and permission, that is, the information collection process / feature extraction process complies with the requirements of laws and regulations and does not constitute an act that harms the public interest.

[0116] Figure 2 The figure shows a schematic diagram of the structure of a log collection device provided by an embodiment of the present application. Figure 2 As shown, the log collection device of this embodiment includes a first collection module 210, a judgment module 220 and a second collection module 230; wherein,

[0117] The first collection module 210 is used to collect log information when the device is successfully initialized and store log information for a first preset time period before the current moment;

[0118] The judgment module 220 is used to perform a network test at regular intervals to determine whether the network connection is normal after the device dials successfully;

[0119] The second collection module 230 is configured to determine the time of the network anomaly if the network connection is determined to be abnormal, and collect log information for a second preset time period from the time of the network anomaly.

[0120] The log collection device provided in the embodiment of the present application has the same beneficial effects as the above-mentioned log collection method based on network anomalies.

[0121] In one embodiment, the first acquisition module includes:

[0122] The log file creation submodule is used to create a preset number of log files when the device is successfully initialized; the preset number is determined according to the first preset duration;

[0123] The log collection submodule is used to collect log information and store the collected log information in each log file in sequence according to a circular coverage strategy, so as to store log information of a first preset time period before the current moment.

[0124] In one embodiment, the log collection submodule includes:

[0125] a target log file determining unit, configured to determine a target log file from a preset number of log files;

[0126] An execution unit, configured to execute the operation of collecting log information and write the log information into a target log file;

[0127] The first calling unit is used to re-determine the target log file from the empty log files and call the execution unit when the target log file is full;

[0128] The second calling unit is configured to, if a preset number of log files are all full, re-determine the earliest full log file as the target log file, clear the target log file, and call the executing unit.

[0129] In one embodiment, the determination module includes:

[0130] The network detection submodule is used to perform network detection at regular intervals after the device dials up successfully, and to determine the network connection status corresponding to each network detection within a preset detection period; the preset detection period includes multiple network detections;

[0131] The detection result output submodule is used to determine that the network connection is abnormal if the network connection status corresponding to each network detection in the preset detection cycle is disconnected; otherwise, determine that the network connection is normal.

[0132] In one embodiment, the determination module includes:

[0133] The judgment submodule is used to regularly create a TCP connection after the device dials successfully, and to detect whether the TCP connection is normal.

[0134] In one embodiment, a log collection device further includes:

[0135] The quota judgment submodule is used to determine whether the total amount of currently stored log information has reached the preset memory quota;

[0136] The deletion submodule is used to delete the specified number of log files that are filled the earliest according to the time when each log file is full if the preset memory limit is reached.

[0137] In one embodiment, a log collection device further includes:

[0138] The upload module is used to upload the stored log information to the target server when it is detected that the network connection is restored.

[0139] It should be noted that the information interaction, execution process, etc. between the above-mentioned devices / units are based on the same concept as the method embodiment of this application. Their specific functions and technical effects can be found in the method embodiment section and will not be repeated here.

[0140] Those skilled in the art can clearly understand that, for the convenience and brevity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In actual applications, the above-mentioned functions can be distributed and completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiment can be integrated into one processing unit, or each unit can exist physically alone, or two or more units can be integrated into one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application. The specific working process of the units and modules in the above-mentioned system can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.

[0141] Figure 3 This is a schematic diagram of the structure of a terminal device provided in an embodiment of the present application. Figure 3 As shown, the terminal device 300 of this embodiment includes a memory 301, a processor 302, and a computer program 303 stored in the memory 301 and executable on the processor 302; when the processor 302 executes the computer program 303, the steps in the above-mentioned log collection method embodiments are implemented; or when the processor 302 executes the computer program 303, the functions of the modules / units in the above-mentioned device embodiments are implemented.

[0142] Exemplarily, the computer program 303 may be divided into one or more modules / units, one or more of which are stored in the memory 301 and executed by the processor 302 to implement the method of the embodiment of the present application. One or more modules / units may be a series of computer program instruction segments capable of performing specific functions, and the instruction segments are used to describe the execution process of the computer program 303 in the terminal device 300. For example, the computer program 303 may be divided into a first acquisition module, a judgment module, and a second acquisition module, and the specific functions of each module are as follows:

[0143] A first collection module is used to collect log information when the device is successfully initialized, and store log information of a first preset time period before the current moment;

[0144] The judgment module is used to perform network detection at regular intervals after the device dials successfully to determine whether the network connection is normal;

[0145] The second collection module is used to determine the time of network abnormality if it is determined that the network connection is abnormal, and collect log information for a second preset time period from the time of network abnormality.

[0146] In application, the terminal device 300 can be a computing device such as a vehicle terminal, a desktop computer, a notebook, a PDA, or a cloud server. The terminal device 300 can include but is not limited to a memory 301 and a processor 302. It will be understood by those skilled in the art that Figure 3 It is only an example of a terminal device and does not constitute a limitation of the terminal device. It may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, the terminal device may also include input and output devices, network access devices, buses, etc.; among them, the input and output devices may include cameras, audio acquisition / playback devices, display screens, etc.; the network access device may include a communication module for wireless communication with external devices.

[0147] In applications, the processor may be a central processing unit (CPU), other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.

[0148] In applications, memory can be an internal storage unit of a terminal device, such as a hard drive or memory; it can also be an external storage device, such as a plug-in hard drive, a Smart Media Card (SMC), a Secure Digital (SD) card, or a flash memory card. It can also include both internal and external storage units. Memory is used to store operating systems, applications, boot loaders, data, and other programs, such as computer program code. Memory can also be used to temporarily store data that has been output or is about to be output.

[0149] An embodiment of the present application further provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments can be implemented.

[0150] The present application implements all or part of the processes in the above-mentioned embodiment method, which can be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium. When the computer program is executed by the processor, it can implement the steps of the above-mentioned various method embodiments. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may at least include: any entity or device that can carry the computer program code to the terminal device, a recording medium, a computer memory, a read-only memory (ROM), a random access memory (RAM), an electric carrier signal, a telecommunication signal and a software distribution medium. For example, a USB flash drive, a mobile hard disk, a magnetic disk or an optical disk.

[0151] A computer-readable storage medium provided in an embodiment of the present application has the same beneficial effects as the above-mentioned log collection method.

[0152] An embodiment of the present application further provides a computer program product, including a computer program, which can implement the steps in the above-mentioned method embodiments when executed by a processor.

[0153] A computer program product provided in an embodiment of the present application has the same beneficial effects as the above-mentioned log collection method.

[0154] In the above embodiments, the description of each embodiment has its own focus. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant description of other embodiments.

[0155] Those skilled in the art will appreciate that the devices and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0156] In the embodiments provided herein, it should be understood that the disclosed devices and methods may be implemented in other ways. For example, the device embodiments described above are merely illustrative. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interface, or the devices may be indirectly coupled or communicated in some manner, whether electrical, mechanical, or other.

[0157] The above-described embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. These modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the various embodiments of the present application, and should all be included in the scope of protection of the present application.

Claims

1. A log collection method, characterized in that: The method comprises: When the device is successfully initialized, the operation of collecting log information is performed, and the log information of the first preset time period before the current moment is stored; After the device dials successfully, it will periodically perform network detection to determine whether the network connection is normal; If it is determined that the network connection is abnormal, the time of the network abnormality is determined, and log information of a second preset time period from the time of the network abnormality is collected.

2. The method according to claim 1, characterized in that When the device is successfully initialized, performing the operation of collecting log information and storing the log information for a first preset time period before the current moment includes: When the device is successfully initialized, a preset number of log files is created; the preset number is determined according to the first preset duration; The operation of collecting log information is performed, and the collected log information is sequentially stored in each of the log files according to a circular overwriting strategy, so as to store the log information of the first preset time period before the current moment.

3. The method according to claim 2, characterized in that The operation of collecting log information and sequentially storing the collected log information into each log file according to a circular overwriting strategy includes: Determining a target log file from the preset number of log files; Execute the operation of collecting log information and write the log information to the target log file; When the target log file is full, re-determine the target log file from the empty log files, return to the step of executing the operation of collecting log information, and write the log information into the target log file; If the preset number of log files are all full, the earliest full log file is re-determined as the target log file, the target log file is cleared, and the process returns to the step of executing the operation of collecting log information and writing the log information into the target log file.

4. The method according to claim 1, wherein After the device dials up successfully, a network check is performed regularly to determine whether the network connection is normal, including: After the device dials up successfully, it performs network detection at regular intervals and determines the network connection status corresponding to each network detection within a preset detection period; the preset detection period includes multiple network detections; If the network connection status corresponding to each network detection in the preset detection period is disconnected, it is determined that the network connection is abnormal; otherwise, it is determined that the network connection is normal.

5. The method according to claim 1, characterized in that After the device dials up successfully, a network check is performed regularly to determine whether the network connection is normal, including: After the device dials up successfully, a TCP connection is established at a regular interval and the TCP connection is checked to see if it is normal.

6. The method according to any one of claims 1 to 5, characterized in that The method further comprises: Determine whether the total amount of the currently stored log information has reached a preset memory limit; If the preset memory limit is reached, the first specified number of log files that are filled up are deleted according to the time when each log file is filled up.

7. The method according to claim 1, characterized in that The method further comprises: When it is detected that the network connection is restored, the stored log information is uploaded to the target server.

8. A log collection device, characterized in that: The device comprises: A first collection module is used to collect log information when the device is successfully initialized, and store the log information for a first preset time period before the current moment; The judgment module is used to perform network detection at regular intervals after the device dials successfully to determine whether the network connection is normal; The second collection module is used to determine the network abnormality time if it is determined that the network connection is abnormal, and collect log information of a second preset time period from the network abnormality time.

9. A terminal device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.

10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.

Citation Information

Cited By

  • IPv6 lightweight network equipment surveying and mapping method based on behavior fingerprints and hop count verification

    CN121217478A