Method, device and equipment for generating operation log record based on SPI (Serial Peripheral Interface) mechanism
By adopting an SPI mechanism-based method in operation logging, the code complexity and system performance problems are solved, code readability and system performance are improved, and memory consumption and maintenance costs are reduced.
Patent Information
- Application Number
- CN202411789822.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-06
- Publication Date
- 2025-03-18
AI Technical Summary
When recording operation logs, the prior art increases the code complexity, reduces readability and maintainability, and may affect system performance in high concurrency scenarios, and it is difficult to transform the old system and maintain it.
The operation logging method based on the SPI mechanism is adopted. By starting the loading operation log package, reading the log variable parameters, starting the log component to form log information, and determining the log drop mode based on the number of pending logs, scanning and loading the definition SPI function, so that the pending log drops asynchronously, and initializing the listener to determine the system running status.
It improves the readability and maintainability of the code, reduces memory consumption, improves system performance, improves compatibility, and reduces the difficulty and maintenance costs of old system transformation.
Smart Images

Figure CN119645771A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of visual language models, and in particular to an operation log recording method, apparatus and device based on an SPI mechanism. Background Art
[0002] Operation logs, also known as transaction logs, audit logs or activity logs, are a mechanism for recording the operations performed by systems, applications or users in software systems. These logs are essential for ensuring stable system operation, troubleshooting, security audits and compliance requirements.
[0003] Recording operation logs directly in business code will increase the complexity of the code and reduce readability and maintainability. In particular, the needs of operation log recording are often not fully considered at the beginning of the design of old systems, and there is a lack of a unified log framework and standards, which leads to the need to significantly modify the system when supplementing the log function later. It takes a lot of manpower and material resources to transform the old system to add logging functions, especially for large and complex systems. Even if the operation log function is successfully added, subsequent maintenance and upgrades may become difficult due to the old system. Continuous investment of resources is required to maintain the effectiveness and security of the log system. The logging process itself may have an impact on system performance, especially in high-concurrency scenarios. How to reduce the impact of logging on application response time and ensure that the system runs without interference is a consideration when implementing logging. Summary of the invention
[0004] Based on this, it is necessary to provide an operation log recording method, device and equipment based on the SPI mechanism to address the above technical problems, which can at least improve code readability and maintainability, reduce memory consumption, improve performance and improve compatibility.
[0005] In a first aspect, the present application provides an operation log recording method based on the SPI mechanism, comprising: starting to load an operation log package and reading log variable parameters;
[0006] Start the log component to generate log information, and determine the log storage method based on the number of logs to be processed;
[0007] Scan and load the defined SPI function, and write the logs to be processed to disk according to the log writing method;
[0008] Initialize the listener and use the listener to determine whether the system is running normally.
[0009] In one embodiment, the disk placement method is determined by the following steps:
[0010] When the number of log requests to be processed is greater than the preset target number, each request log is asynchronously added to the log queue and queued to wait for storage;
[0011] Start multiple threads in the thread pool to read the logs in the queue at the same time, and divide the logs into batches and aggregate them into batches and write them to the disk;
[0012] After all logs in the log queue are written to the disk, the thread pool recycles thread resources and only retains the minimum number of threads.
[0013] In one embodiment, when the number of requests for logs to be processed is less than or equal to a preset target number, each request log is asynchronously added to a log queue to wait for storage;
[0014] When the log queue reaches the preset threshold, a flush is triggered.
[0015] In one embodiment, the method further comprises:
[0016] The log queue is polled at a preset period and at least one log in the log queue is written to the disk.
[0017] In one embodiment, the method further comprises:
[0018] When the listener detects that the system stops running, the logs in the log queue that have not been written to the disk are written to the disk in batches at one time.
[0019] In one embodiment, the method further comprises:
[0020] Custom function annotation OpLogUDF;
[0021] Define a user-defined function class for registering operation logs and implement the ApplicationContextAware interface to obtain the application context and implement automatic registration of UDF;
[0022] Parameters parse SpEL expressions and log parameters dynamically.
[0023] In a second aspect, the present application further provides an operation log recording device based on the SPI mechanism, the device comprising:
[0024] The variable reading module is used to start loading the operation log package and read the log variable parameters;
[0025] The log storage module is used to start the log component to generate log information and determine the log storage method according to the number of logs to be processed;
[0026] Function loading module, scans and loads the defined SPI function, and writes the logs to be processed to disk according to the log writing method;
[0027] The system monitoring module is used to initialize the monitor and determine whether the system is running normally through the monitor.
[0028] In a third aspect, the present application further provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the following steps are implemented:
[0029] Start loading the operation log package and read the log variable parameters;
[0030] Start the log component to generate log information, and determine the log storage method based on the number of logs to be processed;
[0031] Scan and load definition functions;
[0032] Initialize the listener and use the listener to determine whether the system is running normally.
[0033] In a fourth aspect, the present application further provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the following steps are implemented:
[0034] Start loading the operation log package and read the log variable parameters;
[0035] Start the log component to generate log information, and determine the log storage method based on the number of logs to be processed;
[0036] Scan and load definition functions;
[0037] Initialize the listener and use the listener to determine whether the system is running normally.
[0038] In a fifth aspect, the present application further provides a computer program product, including a computer program, which implements the following steps when executed by a processor:
[0039] Start loading the operation log package and read the log variable parameters;
[0040] Start the log component to generate log information, and determine the log storage method based on the number of logs to be processed;
[0041] Scan and load definition functions;
[0042] Initialize the listener and use the listener to determine whether the system is running normally.
[0043] The above-mentioned operation log recording method, device and equipment based on the SPI mechanism can at least improve code readability and maintainability, reduce memory consumption, improve performance, and improve compatibility. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments of the present application will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without creative work.
[0045] Figure 1 The figure is a flow chart of an operation log recording method based on the SPI mechanism in one embodiment;
[0046] Figure 2 It is a flowchart of an operation log recording method based on the SPI mechanism in another embodiment;
[0047] Figure 3 It is a flowchart of an operation log recording method based on the SPI mechanism in another embodiment;
[0048] Figure 4 It is a structural block diagram of an operation log recording device based on the SPI mechanism in one embodiment;
[0049] Figure 5 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment.
[0050] Reference numerals and descriptions:
[0051] 10. Variable reading module; 20. Log storage module; 30. Function loading module; 40. System monitoring module. DETAILED DESCRIPTION
[0052] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0053] The distributed relational database testing method provided in the embodiment of the present application can be applied to various personal computers, laptops, smart phones, tablet computers, Internet of Things devices and portable wearable devices. The Internet of Things devices can be smart speakers, smart TVs, smart air conditioners, smart car devices, projection devices, etc. Portable wearable devices can be smart watches, smart bracelets, head-mounted devices, etc. Head-mounted devices can be virtual reality (VR) devices, augmented reality (AR) devices, smart glasses, etc.
[0054] It should be noted that in the field of software development, especially in the Java platform, SPI is a mechanism that allows service providers to be discovered and used by service users in the form of plug-ins, without the need for service users to know the specific implementation of the service provider in advance. This is done by reading configuration files at runtime or scanning metadata in jar files in a specific directory (usually using text files in the META-INF / services directory) to dynamically discover and load service implementation classes. This approach promotes modular design and improves the scalability and flexibility of the code. For example, Java's JDBC API is a typical application of SPI, which allows different database vendors to provide their own driver implementations, and the application only needs to load the corresponding driver according to the database type.
[0055] The operation log recording method proposed in this application can be a kind of SDK, where SDK is the abbreviation of Software Development Kit, which means "software development kit" in Chinese. It is a collection of programs and tools designed to help software developers create applications that can work efficiently based on specific software, frameworks, hardware platforms or operating systems. SDK usually includes but is not limited to the following components: API, libraries and frameworks, documents, sample codes, development tools, resource files. The role of SDK is to simplify the development process, improve development efficiency, ensure that developers follow best practices and standards, and also enable software products to be seamlessly integrated with specific environments or services. For example, game SDKs usually integrate functional modules such as user registration, login, payment, and data reporting, allowing game developers to quickly integrate these functions into the game without having to write relevant code from scratch.
[0056] Operation logs are important files or database entries that record user and system activities in software systems, network devices, or IT infrastructure. These logs track in detail who (user), when (time), what (operation), and where (module or system part) was done, and are essential for system maintenance, troubleshooting, security audits, and compliance checks. Operation logs, also known as transaction logs, audit logs, or activity logs, are a mechanism for recording operations performed by systems, applications, or users in software systems. These logs are essential for ensuring stable system operation, troubleshooting, security audits, and compliance requirements. The following is a simplified diagram of the system structure. Figure 1 The purpose of the operation log is as follows:
[0057] Fault diagnosis and troubleshooting: When an exception or performance problem occurs in the system, the operation log provides a detailed sequence of events to help developers track the context of the problem and quickly locate the cause of the problem.
[0058] Security Audit: Records detailed information of every system login and sensitive operation (such as password modification, access permission change, data deletion, etc.), which helps detect unauthorized access or malicious behavior and meet compliance requirements such as GDPR, HIPAA, etc.
[0059] Performance monitoring and optimization: By analyzing data such as timestamps and response times in operation logs, system bottlenecks can be identified and performance can be optimized.
[0060] Business analysis: Operation logs can also be used to analyze user behavior patterns, evaluate the frequency of function usage, and provide data support for product iteration and decision-making.
[0061] Proof of compliance: In industries such as finance and healthcare, keeping detailed operation logs is a legal requirement to prove the legality and traceability of operations.
[0062] Automated O&M: Combining log analysis tools and scripts can automatically trigger alarms, perform fault recovery operations, and improve O&M efficiency.
[0063] Please refer to Figure 1 In an exemplary embodiment, an operation log recording method based on the SPI mechanism is provided, comprising the following steps S101 to S104. Among them:
[0064] Step S101, start loading the operation log package and read the log variable parameters.
[0065] As an example, the request parameters sent by the app may be id: userId: operator id, goodsId: product id, num: quantity, etc.
[0066] Step S102, start the log component to generate log information, and determine the log storage method according to the number of logs to be processed.
[0067] Specifically, the disk placement method can be determined through the following steps: when the number of log requests to be processed is greater than the preset target number, each request log is asynchronously added to the log queue to queue and wait for disk placement; multiple threads are started in the thread pool to read the logs in the queue at the same time, and the logs are divided into batches and aggregated for disk placement; after all the logs in the log queue are placed on disk, the thread pool recycles thread resources and only retains the minimum number of threads.
[0068] Optionally, when the number of log requests to be processed is less than or equal to a preset target number, each request log is asynchronously added to a log queue to wait for disk flushing; when the log queue reaches a preset threshold, a flushing is triggered.
[0069] Specifically, the method further includes: polling the log queue every preset period, and writing at least one log in the log queue to a disk.
[0070] As an example, the preset target number can be 10. When the number of log requests to be processed is greater than 10, the following steps can be performed: each request log is asynchronously added to the log queue to queue and wait for disk storage; the thread pool starts multiple threads to read the logs in the queue together, divide the logs into batches and aggregate them into batches and store them in disk (for example, if there are 100 logs in the queue, 10 threads are started and each thread reads 10 logs. Each thread aggregates the 10 read logs and stores them in batches at one time, which saves a lot of execution time compared to storing logs one by one); all logs in the log queue are stored in disk, and the thread pool recycles thread resources and only retains the minimum number of threads.
[0071] As an example, when the number of requests for logs to be processed is less than or equal to 10, the following steps can be performed: scattered request logs are asynchronously added to the log queue to queue and wait for disk flushing; the log queue reaches a threshold to trigger a flushing (for example, when the log queue accumulates 10 logs, a batch flushing is triggered); periodic polling for flushing (for example, the threshold is 10, the polling time is 30 seconds, that is, polling every 30 seconds, and currently only 8 logs have failed to trigger the threshold for flushing, but the polling time has expired, then the 8 logs in the queue are flushed to disk at one time).
[0072] Step S103, scan and load the defined SPI function, and write the log to be processed to the disk according to the log writing method.
[0073] Specifically, a log provider interface can be defined: it interacts with the log system in an abstract way, defines the basic operations of the log system, and allows different log implementations to be its specific implementation.
[0074] Specifically, a log provider plugin manager can be defined: responsible for managing log provider plugins, including loading, unloading, and managing the life cycle of plugins.
[0075] Specifically, you can define a log provider factory (factory): used to dynamically create and obtain log provider instances based on the configuration specifier. The log provider is a component that specifically implements the logging function, and the factory is responsible for managing and providing instances of these components.
[0076] Step S104: Initialize the listener and determine whether the system is running normally through the listener.
[0077] Optionally, the method further includes: when the listener detects that the system stops running, writing the logs in the log queue that have not been written to the disk to the disk in batches at one time.
[0078] As an example, when the system is shut down, the following steps can be performed: the log listener detects that the system has stopped running; the logs in the queue that have not been written to the disk are written to the disk in batches at one time to prevent log loss (for example, the polling time is 30 seconds, and there are currently only 8 logs in the queue that have not triggered the threshold for writing to the disk and the polling time has not arrived. At this time, if the system is forcibly shut down, it will trigger the 8 logs to be written to the disk in batches before shutting down the system).
[0079] Optionally, the method further includes: customizing function annotation OpLogUDF; defining a user-defined function class for registering operation logs, implementing ApplicationContextAware interface to obtain application context, and realizing automatic registration of UDF; parameter parsing SpEL expression and dynamically logging parameters.
[0080] Exemplarily, the system access log SDK startup process includes: starting to load the operation log package; reading the log variable parameters; starting the log component; initializing the log listener; application startup is completed; the application runs normally and records logs; when the application stops, the log listener is triggered to write the logs that have not been written to the disk.
[0081] The steps of starting the log component include: loading the log disk driver using SPI; initializing the log thread pool if the multi-threaded mode is turned on; initializing the log queue if the asynchronous mode is turned on; initializing the log periodic polling thread if the asynchronous mode is turned on; scanning and loading the definition function.
[0082] For example, Zhang San bought a pair of Nike shoes through the APP and hopes to record the log as follows: Operator: Zhang San, Operation object: Nike shoes, Operation content: Order to buy 1 pair of shoes, Operation time: 2024-11-26 12:24:54, Region: Guangzhou. The request parameters sent by the app are id: userId: operator id, goodsId: product id, num: quantity.
[0083] When the operation log is not connected, the backend process includes: querying whether the product inventory is sufficient based on the goodsId; generating an order; storing the order in the warehouse; returning a successful order; after connecting to the log SDK, the AOP asynchronous method is used to execute the log steps: assembling basic log information Operation time: 2024-11-26 12:24:54, region: Guangzhou; converting userId into Zhang San and goodsId into Nike shoes through custom function conversion parameters, and assembling log information Operator: Zhang San, operation object: Nike shoes, operation content: placing an order to purchase 1 pair of shoes; after forming the complete log information, add it to the log queue and wait for it to be dropped on the disk.
[0084] Specifically, this application uses AOP (aspect-oriented programming) to record logs. The specific steps include: custom annotation (Annotation): log annotation OpLog; custom aspect class (Aspect): separate business logic code from system services (logs, custom function parsing), improve the modularity of the code, reduce coupling, and enable these concerns to be centrally managed and maintained.
[0085] Specifically, this application uses SpEL to call methods of Java objects, including static methods and instance methods, supports method calls with parameters, and supports multiple operators, including arithmetic operators, relational operators, logical operators, regular matching, etc.
[0086] As an example, see Figure 2 , Figure 2 FIG. 2 is a flow chart of an operation log recording method based on the SPI mechanism in another embodiment. Figure 2 As shown, the operation log recording method based on the SPI mechanism includes:
[0087] Step S201, executing front template analysis.
[0088] Step S202, method execution.
[0089] Step S203, determine whether an exception is thrown.
[0090] If not, execute step S204, successful template.
[0091] If yes, execute step S205, failure template.
[0092] Step S206, model analysis.
[0093] Step S207, add the EvaluationContext variable to the RootObject.
[0094] Step S208, spEL parsing.
[0095] Step S209, log recording.
[0096] Step S210, determining whether it is a failed template.
[0097] If yes, execute step S211 and throw an exception.
[0098] If not, execute step S212 to release the LogRecord variable.
[0099] As an example, see Figure 3 , Figure 3FIG. 4 is a flow chart of an operation log recording method based on the SPI mechanism in another embodiment. Figure 3 As shown, the operation log recording method based on the SPI mechanism includes:
[0100] Step S301, importing the SDK package.
[0101] Step S302, adding a tracking point.
[0102] Step S303: configure log parameters.
[0103] Step S304, configuration center.
[0104] Step S305: template analysis.
[0105] Step S306, determining the disk placement method.
[0106] Step S307, storage.
[0107] Step S308, mysql.
[0108] Step S309, log query.
[0109] Step S310, query the channel.
[0110] Step S311, write a log file.
[0111] Step S312, collector.
[0112] Step S313, log service.
[0113] Step S314, query API.
[0114] It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0115] Based on the same inventive concept, the embodiment of the present application also provides an operation log recording device based on the SPI mechanism and an operation log recording method based on the SPI mechanism. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above method, so the specific limitations in the one or more embodiments of the operation log recording device based on the SPI mechanism provided below can refer to the limitations of the operation log recording method based on the SPI mechanism above, and will not be repeated here.
[0116] Please refer to Figure 4 , in an exemplary embodiment, an operation log recording device based on the SPI mechanism is provided, comprising: a variable reading module 10, for starting to load an operation log package and reading log variable parameters;
[0117] The log storage module 20 is used to start the log component to generate log information and determine the log storage method according to the number of logs to be processed;
[0118] The function loading module 30 scans and loads the defined SPI function, and writes the logs to be processed to the disk according to the log writing mode;
[0119] The system monitoring module 40 is used to initialize the monitor and determine whether the system is running normally through the monitor.
[0120] Each module in the above-mentioned operation log recording device based on the SPI mechanism can be implemented in whole or in part by software, hardware and a combination thereof. Each of the above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory in the computer device in the form of software, so that the processor can call and execute the operations corresponding to each of the above modules.
[0121] In an exemplary embodiment, a computer device is provided, which may be a terminal. The computer device includes a processor, a memory, an input / output interface, a communication interface, a display unit, and an input device. The processor, the memory, and the input / output interface are connected via a system bus, and the communication interface, the display unit, and the input device are connected to the system bus via the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner can be implemented through WIFI, a mobile cellular network, near field communication (NFC) or other technologies. When the computer program is executed by the processor, a multimodal information generation method based on a visual regression model is implemented. The display unit of the computer device is used to form a visually visible picture, which may be a display screen, a projection device, or a virtual reality imaging device. The display screen can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer device can be a touch layer covering the display screen, or a button, trackball or touchpad set on the computer device shell, or an external keyboard, touchpad or mouse.
[0122] Those skilled in the art will understand that Figure 5 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0123] In an exemplary embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and when the processor executes the computer program, the following steps are implemented:
[0124] Start loading the operation log package and read the log variable parameters;
[0125] Start the log component to generate log information, and determine the log storage method based on the number of logs to be processed;
[0126] Scan and load the defined SPI function, and write the logs to be processed to disk according to the log writing method;
[0127] Initialize the listener and use the listener to determine whether the system is running normally.
[0128] In one embodiment, a computer readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the following steps are implemented:
[0129] Start loading the operation log package and read the log variable parameters;
[0130] Start the log component to generate log information, and determine the log storage method based on the number of logs to be processed;
[0131] Scan and load the defined SPI function, and write the logs to be processed to disk according to the log writing method;
[0132] Initialize the listener and use the listener to determine whether the system is running normally.
[0133] In one embodiment, a computer program product is provided, comprising a computer program, which, when executed by a processor, implements the following steps:
[0134] Start loading the operation log package and read the log variable parameters;
[0135] Start the log component to generate log information, and determine the log storage method based on the number of logs to be processed;
[0136] Scan and load the defined SPI function, and write the logs to be processed to disk according to the log writing method;
[0137] Initialize the listener and use the listener to determine whether the system is running normally.
[0138] Those of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, an artificial intelligence (AI) processor, etc., but are not limited to this.
[0139] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.
[0140] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be construed as limiting the scope of the present application. It should be noted that, for a person of ordinary skill in the art, several modifications and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. An operation log recording method based on SPI mechanism, characterized in that: The method comprises: Start loading the operation log package and read the log variable parameters; Start the log component to generate log information, and determine the log storage method based on the number of logs to be processed; Scan and load the defined SPI function, and write the logs to be processed to disk according to the log writing method; Initialize the listener and use the listener to determine whether the system is running normally.
2. The operation log recording method based on the SPI mechanism according to claim 1 is characterized in that: Determine the placement method by following the steps below: When the number of log requests to be processed is greater than the preset target number, each request log is asynchronously added to the log queue and queued to wait for storage; Start multiple threads in the thread pool to read the logs in the queue at the same time, and divide the logs into batches and aggregate them into batches and write them to the disk; After all logs in the log queue are written to the disk, the thread pool recycles thread resources and only retains the minimum number of threads.
3. The operation log recording method based on the SPI mechanism according to claim 2 is characterized in that: When the number of log requests to be processed is less than or equal to the preset target number, each request log is asynchronously added to the log queue and queued to be written to the disk; When the log queue reaches the preset threshold, a flush is triggered.
4. The operation log recording method based on the SPI mechanism according to claim 3 is characterized in that: The method further comprises: The log queue is polled at a preset period and at least one log in the log queue is written to the disk.
5. The operation log recording method based on the SPI mechanism according to claim 1 is characterized in that: The method further comprises: When the listener detects that the system stops running, the logs in the log queue that have not been written to the disk are written to the disk in batches at one time.
6. The operation log recording method based on the SPI mechanism according to claim 1 is characterized in that: The method further comprises: Custom function annotation OpLogUDF; Define a user-defined function class for registering operation logs and implement the ApplicationContextAware interface to obtain the application context and implement automatic registration of UDF; Parameters parse SpEL expressions and log parameters dynamically.
7. An operation log recording device based on the SPI mechanism, characterized in that: The device comprises: The variable reading module is used to start loading the operation log package and read the log variable parameters; The log storage module is used to start the log component to generate log information and determine the log storage method according to the number of logs to be processed; Function loading module, scans and loads the defined SPI function, and writes the logs to be processed to disk according to the log writing method; The system monitoring module is used to initialize the monitor and determine whether the system is running normally through the monitor.
8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 6 are implemented.
9. A computer-readable storage medium having a computer program stored thereon, 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 6 are implemented.
10. A computer program product, comprising 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 6 are implemented.
Citation Information
Cited By
Boot full-amount log writing method, computer device, and computer program product
CN122673068A