Processing method for outputting system logs in json format for gateway
By adding specific identifiers to the system log and monitoring the process using UDP server, reencapsulating and classifying the system log, the problem of delay in obtaining system log information and difficulty in classification is solved, and efficient and accurate acquisition and processing of log information is achieved.
Patent Information
- Application Number
- CN202411459224.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-18
- Publication Date
- 2025-02-11
AI Technical Summary
In the prior art, the system log information is uniformly stored in a system log file, without relevant type classification identifiers, which leads to the user being unable to directly obtain the required log information, and there is a problem of acquisition delay in extracting log records through the system log file, which affects the acquisition event. accuracy and timeliness.
By modifying the system kernel program, adding specific identifiers to the system logs, and monitoring the process based on the started UDP server, receiving system logs through port 514, intercepting system logs with identifiers, classifying them, and the system logs are in json format Re-encapsulate, add relevant type identifiers, and finally transmit to the receiving interface of the target device through the message queue.
The function of users to directly obtain system logs is realized, the information acquisition efficiency is improved through type identification, and the system log information is synchronized through the UDP server monitoring port. There is basically no delay, which greatly improves the operation efficiency.
Smart Images

Figure CN119415488A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of log data processing, for example, to a processing method for outputting system logs in JSON format for a gateway. Background Art
[0002] The portable operation and maintenance gateway is a domestically produced portable gateway product developed based on the "Technical Specifications for Portable Operation and Maintenance Gateways of Power Monitoring Systems (Trial)" proposed by the State Grid Corporation of China. This product is suitable for the operation and maintenance control of power monitoring systems in substations and distribution stations, as well as the operation and maintenance control of automation equipment equipped in booster stations.
[0003] According to the interface type of the object being operated and maintained, different cables (network cable, RS232 serial cable, USB cable, HDMI video cable) are used to connect the portable operation and maintenance gateway in series between the operation and maintenance terminal and the object being operated and maintained. Since the device needs to control the operation and maintenance work, when the device is connected to the portable operation and maintenance gateway, the portable operation and maintenance gateway needs to record the relevant device access log, and users can query the records as needed.
[0004] Currently, all log information is stored in a system log file without any relevant type classification identification, so users cannot directly obtain the required log information. At the same time, there is a problem of acquisition delay when extracting log records through the system log file, which affects the accuracy and timeliness of the acquired events.
[0005] It should be noted that the information disclosed in the above background technology section is only used to enhance the understanding of the background of this application. Summary of the invention
[0006] In order to provide a basic understanding of some aspects of the disclosed embodiments, a brief summary is given below. The summary is not an extensive review, nor is it intended to identify key / critical components or delineate the scope of protection of these embodiments, but rather serves as a prelude to the detailed description that follows.
[0007] The present disclosure provides a method for processing a gateway to output a system log in JSON format, the method comprising:
[0008] Modify the system kernel program and add specific identifiers in the system log;
[0009] Based on the started UDP server monitoring process, system logs are received through port 514;
[0010] Based on the UDP server monitoring process, intercept the system log with identification;
[0011] Categorize system logs with labels;
[0012] Repackage the system log in JSON format and add relevant type identifiers;
[0013] The encapsulated log information is transmitted to the receiving interface of the target device through the message queue, so that the target device can receive the system log in json format based on the started event receiving interface.
[0014] In some embodiments, the structure corresponding to the JSON format includes version, timestamp, type and detail.
[0015] In some embodiments, before receiving the system log, the method includes:
[0016] When the portable operation and maintenance gateway detects external interface access, the portable operation and maintenance gateway identifies the access interface type and access device information, and the kernel processes the relevant information and sends a system log with an identifier.
[0017] In some embodiments, the intercepting of the system log with the identifier based on the UDP server monitoring process includes:
[0018] Configure the UDP server to record log content;
[0019] Based on preset keywords or identifiers, the recorded log content is analyzed and intercepted.
[0020] In some embodiments, classifying the system logs with the identifiers includes:
[0021] Parse the system logs with identifiers according to the identifiers;
[0022] The parsed logs are classified according to the corresponding log levels.
[0023] The embodiment of the present disclosure provides a processing device for outputting system logs in JSON format for a gateway, the device comprising:
[0024] The processing module is used to modify the system kernel program and add a specific identifier in the system log;
[0025] The processing module is also used to receive system logs through port 514 based on the started UDP server monitoring process;
[0026] The interception module is used to intercept the system logs with identification based on the UDP server monitoring process;
[0027] A classification module is used to classify system logs with labels;
[0028] The encapsulation module is used to re-encapsulate the system log in JSON format and add relevant type identifiers;
[0029] The transmission module is used to transmit the encapsulated log information to the receiving interface of the target device through the message queue, so that the target device can receive the system log in json format based on the started event receiving interface.
[0030] In some embodiments, the structure corresponding to the JSON format includes version, timestamp, type and detail.
[0031] In some embodiments, the storage medium stores program instructions, and when the program instructions are run, they execute the processing method for outputting system logs in JSON format for the gateway in the above embodiment.
[0032] The processing method, device and storage medium for outputting system logs in JSON format provided by the embodiments of the present disclosure can achieve the following technical effects:
[0033] It allows users to directly obtain system logs, and users do not need to filter system logs when using the device, but only need to call relevant interfaces; the system logs are reconstructed, and type identifiers are added to each type of log. Users can obtain the desired event information through the identifiers, which improves the efficiency of information acquisition; by monitoring the UDP server port, system log information can be obtained synchronously, with basically no delay, greatly improving the operating efficiency.
[0034] The above general description and the following description are exemplary and explanatory only and are not intended to limit the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] One or more embodiments are exemplarily described by corresponding drawings, which do not limit the embodiments. Elements with the same reference numerals in the drawings are shown as similar elements, and the drawings do not constitute a scale limitation, and wherein:
[0036] Figure 1 It is a flowchart of a processing method for outputting system logs in JSON format for a gateway provided by an embodiment of the present disclosure;
[0037] Figure 2 It is a structural diagram of a processing device for outputting system logs in JSON format for a gateway provided by an embodiment of the present disclosure;
[0038] Figure 3 It is a structural diagram of a processing system for outputting system logs in JSON format for a gateway provided by an embodiment of the present disclosure. DETAILED DESCRIPTION
[0039] In order to be able to understand the features and technical contents of the embodiments of the present disclosure in more detail, the implementation of the embodiments of the present disclosure is described in detail below in conjunction with the accompanying drawings. The attached drawings are for reference only and are not used to limit the embodiments of the present disclosure. In the following technical description, for the convenience of explanation, a full understanding of the disclosed embodiments is provided through multiple details. However, one or more embodiments can still be implemented without these details. In other cases, to simplify the drawings, well-known structures and devices can be simplified for display.
[0040] The terms "first", "second", etc. in the embodiments of the present disclosure are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the terms used in this way can be interchanged where appropriate, so as to describe the embodiments of the present disclosure described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions.
[0041] Unless otherwise stated, the term "plurality" means two or more.
[0042] In the embodiment of the present disclosure, the character " / " indicates that the preceding and following objects are in an "or" relationship. For example, A / B indicates: A or B.
[0043] The term "and / or" is a description of the association relationship between objects, indicating that three relationships can exist. For example, A and / or B means: A or B, or, A and B.
[0044] The term "correspondence" may refer to an association relationship or a binding relationship. The correspondence between A and B means that there is an association relationship or a binding relationship between A and B.
[0045] The following describes a processing method, device, and storage medium for outputting system logs in JSON format provided by an embodiment of the present disclosure in conjunction with the accompanying drawings.
[0046] Figure 1 It is a flowchart of a processing method for a gateway to output system logs in JSON format provided by an embodiment of the present disclosure.
[0047] like Figure 1 As shown, the processing method for the gateway to output the system log in JSON format may include:
[0048] S01, modify the system kernel program and add a specific identifier in the system log;
[0049] S02, based on the started UDP server monitoring process, receives system logs through port 514;
[0050] S03, intercepting the system log with identification based on the UDP server monitoring process;
[0051] S04, classifying the system logs with the identification;
[0052] S05, repackage the system log in JSON format and add relevant type identification;
[0053] S06, transmitting the encapsulated log information to the receiving interface of the target device through the message queue, so that the target device receives the system log in json format based on the started event receiving interface.
[0054] In the present disclosure, the function of allowing users to directly obtain system logs can be realized, and users do not need to filter system logs when using devices, but only need to call relevant interfaces; the system logs are reconstructed, and type identifiers are added to each type of log. Users can obtain the desired event information through the identifiers, thereby improving the efficiency of information acquisition; by monitoring the UDP server port, system log information can be obtained synchronously, with basically no delay, greatly improving the operating efficiency.
[0055] In some embodiments, the structure corresponding to the JSON format includes version, timestamp, type and detail.
[0056] The specific JSON format structure and attribute definition are shown in Table 1.
[0057] Table 1
[0058] Fields Field Type illustrate version Integer The current default is 1 timestamp Integer Number of seconds since 1970-01-01 00:00:00+0000 (UTC) type Integer Type of event detail Object Specific message information
[0059] In some embodiments, before receiving the system log, the method includes:
[0060] When the portable operation and maintenance gateway detects external interface access, the portable operation and maintenance gateway identifies the access interface type and access device information, and the kernel processes the relevant information and sends a system log with an identifier.
[0061] In a specific example, for example, a U disk device can be inserted into a USB interface of a portable operation and maintenance gateway; the portable operation and maintenance gateway identifies the U disk device; and the system kernel sends a system log with an identification when the insertion of the U disk device is detected.
[0062] In some embodiments, the intercepting of the system log with the identifier based on the UDP server monitoring process includes:
[0063] Configure the UDP server to record log content;
[0064] Based on preset keywords or identifiers, the recorded log content is analyzed and intercepted.
[0065] In some embodiments, classifying the system logs with the identifiers includes:
[0066] Parse the system logs with identifiers according to the identifiers;
[0067] The parsed logs are classified according to the corresponding log levels.
[0068] In a specific example, a method for processing a gateway to output a system log in JSON format may specifically include:
[0069] First, modify the system kernel program to send a log with keywords after detecting device access action on the relevant hardware interface.
[0070] Second, modify the system configuration to synchronously forward the system log to port 514.
[0071] Third, write a UDP server monitoring program to obtain the log data of port 514. Intercept the system log according to the keyword and repackage it into a message event in json format. When reconstructing, classify the log according to the content and add different type identifiers to different logs. The general json structure of the message event is as follows:
[0072] {
[0073] "version":1
[0074] "timestamp":1629895160,
[0075] "type":1,
[0076] "detail":{…}
[0077] }
[0078] The property definitions in the json string are shown in Table 1.
[0079] Fourth, the processed logs are sent to the outside through the message queue, and the encapsulated log information is obtained through the external interface.
[0080] In the present disclosure, the function of allowing users to directly obtain system logs can be realized. When using the device, the user does not need to filter the system logs, but only needs to call the relevant interface; the system logs are reconstructed, and type identifiers are added to each type of log. Users can obtain the desired event information through the identifiers, thereby improving the efficiency of information acquisition; by monitoring the UDP server port, the system log information can be obtained synchronously, with basically no delay, greatly improving the operating efficiency.
[0081] Figure 2 is a schematic diagram of a processing device for outputting system logs in JSON format for a gateway provided by an embodiment of the present disclosure, such as Figure 2 As shown, the processing device for outputting the system log in json format for the gateway may include:
[0082] Processing module 201, used to modify the system kernel program and add a specific identifier in the system log;
[0083] The processing module 201 is also used to monitor the process based on the started UDP server and receive the system log through port 514;
[0084] The interception module 202 is used to intercept the system log with the identifier based on the UDP server monitoring process;
[0085] A classification module 203, used to classify the system logs with identification;
[0086] The encapsulation module 204 is used to re-encapsulate the system log in JSON format and add relevant type identification;
[0087] The transmission module 205 is used to transmit the encapsulated log information to the receiving interface of the target device through the message queue, so that the target device receives the system log in json format based on the started event receiving interface.
[0088] In some embodiments, the structure corresponding to the JSON format includes version, timestamp, type and detail.
[0089] In some embodiments, before receiving the system log, when the portable operation and maintenance gateway detects external interface access, the portable operation and maintenance gateway identifies the access interface type and access device information, and the kernel processes the relevant information and sends the identified system log.
[0090] In some embodiments, the intercepting of the system log with the identifier based on the UDP server monitoring process includes:
[0091] Configure the UDP server to record log content;
[0092] Based on preset keywords or identifiers, the recorded log content is analyzed and intercepted.
[0093] In some embodiments, classifying the system logs with the identifiers includes:
[0094] Parse the system logs with identifiers according to the identifiers;
[0095] The parsed logs are classified according to the corresponding log levels.
[0096] Combination Figure 3 As shown, the embodiment of the present disclosure also provides a processing system 300 for outputting system logs in json format for a gateway, including a processor 304 and a memory 301. Optionally, the system may also include a communication interface 302 and a bus 303. Among them, the processor 304, the communication interface 302, and the memory 301 can communicate with each other through the bus 303. The communication interface 302 can be used for information transmission. The processor 304 can call the logic instructions in the memory 301 to execute the processing method for outputting system logs in json format for a gateway in the above embodiment.
[0097] In addition, the logic instructions in the memory 301 described above can be implemented in the form of software functional units and can be stored in a computer-readable storage medium when sold or used as an independent product.
[0098] The memory 301 is a computer-readable storage medium that can be used to store software programs and computer executable programs, such as program instructions / modules corresponding to the method in the embodiment of the present disclosure. The processor 304 executes the function application and data processing by running the program instructions / modules stored in the memory 301, that is, the processing method for outputting the system log in json format for the gateway in the above embodiment is implemented.
[0099] The memory 301 may include a program storage area and a data storage area, wherein the program storage area may store an operating system and an application required for at least one function; the data storage area may store data created according to the use of the terminal device, etc. In addition, the memory 301 may include a high-speed random access memory and may also include a non-volatile memory.
[0100] The embodiment of the present disclosure provides a computer-readable storage medium storing computer-executable instructions, wherein the computer-executable instructions are configured to execute a processing method for outputting a system log in a JSON format for a gateway.
[0101] The computer-readable storage medium mentioned above may be a transient computer-readable storage medium or a non-transitory computer-readable storage medium.
[0102] The technical solution of the embodiment of the present disclosure can be embodied in the form of a software product, which is stored in a storage medium and includes one or more instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the method of the embodiment of the present disclosure. The aforementioned storage medium may be a non-transient storage medium, including: a USB flash drive, a mobile hard disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a disk or an optical disk, and other media that can store program codes, or a transient storage medium.
[0103] The above description and the accompanying drawings fully illustrate the embodiments of the present disclosure so that those skilled in the art can practice them. Other embodiments may include structural, logical, electrical, process and other changes. The embodiments represent possible changes only. Unless explicitly required, separate components and functions are optional, and the order of operations may vary. Parts and features of some embodiments may be included in or replace parts and features of other embodiments. As used in the description of the embodiments, unless the context clearly indicates otherwise, the singular forms of "a", "an" and "the" are intended to include plural forms as well. Similarly, the term "and / or" as used in this application refers to any and all possible combinations of one or more associated listings. In addition, when used in this application, the term "comprise" and its variants "comprises" and / or including (comprising) refer to the existence of stated features, wholes, steps, operations, elements, and / or components, but do not exclude the existence or addition of one or more other features, wholes, steps, operations, elements, components and / or these groups. In the absence of further restrictions, the elements defined by the sentence "comprising a ..." do not exclude the existence of other identical elements in the process, method or device comprising the elements. In this article, each embodiment may focus on the differences from other embodiments, and the same or similar parts between the embodiments may refer to each other. For the methods, products, etc. disclosed in the embodiments, if they correspond to the method part disclosed in the embodiments, then the relevant parts can refer to the description of the method part.
[0104] Those skilled in the art will appreciate that the units 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 may depend on the specific application and design constraints of the technical solution. Technicians can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the embodiments of the present disclosure. Technicians can clearly understand that for the convenience and simplicity of description, the specific working process of the systems, devices and units described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.
[0105] In the embodiments disclosed herein, the disclosed methods and products (including but not limited to devices, equipment, etc.) can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of units can be only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between each other shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms. The units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the units may be selected according to actual needs to implement this embodiment. In addition, each functional unit in the embodiment of the present disclosure may be integrated in a processing unit, or each unit may exist physically alone, or two or more units may be integrated in one unit.
[0106] The flowchart and block diagram in the accompanying drawings show the possible architecture, functions and operations of the system, method and computer program product according to the embodiment of the present disclosure. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of the code, and a part of the module, program segment or code contains one or more executable instructions for realizing the specified logical function. In some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, which can depend on the functions involved. In the description corresponding to the flowchart and block diagram in the accompanying drawings, the operations or steps corresponding to different boxes can also occur in a different order from the order disclosed in the description, and sometimes there is no specific order between different operations or steps. For example, two consecutive operations or steps can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, which can depend on the functions involved. Each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, may be implemented by a dedicated hardware-based system that performs the specified functions or actions, or may be implemented by a combination of dedicated hardware and computer instructions.
Claims
1. A processing method for outputting system logs in JSON format for a gateway, characterized in that: The method comprises: Modify the system kernel program and add specific identifiers in the system log; Based on the started UDP server monitoring process, system logs are received through port 514; Based on the UDP server monitoring process, intercept the system log with identification; Categorize system logs with labels; Repackage the system log in JSON format and add relevant type identifiers; The encapsulated log information is transmitted to the receiving interface of the target device through the message queue, so that the target device can receive the system log in json format based on the started event receiving interface.
2. The method according to claim 1, characterized in that The structure corresponding to the JSON format includes version, timestamp, type and detail.
3. The method according to claim 1, characterized in that Before receiving the system log, the method includes: When the portable operation and maintenance gateway detects external interface access, the portable operation and maintenance gateway identifies the access interface type and access device information, and the kernel processes the relevant information and sends a system log with an identifier.
4. The method according to claim 1, characterized in that: The UDP server-based monitoring process intercepts the system log with the identifier, including: Configure the UDP server to record log content; Based on preset keywords or identifiers, the recorded log content is analyzed and intercepted.
5. The method according to claim 1, characterized in that The classifying of the system logs with identification includes: Parse the system logs with identifiers according to the identifiers; The parsed logs are classified according to the corresponding log levels.
6. A processing device for outputting system logs in json format for a gateway, characterized in that: The device comprises: The processing module is used to modify the system kernel program and add a specific identifier in the system log; The processing module is also used to receive system logs through port 514 based on the started UDP server monitoring process; The interception module is used to intercept the system logs with identification based on the UDP server monitoring process; A classification module is used to classify system logs with labels; The encapsulation module is used to re-encapsulate the system log in JSON format and add relevant type identifiers; The transmission module is used to transmit the encapsulated log information to the receiving interface of the target device through the message queue, so that the target device can receive the system log in json format based on the started event receiving interface.
7. The device according to claim 6, characterized in that The structure corresponding to the JSON format includes version, timestamp, type and detail.
8. A storage medium storing program instructions, characterized in that: When the program instructions are run, they execute the processing method for outputting system logs in JSON format for the gateway as described in any one of claims 1 to 5.