WO2020252724A1 - Log processing method and device, and computer-readable storage medium - Google Patents

Log processing method and device, and computer-readable storage medium Download PDF

Info

Publication number
WO2020252724A1
WO2020252724A1 PCT/CN2019/091998 CN2019091998W WO2020252724A1 WO 2020252724 A1 WO2020252724 A1 WO 2020252724A1 CN 2019091998 W CN2019091998 W CN 2019091998W WO 2020252724 A1 WO2020252724 A1 WO 2020252724A1
Authority
WO
WIPO (PCT)
Prior art keywords
client
shared memory
server
log
memory
Prior art date
Application number
PCT/CN2019/091998
Other languages
French (fr)
Chinese (zh)
Inventor
廖凯
邱桂添
Original Assignee
深圳市大疆创新科技有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 深圳市大疆创新科技有限公司 filed Critical 深圳市大疆创新科技有限公司
Priority to PCT/CN2019/091998 priority Critical patent/WO2020252724A1/en
Priority to CN201980012096.4A priority patent/CN111699479A/en
Publication of WO2020252724A1 publication Critical patent/WO2020252724A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/18File system types
    • G06F16/1805Append-only file systems, e.g. using logs or journals to store data
    • G06F16/1815Journaling file systems
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/544Buffers; Shared memory; Pipes

Definitions

  • the embodiments of the present invention relate to the field of communications, and in particular to a log processing method, device and computer-readable storage medium.
  • Network equipment, systems and service programs, etc. will generate log logs during operation, and each log records the description of related operations such as date, time, user, and action.
  • large software projects often generate a large number of logs. Because of the large number of logs, how to quickly communicate and store logs has become an urgent problem to be solved.
  • the storage of logs is generally implemented through a Syslog log system.
  • the Syslog log system supports local and remote log storage services by providing calling interfaces, configuration files, and daemon processes.
  • the remote log storage service can obtain logs by monitoring fixed ports.
  • the embodiments of the present invention provide a log processing method, device, and computer-readable storage medium to solve the technical problem that the existing log processing method is not suitable for high-concurrency scenarios and cannot manage logs of multiple processes.
  • the first aspect of the embodiments of the present invention is to provide a log processing method, including:
  • the client sends a registration request to the server through the preset calling interface
  • the server receives the registration request sent by the client
  • the server applies for shared memory for the client according to the registration request
  • the server After the shared memory application is successful, the server sends registration success information to the client;
  • the server obtains the log information from the shared memory and stores it in a preset storage path.
  • the second aspect of the embodiments of the present invention is to provide a log processing method applied to a client, and the method includes:
  • the log information of the client is written into the shared memory of the client and the server.
  • the third aspect of the embodiments of the present invention is to provide a log processing method applied to the server, and the method includes:
  • the fourth aspect of the embodiments of the present invention is to provide a log processing system, including
  • One or more processors are One or more processors;
  • One or more memories are One or more memories
  • the memory is used to store program codes
  • the processor is used to call the program code, and when the program code is executed, it is used to perform the following operations:
  • the log information is obtained from the shared memory through the server and stored in a preset storage path.
  • the fifth aspect of the embodiments of the present invention is to provide a client terminal device, and the terminal device includes:
  • the memory is used to store program codes
  • the processor calls the program code, and when the program code is executed, is used to perform the following operations:
  • the log information is written into the shared memory of the client and the server.
  • a sixth aspect of the embodiments of the present invention is to provide a service terminal device, where the service terminal device includes: a memory and a processor;
  • the memory is used to store program codes
  • the processor calls the program code, and when the program code is executed, is used to perform the following operations:
  • a seventh aspect of the embodiments of the present invention is to provide a computer-readable storage medium on which a computer program is stored, and the computer program is executed by a processor to implement the method described in the first aspect or the second aspect or the third aspect .
  • the log processing method, device, and computer-readable storage medium provided in this embodiment send a registration request to the server through a preset calling interface, so that the server applies for shared memory for the client according to the registration request, and applies for shared memory After success, the registration success information is fed back to the client, where the client and the server share the shared memory. After receiving the registration success information fed back by the server, the log information generated by the client is written into the shared memory so that the server can obtain the log information written by the client from the shared memory and store it in the preset In the storage path. Since the server can apply for shared memory according to at least one thread of at least one client, it can be applied to high-concurrency scenarios, and can effectively manage the logs of multiple processes.
  • FIG. 1 is a schematic flowchart of a log processing method provided by Embodiment 1 of the present invention
  • Embodiment 2 is a schematic flowchart of a log processing method provided by Embodiment 2 of the present invention.
  • Embodiment 3 is a schematic flowchart of a log processing method provided by Embodiment 3 of the present invention.
  • Embodiment 4 is a schematic flowchart of a log processing method provided by Embodiment 4 of the present invention.
  • FIG. 5 is a schematic flowchart of a log processing method according to Embodiment 5 of the present invention.
  • FIG. 6 is a schematic flowchart of a log processing method provided by Embodiment 6 of the present invention.
  • FIG. 7 is a schematic flowchart of a log processing method provided by Embodiment 7 of the present invention.
  • FIG. 8 is a schematic flowchart of a log processing method provided by Embodiment 8 of the present invention.
  • Embodiment 9 is a schematic flowchart of a log processing method provided by Embodiment 9 of the present invention.
  • FIG. 10 is a schematic structural diagram of a client terminal device according to Embodiment 10 of the present invention.
  • FIG. 11 is a schematic structural diagram of a service terminal device provided by Embodiment 11 of the present invention.
  • a component when a component is said to be “fixed to” another component, it can be directly on the other component or a central component may also exist. When a component is considered to be “connected” to another component, it can be directly connected to another component or there may be a centered component at the same time.
  • the present invention provides a log processing method, device, and computer-readable storage medium.
  • the present invention provides The log processing method, device, and computer-readable storage medium can be applied to any log processing scenario.
  • FIG. 1 is a schematic flowchart of a log processing method provided in Embodiment 1 of the present invention. As shown in FIG. 1, the log processing method includes:
  • Step 101 The client sends a registration request to the server through a preset calling interface
  • Step 102 The server receives the registration request sent by the client.
  • Step 103 The server applies for shared memory for the client according to the registration request;
  • Step 104 After the shared memory application is successful, the server sends registration success information to the client;
  • Step 105 When receiving the registration success information fed back by the server, the client writes the log information of the client into the shared memory;
  • Step 106 The server obtains the log information from the shared memory and stores it in a preset storage path.
  • the execution subject of this embodiment is a log processing system, where the log processing system includes a client and a server.
  • the client can send a registration request to the server through a preset calling interface.
  • the server can determine whether to apply for shared memory for the client according to the registration request. For example, if the server’s current storage space is insufficient and its processing capacity is weak, it is not necessary to apply for shared memory for the client according to the registration request; if the server’s current storage space is large and its processing capacity is strong, it can be The registration request applies for shared memory for the client.
  • the client and the server share the shared memory.
  • the client can write the generated log information into the shared memory, and the server can take out the log information from the shared memory. Further, after the server determines that it can apply for shared memory for the client according to the registration request, it can feed back registration success information to the client, so that the client can understand the status of the current registration request in time.
  • the client receives the registration success message sent by the server, it can write the log information that needs to be stored into the shared memory.
  • the registration success information may include the storage address of the shared memory, and the registration success information may be sent by the server to the client through a preset or newly added calling interface. Therefore, the server can obtain the log information stored by the client from the shared memory and store it in a preset storage path.
  • the shared memory is a locked queue instance.
  • the registration request is sent by one of the threads of the client.
  • the registration request may specifically be sent by one of the threads in the client. Since there are multiple threads in the client, each thread can send a registration request to the server. Accordingly, the server can apply for shared memory for the client where the thread is located according to the registration request sent by each thread. By separately applying for shared memory for multiple threads of the client, it is possible to realize log storage under high concurrency.
  • the client sends a registration request to the server through a preset calling interface; the server receives the registration request sent by the client; the server applies for shared memory for the client according to the registration request; when the shared memory applies After success, the server sends the registration success information to the client; when the client receives the registration success information fed back by the server, it writes the log information of the client to the shared memory; the server obtains the log information from the shared memory and stores it To the preset storage path. Since the server can apply for shared memory for the client corresponding to the thread according to at least one thread of at least one client, it can be applied to high-concurrency scenarios, and can effectively manage the logs of multiple processes.
  • the shared memory is a lock-free queue instance.
  • the shared memory may specifically be a lock-free queue instance.
  • the lock-free queue instance may be a lock-free queue instance implemented by a compare and replace (Compare and Set, CAS for short) mechanism, or any other one may be used.
  • An example of a lock-free queue implemented by this mechanism is not limited in the present invention. Using a lock-free queue instance can save lock overhead on the basis of improving log processing efficiency.
  • the log processing method provided in this embodiment uses a lock-free queue instance as a shared memory, thereby improving the log processing effect, and further enabling log processing in a multi-process high-concurrency scenario.
  • the writing the log information of the client into the shared memory includes:
  • the log of each thread in the client is written into the shared memory according to a predetermined thread storage sequence.
  • a thread storage order in order to improve the efficiency of log processing, can be preset.
  • the thread storage order can be determined by one or more of the priority, urgency, data size, and sending time of each thread.
  • the user can also make real-time adjustments according to current needs, and the present invention is not limited here.
  • the log processing method provided in this embodiment can effectively improve the efficiency of log processing by writing the log of each thread in the client into the shared memory in a predetermined thread storage sequence.
  • the writing the log information of the client into the shared memory includes:
  • the priority of the log information can be determined first, and the log information with a priority higher than the preset first printing level can be written into the log information.
  • the first printing level may be set by the user according to actual needs, or may be a printing level preset by the system, which is not limited in the present invention.
  • the printing level of the log information includes OFF level, FATAL level, ERROR level, WARN level, INFO level, DEBUG level, and TRACE level in descending order of priority. And ALL level.
  • log information with a priority higher than the preset first print level is stored in the shared memory, so that the quality of log information can be optimized and the storage space can be reduced. Log processing efficiency.
  • the writing the log information of the client to the shared memory includes:
  • the client writes the log information of the client into the shared memory in an asynchronous storage manner.
  • the existing log processing method since the existing log processing method generally waits for the server to feedback that the log information is stored successfully after the client writes the log information on the server, and performs subsequent log write operations, it is often more Time-consuming, resulting in low log processing efficiency.
  • the log information of the client can be written to the shared memory in the manner of asynchronous storage. Specifically, after the client writes the log information in the shared memory, the subsequent log writing operation can be performed without waiting for the storage success information fed back by the server.
  • the log processing method provided in this embodiment can effectively increase the log writing speed by writing the log information of the client into the shared memory in an asynchronous storage manner, thereby improving log processing efficiency.
  • the storage of log information through asynchronous storage can effectively solve the problem of IO stuck in the prior art using synchronous Zlog storage, which is suitable for real-time requirements. Higher system.
  • the method before sending a registration request to the server through the calling interface preset by the client, the method further includes:
  • the client generates the registration request according to a preset log writing configuration.
  • the log writing configuration may be determined first.
  • the log writing configuration may specifically be input by the user according to current requirements, or may be a default writing configuration, which is not limited in the present invention.
  • Generate a registration request according to the log writing configuration and send the registration request to the server, so that the server can apply for shared memory for the client according to the log writing configuration.
  • the log writing configuration includes at least one of memory size to be occupied, storage mode, storage location, storage subfolder division, and storage subfolder size.
  • different priorities can correspond to different log writing configurations.
  • the log writing configuration with a lower priority can only include the memory size to be occupied, while the log writing of the client with a higher priority
  • the configuration can also include other personalized demand parameters.
  • the log processing method provided in this embodiment generates the registration request according to a preset log writing configuration, so that on the basis of improving the log processing efficiency, the client's personalized requirements in the log writing process can be met.
  • Figure 2 is a schematic flow chart of the log processing method provided by the second embodiment of the present invention.
  • the registration success information fed back by the server is received, the After the log information of the client is written into the shared memory, it further includes:
  • Step 201 The client obtains the number of connections of the shared memory
  • Step 202 The client determines whether the server is disconnected from the shared memory according to the number of connections.
  • the client and the server need to be connected to the shared memory at the same time. Therefore, in order to ensure that the server is not dropped during log processing, the number of shared memory connections can be obtained. It should be noted that when no server is disconnected, the total number of shared memory connections is the total number of servers and clients currently connected to the shared memory. Therefore, the current status of the server can be determined according to the number of connections. After determining the number of connections, you can determine whether the server is disconnected from the shared memory according to the number of connections.
  • the log processing method by acquiring the number of connections of the shared memory, it is determined whether the server is disconnected from the shared memory according to the number of connections. Thereby, the effectiveness of log writing can be ensured, and the efficiency of log processing can be further improved.
  • the determining whether the server is disconnected from the shared memory according to the number of connections includes:
  • the client remains connected to the shared memory, and the number of connections is less than the preset total number of connections, it is determined that the server is disconnected from the shared memory; wherein, the total number of connections is The number of connections to the shared memory in the normal log storage state;
  • the client if the client is currently connected to the shared memory and the number of connections is less than the preset total number of connections, it can be determined that the server is disconnected from the shared memory, where the total number of connections is in the normal log storage state.
  • the number of shared memory connections if the client is currently connected to the shared memory and the number of connections is not less than the preset total number of connections, it can be determined that the server is not currently disconnected. Taking a practical application as an example, if there is currently a client and a server connected to the shared memory, then the number of shared memory connections is 2. If the client detects that the current number of connections in the shared memory is 2, it can be determined that the current server is running normally and not disconnected. Correspondingly, if the client detects that the current number of connections in the shared memory is 1, it can be determined that the server has dropped In order to ensure the normal processing of log information, the server needs to be reminded.
  • the log processing method provided in this embodiment determines that the server is disconnected from the shared memory if the client remains connected to the shared memory and the number of connections is less than the preset total number of connections Connection; the total number of connections is the number of connections to the shared memory in the normal log storage state, if the client is connected to the shared memory, and the number of connections is not less than the preset total number of connections, it is determined
  • the server is not disconnected from the shared memory.
  • FIG. 3 is a schematic flowchart of a log processing method provided in Embodiment 3 of the present invention. Based on any of the above embodiments, as shown in FIG. 3, the method further includes:
  • Step 301 When it is determined that the server is disconnected, send a reconnection request to the server according to a preset frequency
  • Step 302 When the server receives the reconnection request sent by the client, the server reconnects to the shared memory according to the reconnection request.
  • a reconnection request can be sent to the server at a preset frequency, so that the server can re-establish a communication connection with the shared memory according to the reconnection request.
  • the preset frequency can be a preset frequency, or it can be set according to actual needs.
  • the client can send a reconnection request at a higher frequency; if the client The occupied shared memory is relatively large, and the reconnection request can also be sent at a higher frequency, which is not limited in the present invention.
  • the server by sending a reconnection request to the server at a preset frequency when it is determined that the server is disconnected, the server can connect to the shared memory according to the reconnection request , Which can ensure the effectiveness of log writing, and further improve the efficiency of log processing.
  • the registration success information includes the identification code allocated by the server to the client;
  • the reconnection request includes the identification code;
  • the reconnection request to reconnect with the shared memory includes:
  • the server connects to the shared memory according to the identification code in the reconnection request.
  • the server can send a registration success message to the client, where the registration success message includes the identification code assigned by the server to the client.
  • the client detects that the server is disconnected from the shared memory, it can send a reconnection request including the identification code to the server. Therefore, the server can reconnect to the shared memory according to the identification code.
  • the identification code in the received registration success message is placed in the reconnection request and sent to the server, so that the server can reconnect to the shared memory according to the identification code, and then be able to On the basis of ensuring the validity of log writing, the efficiency of log processing is further improved.
  • the server obtains the log information from the shared memory and stores it in a preset storage path, including:
  • the server obtains log information with a priority higher than a preset second printing level from the shared memory, and stores it in a preset storage path.
  • the server since the number of log information written by the client is large, different log information has different priorities. Therefore, in order to optimize the quality of log information and reduce storage space, when the server obtains the log information from the shared memory, it first needs to determine the priority of the log information and set the priority higher than the preset second printing level of the log information , Save to the preset storage path.
  • the second printing level can be set by the user according to actual needs, or can be a printing level preset by the system, which is not limited in the present invention.
  • the printing level of the log information includes OFF level, FATAL level, ERROR level, WARN level, INFO level, DEBUG level, and TRACE level in descending order of priority. And ALL level.
  • the log processing method provided in this embodiment obtains log information with a priority higher than the preset second printing level from the shared memory and stores it in a preset storage path, thereby optimizing the quality of log information and reducing Improve log processing efficiency based on small storage space.
  • the server obtains the log information from the shared memory and stores it in a preset storage path, including:
  • the server obtains the log information from the shared memory in a single-threaded manner and stores it in a preset storage path.
  • the server in order to improve log processing efficiency, after the client writes the log information into the shared memory, the server can obtain the log information from the shared memory in a single process and store it in a preset storage path.
  • the log processing method provided in this embodiment can effectively increase the log writing speed by acquiring the log information from the shared memory in a single-threaded manner and storing it in a preset storage path, thereby improving log processing. effectiveness.
  • the registration request includes the amount of memory to be occupied
  • the application for shared memory for the client according to the registration request includes:
  • the server applies for shared memory for the client according to the remaining amount of memory and the amount of memory to be occupied.
  • the registration request may include the amount of memory to be occupied.
  • the client when it sends a registration request to the server, it can determine the amount of memory to be occupied, and generate a registration request according to the amount of memory to be occupied.
  • the server After receiving the registration request, the server can first determine the current remaining amount of memory, and apply for shared memory for the client according to the remaining amount of memory and the amount of memory to be occupied.
  • the applying for shared memory for the client according to the remaining amount of memory and the amount of memory to be occupied includes:
  • the client can apply for shared memory corresponding to the amount of memory to be occupied; otherwise, if the amount of memory to be occupied is not less than the remaining amount of memory, it means The current remaining memory of the server is insufficient to apply for shared memory for the client. At this time, it can refuse to apply for shared memory for the client.
  • the log processing method provided in this embodiment determines the current remaining amount of memory on the server, and applies for shared memory for the client based on the remaining amount of memory and the amount of memory to be occupied, so that it can quickly apply for the client Shared memory improves log processing efficiency.
  • the registration request further includes the process identifier of the client
  • the applying for shared memory for the client according to the registration request includes:
  • the registration request also includes the process identification.
  • the server can generate a blacklist based on historical experience.
  • the blacklist Include the process ID. Therefore, after the server receives the registration request that includes the process ID, it can detect whether the process ID is included in the blacklist. If so, it can refuse to apply for shared memory for the client. Otherwise, it can be the client according to the registration request. Apply for shared memory.
  • the log information generated by some clients may be more important or some clients have higher priority. Therefore, the server may also generate a whitelist based on historical experience, where the whitelist includes the process identifier.
  • the server After the server receives the registration request including the process ID, it can detect whether the process ID is included in the whitelist. If so, it can provide the client corresponding to the process ID with larger shared memory, or can provide the process Identifies the corresponding client to store log information with lower priority.
  • the server can provide different services to the clients according to different priorities. Therefore, after receiving the registration request including the process identifier, the server can first determine the priority corresponding to the process identifier, and provide the client with a service corresponding to the priority according to the priority.
  • the log processing method provided in this embodiment judges whether the process identifier is included in the preset process blacklist, if it does not exist, apply for shared memory for the process, and if it exists, refuse to apply for shared memory for the process , So that the server can selectively apply for shared memory for the client, and then can ensure the security of the server on the basis of ensuring the efficiency of log processing.
  • the registration request is generated according to a preset log writing configuration
  • the applying for shared memory for the client according to the registration request includes:
  • the server applies for shared memory for the client according to the log writing configuration.
  • the client may first determine the log writing configuration, and generate a registration request according to the log writing configuration.
  • the log writing configuration may specifically be input by the user according to current requirements, or may be a default writing configuration, which is not limited in the present invention.
  • the server can apply for shared memory for the client according to the log writing configuration.
  • the log writing configuration includes at least one of memory size to be occupied, storage mode, storage location, storage subfolder division, and storage subfolder size.
  • the stored subfolders are used to divide the stored subfolders according to different functions of threads, and the stored subfolders can also be divided according to different types of logs.
  • different priorities can correspond to different log writing configurations. For example, the log writing configuration with a lower priority can only include the memory size to be occupied, while the log writing of the client with a higher priority
  • the configuration can also include other personalized demand parameters.
  • the method further includes:
  • the server performs an initialization operation on the shared memory to obtain a lock-free queue instance.
  • the shared memory may be initialized to obtain a lock-free queue instance.
  • the lock-free queue instance can be a lock-free queue instance implemented by a Compare and Replace (Compare and Set, CAS for short) mechanism, or a lock-free queue instance implemented by any other mechanism, and the present invention is not limited here. .
  • Using a lock-free queue instance can save lock overhead on the basis of improving log processing efficiency.
  • the log processing method provided in this embodiment obtains a lock-free queue instance by initializing the shared memory, thereby improving the log processing effect, and further enabling log processing in a multi-process high concurrency scenario.
  • the method further includes:
  • the method further includes:
  • the server monitors the log writing status in the shared memory, and manages the client according to the monitoring result.
  • the client can write log information in the shared memory after receiving the registration success information.
  • the server can monitor the log writing status in the shared memory, and control the client according to the monitoring results. For example, you can determine whether the client is a malicious client based on the log writing status, and whether the client is currently malfunctioning.
  • the log processing method provided in this embodiment monitors the log writing status in the shared memory, and manages and controls the client according to the monitoring result, so that the log processing efficiency can be improved on the basis of improving the log processing efficiency. Effective management and control.
  • the server monitors the log writing status in the shared memory, and manages the client according to the monitoring result, including:
  • the server determines whether the speed at which the client writes the log exceeds a preset speed threshold
  • the current speed at which the client writes the log can be determined, and the status of the client can be determined according to the speed. Specifically, if it is detected that the speed at which the client writes the log exceeds a preset speed threshold, it can be determined that the client is currently malfunctioning, anyway, it means that the current client is operating normally.
  • the monitoring of the log writing status in the shared memory and the management and control of the client according to the monitoring result includes:
  • the number of logs currently written by the client can be determined, and the status of the client can be determined according to the number. Specifically, if it is detected that the number of logs written by the client exceeds a preset number threshold, it can be determined that the client is currently malfunctioning, otherwise, it means that the current client is operating normally.
  • the above two embodiments can be implemented separately or in combination.
  • it can be determined whether the number of logs currently written by the client exceeds the preset number threshold and whether the speed of the client currently writing logs exceeds the preset speed according to the number and speed of logs currently written by the client The threshold, if yes, it is determined that the client is currently malfunctioning, anyway, it means that the current client is operating normally.
  • the log processing method provided in this embodiment determines whether the client is currently malfunctioning by determining whether the number and/or speed of logs currently written by the client exceed the preset number and/or speed threshold, which can effectively achieve the End monitoring.
  • the method further includes:
  • the server manages and controls the log information written by the client according to the authority information.
  • the permission information corresponding to the client can be determined according to the process identifier of the client, and the log information written by the client can be controlled according to the permission information.
  • the All log information is stored; accordingly, if the priority of the client currently writing to the log is lower, when it is detected that the number and/or speed of the current written log of the client exceeds the preset number and/or speed threshold, Part of the log information written by the client can be stored, or the client can be refused to continue to provide shared memory.
  • the authority information corresponding to the client is determined according to the process identifier, and the log information written by the client is controlled according to the authority information, so as to be effective for the client. Control.
  • the method includes:
  • the server obtains the log information from the shared memory, and publishes the log information.
  • the client writes the log information into the shared memory
  • the server can obtain the log information from the shared memory and perform publishing processing.
  • FIG. 4 is a schematic flow chart of a log processing method provided by Embodiment 4 of the present invention, which is applied to a client terminal. As shown in FIG. 4, the method includes:
  • Step 401 Send a registration request to the server through a preset calling interface.
  • the execution subject of this embodiment is a client, where the client may be an application, a process, or a terminal device.
  • the client can send a registration request to the server through a preset calling interface.
  • the server can determine whether to apply for shared memory for the client according to the registration request. For example, if the server’s current storage space is insufficient and its processing capacity is weak, it is not necessary to apply for shared memory for the client according to the registration request; if the server’s current storage space is large and its processing capacity is strong, it can be The registration request applies for shared memory for the client.
  • the client and the server share the shared memory.
  • the client can write the generated log information into the shared memory, and the server can take out the log information from the shared memory. Further, after the server determines that it can apply for shared memory for the client according to the registration request, it can feed back registration success information to the client, so that the client can understand the status of the current registration request in time.
  • the registration request is sent by one of the threads of the client.
  • the registration request may specifically be sent by one of the threads in the client. Since there are multiple threads in the client, each thread can send a registration request to the server. Accordingly, the server can apply for shared memory for the client where the thread is located according to the registration request sent by each thread. By separately applying for shared memory for multiple threads of the client, it is possible to realize log storage under high concurrency.
  • Step 402 When the registration success information fed back by the server is received, the log information of the client is written into the shared memory.
  • the client when the client receives the registration success information sent by the server, it can write the log information that needs to be stored into the shared memory.
  • the registration success information may include the storage address of the shared memory, and the registration success information may be sent by the server to the client through a preset or newly added calling interface. Therefore, the server can obtain the log information stored by the client from the shared memory and store it in a preset storage path.
  • the log processing method provided in this embodiment sends a registration request to the server through a preset calling interface, so that the server applies for shared memory for the client according to the registration request, and reports the successful registration to the client after the shared memory application is successful Information, where the client and server share the shared memory.
  • the log information generated by the client is written into the shared memory so that the server can obtain the log information written by the client from the shared memory and store it in the preset In the storage path. Since the server can apply for shared memory according to at least one thread of at least one client, it can be applied to high-concurrency scenarios, and can effectively manage the logs of multiple processes.
  • the shared memory is a lock-free queue instance.
  • the shared memory may specifically be a lock-free queue instance.
  • the lock-free queue instance may be a lock-free queue instance implemented by a compare and replace (Compare and Set, CAS for short) mechanism, or any other one may be used.
  • An example of a lock-free queue implemented by this mechanism is not limited in the present invention. Using a lock-free queue instance can save lock overhead on the basis of improving log processing efficiency.
  • the log processing method provided in this embodiment uses a lock-free queue instance as a shared memory, thereby improving the log processing effect, and further enabling log processing in a multi-process high-concurrency scenario.
  • the shared memory is a locked queue instance.
  • the writing the log information of the client into the shared memory includes:
  • the log of each thread in the client is written into the shared memory according to a predetermined thread storage sequence.
  • a thread storage order in order to improve the efficiency of log processing, can be preset.
  • the thread storage order can be determined by one or more of the priority, urgency, data size, and sending time of each thread.
  • the user can also make real-time adjustments according to current needs, and the present invention is not limited here.
  • the log processing method provided in this embodiment can effectively improve the efficiency of log processing by writing the log of each thread in the client into the shared memory in a predetermined thread storage sequence.
  • the writing the log information of the client into the shared memory includes:
  • the priority of the log information can be determined first, and the log information with a priority higher than the preset first printing level can be written into the log information.
  • the first printing level may be set by the user according to actual needs, or may be a printing level preset by the system, which is not limited in the present invention.
  • the printing level of the log information includes OFF level, FATAL level, ERROR level, WARN level, INFO level, DEBUG level, and TRACE level in descending order of priority. And ALL level.
  • log information with a priority higher than the preset first print level is stored in the shared memory, so that the quality of log information can be optimized and the storage space can be reduced. Log processing efficiency.
  • the writing the log information of the client to the shared memory includes:
  • the log information of the client is written into the shared memory in an asynchronous storage manner.
  • the existing log processing method since the existing log processing method generally waits for the server to feedback that the log information is stored successfully after the client writes the log information on the server, and performs subsequent log write operations, it is often more Time-consuming, resulting in low log processing efficiency.
  • the log information of the client can be written to the shared memory in the manner of asynchronous storage. Specifically, after the client writes the log information in the shared memory, the subsequent log writing operation can be performed without waiting for the storage success information fed back by the server.
  • the log processing method provided in this embodiment can effectively increase the log writing speed by writing the log information of the client into the shared memory in an asynchronous storage manner, thereby improving log processing efficiency.
  • the storage of log information through asynchronous storage can effectively solve the problem of IO stuck in the prior art using synchronous Zlog storage, which is suitable for real-time requirements. Higher system.
  • the registration information also includes the process identifier of the process that sent the registration request, so that the server can determine whether to provide the process for the process according to the process identifier.
  • Memory information
  • the registration information also includes the process identifier of the process that sent the registration request.
  • the server can generate a blacklist based on historical experience, where the blacklist includes the process identifier. Therefore, after the server receives the registration request that includes the process ID, it can detect whether the process ID is included in the blacklist. If so, it can refuse to apply for shared memory for the client. Otherwise, it can be the client according to the registration request. Apply for shared memory.
  • the log information generated by some clients may be more important or some clients have a higher priority. Therefore, the server may also generate a whitelist based on historical experience, where the whitelist includes the process identifier.
  • the server After the server receives the registration request including the process ID, it can detect whether the process ID is included in the whitelist. If so, it can provide the client corresponding to the process ID with larger shared memory, or can provide the process Identifies the corresponding client to store log information with lower priority.
  • the server can provide different services to the clients according to different priorities. Therefore, after receiving the registration request including the process identifier, the server can first determine the priority corresponding to the process identifier, and provide the client with a service corresponding to the priority according to the priority.
  • the registration information also includes the process identification of the process that sent the registration request, so that the server can selectively apply for shared memory for the client, thereby ensuring log processing efficiency. , To ensure the security of the server.
  • the method before sending a registration request to the server through the calling interface preset by the client, the method further includes:
  • the registration request is generated according to the preset log writing configuration.
  • the log writing configuration may be determined first.
  • the log writing configuration may specifically be input by the user according to current requirements, or may be a default writing configuration, which is not limited in the present invention.
  • Generate a registration request according to the log writing configuration and send the registration request to the server, so that the server can apply for shared memory for the client according to the log writing configuration.
  • the log writing configuration includes at least one of memory size to be occupied, storage mode, storage location, storage subfolder division, and storage subfolder size.
  • different priorities can correspond to different log writing configurations.
  • the log writing configuration with a lower priority can only include the memory size to be occupied, while the log writing of the client with a higher priority
  • the configuration can also include other personalized demand parameters.
  • the log processing method provided in this embodiment generates the registration request according to a preset log writing configuration, so that on the basis of improving the log processing efficiency, the client's personalized requirements in the log writing process can be met.
  • FIG. 5 is a schematic flowchart of a log processing method provided by Embodiment 5 of the present invention.
  • the registration success information fed back by the server is received, the After the log information of the client is written into the shared memory, it further includes:
  • Step 501 Obtain the number of connections of the shared memory.
  • Step 502 Determine whether the server is disconnected from the shared memory according to the number of connections.
  • the client and the server need to be connected to the shared memory at the same time. Therefore, in order to ensure that the server is not dropped during log processing, the number of shared memory connections can be obtained. It should be noted that when no server is disconnected, the total number of shared memory connections is the total number of servers and clients currently connected to the shared memory. Therefore, the current status of the server can be determined according to the number of connections. After determining the number of connections, you can determine whether the server is disconnected from the shared memory according to the number of connections.
  • the log processing method by acquiring the number of connections of the shared memory, it is determined whether the server is disconnected from the shared memory according to the number of connections. Thereby, the effectiveness of log writing can be ensured, and the efficiency of log processing can be further improved.
  • the determining whether the server is disconnected from the shared memory according to the number of connections includes:
  • the client remains connected to the shared memory, and the number of connections is less than the preset total number of connections, it is determined that the server is disconnected from the shared memory; the total number of connections is a normal log The number of connections of the shared memory in the storage state;
  • the client if the client is currently connected to the shared memory and the number of connections is less than the preset total number of connections, it can be determined that the server is disconnected from the shared memory, where the total number of connections is in the normal log storage state.
  • the number of shared memory connections if the client is currently connected to the shared memory and the number of connections is not less than the preset total number of connections, it can be determined that the server is not currently disconnected. Taking a practical application as an example, if there is currently a client and a server connected to the shared memory, then the number of shared memory connections is 2. If the client detects that the current number of connections in the shared memory is 2, it can be determined that the current server is running normally and not disconnected. Correspondingly, if the client detects that the current number of connections in the shared memory is 1, it can be determined that the server has dropped In order to ensure the normal processing of log information, the server needs to be reminded.
  • the log processing method provided in this embodiment determines that the server is disconnected from the shared memory if the client remains connected to the shared memory and the number of connections is less than the preset total number of connections Connection; the total number of connections is the number of connections to the shared memory in the normal log storage state, if the client is connected to the shared memory, and the number of connections is not less than the preset total number of connections, it is determined
  • the server is not disconnected from the shared memory.
  • the method further includes:
  • a reconnection request is sent to the server at a preset frequency.
  • a reconnection request can be sent to the server at a preset frequency, so that the server can re-establish a communication connection with the shared memory according to the reconnection request.
  • the preset frequency can be a preset frequency, or it can be set according to actual needs.
  • the client can send a reconnection request at a higher frequency; if the client The occupied shared memory is relatively large, and the reconnection request can also be sent at a higher frequency, which is not limited in the present invention.
  • a reconnection request is sent to the server at a preset frequency, so that the server can connect according to the reconnection request.
  • the shared memory can ensure the effectiveness of log writing, and further improve the efficiency of log processing.
  • the registration success information includes an identification code allocated by the server to the client; the reconnection request includes the identification code; the identification code is used Therefore, the server can connect to the shared memory according to the identification code in the reconnection request.
  • the server may send registration success information to the client, where the registration success information includes the identification code assigned by the server to the client.
  • the client detects that the server is disconnected from the shared memory, it can send a reconnection request including the identification code to the server. Therefore, the server can reconnect to the shared memory according to the identification code.
  • the identification code in the received registration success message is placed in the reconnection request and sent to the server, so that the server can reconnect to the shared memory according to the identification code, thereby enabling On the basis of ensuring the validity of log writing, the efficiency of log processing is further improved.
  • FIG. 6 is a schematic flowchart of a log processing method provided by Embodiment 6 of the present invention, which is applied to the server side. As shown in FIG. 6, the method includes:
  • Step 601 Receive a registration request sent by the client.
  • Step 602 Apply for shared memory for the client according to the registration request
  • Step 603 After the shared memory application is successful, send registration success information to the client;
  • Step 604 Obtain the log information from the shared memory and store it in a preset storage path.
  • the execution body of this embodiment is the server, where the server can be an application, a process, or a terminal device.
  • the client can use a preset calling interface to The server sends a registration request.
  • the server can receive the registration request sent by the client, and apply for shared memory for the client according to the registration request. For example, if the server’s current storage space is insufficient and its processing capacity is weak, it is not necessary to apply for shared memory for the client according to the registration request; if the server’s current storage space is large and its processing capacity is strong, it can be The registration request applies for shared memory for the client. After successfully applying for shared memory for the client, the registration success message can be sent to the client.
  • the client When receiving the registration success information sent by the server, the client can write log information that needs to be stored into the shared memory, where the registration success information can include the storage address of the shared memory. Since the client and the server are connected to the shared memory at the same time, after the client writes the log information in the shared memory, the server can obtain the log information from the shared memory and store it in a preset storage path.
  • the registration request is sent by one of the threads of the client.
  • the registration request may specifically be sent by one of the threads in the client. Since there are multiple threads in the client, each thread can send a registration request to the server. Accordingly, the server can apply for shared memory for the client corresponding to the thread according to the registration request sent by each thread. By separately applying for shared memory for multiple threads of the client, it is possible to realize log storage under high concurrency.
  • the client finishes writing all the log information, the client disconnects from the shared memory, and the server can reclaim the shared memory currently used by the client so that no other clients can apply for it later.
  • the log processing method provided in this embodiment receives a registration request sent by a client, applies for shared memory for the client according to the registration request, and sends a registration success message to the client after the shared memory application is successful , So that the client writes log information in the shared memory according to the registration success information, acquires the log information from the shared memory, and stores it in a preset storage path. Since the server can apply for shared memory according to at least one thread of at least one client, the log information generated by all processes in the client can be stored in the shared memory, which can be applied to the high concurrency of multiple threads in an application. In turn, the logs of multiple processes can be effectively managed.
  • the acquiring the log information from the shared memory and storing it in a preset storage path includes:
  • the server since the number of log information written by the client is large, different log information has different priorities. Therefore, in order to optimize the quality of log information and reduce storage space, when the server obtains the log information from the shared memory, it first needs to determine the priority of the log information and set the priority higher than the preset second printing level of the log information , Save to the preset storage path.
  • the second printing level can be set by the user according to actual needs, or can be a printing level preset by the system, which is not limited in the present invention.
  • the printing level of the log information includes OFF level, FATAL level, ERROR level, WARN level, INFO level, DEBUG level, and TRACE level in descending order of priority. And ALL level.
  • the log processing method provided in this embodiment obtains log information with a priority higher than the preset second printing level from the shared memory and stores it in a preset storage path, thereby optimizing the quality of log information and reducing Improve log processing efficiency based on small storage space.
  • the server acquiring the log information from the shared memory and storing it in a preset storage path includes:
  • the server obtains the log information from the shared memory in a single-threaded manner and stores it in a preset storage path.
  • the server in order to improve log processing efficiency, after the client writes the log information into the shared memory, the server can obtain the log information from the shared memory in a single process and store it in a preset storage path.
  • the log processing method provided in this embodiment can effectively increase the log writing speed by acquiring the log information from the shared memory in a single-threaded manner and storing it in a preset storage path, thereby improving log processing. effectiveness.
  • FIG. 7 is a schematic flow chart of a log processing method provided by Embodiment 7 of the present invention. Based on any of the foregoing embodiments, as shown in FIG. 7, the registration request includes the amount of memory to be occupied, and the The request to apply for shared memory for the client includes:
  • Step 701 Determine the current remaining amount of memory on the server
  • Step 702 Apply for shared memory for the client according to the remaining amount of memory and the amount of memory to be occupied.
  • the registration request may include the amount of memory to be occupied.
  • the client when it sends a registration request to the server, it can determine the amount of memory to be occupied, and generate a registration request according to the amount of memory to be occupied.
  • the server After receiving the registration request, the server can first determine the current remaining amount of memory, and apply for shared memory for the client according to the remaining amount of memory and the amount of memory to be occupied.
  • the applying for shared memory for the client according to the remaining amount of memory and the amount of memory to be occupied includes:
  • the client can apply for shared memory corresponding to the amount of memory to be occupied; otherwise, if the amount of memory to be occupied is not less than the remaining amount of memory, the The current remaining memory of the server is insufficient to apply for shared memory for the client. At this time, it can refuse to apply for shared memory for the client.
  • the log processing method provided in this embodiment determines the current remaining amount of memory on the server, and applies for shared memory for the client based on the remaining amount of memory and the amount of memory to be occupied, so that it can quickly apply for the client Shared memory improves log processing efficiency.
  • FIG. 8 is a schematic flowchart of a log processing method provided by Embodiment 8 of the present invention.
  • the registration request also includes the process identifier; accordingly, the Applying for shared memory for the client according to the registration request includes:
  • Step 801 Determine whether the process identifier is included in the preset process blacklist
  • Step 802 If it does not exist, apply for shared memory for the process;
  • Step 803 If it exists, refuse to apply for shared memory for the process.
  • the registration request also includes the process identification.
  • the server can generate a blacklist based on historical experience.
  • the blacklist Include the process ID. Therefore, after the server receives the registration request that includes the process ID, it can detect whether the process ID is included in the blacklist. If so, it can refuse to apply for shared memory for the client. Otherwise, it can be the client according to the registration request. Apply for shared memory.
  • the log information generated by some clients may be more important or some clients have higher priority. Therefore, the server may also generate a whitelist based on historical experience, where the whitelist includes the process identifier.
  • the server After the server receives the registration request including the process ID, it can detect whether the process ID is included in the whitelist. If so, it can provide the client corresponding to the process ID with larger shared memory, or can provide the process Identifies the corresponding client to store log information with lower priority.
  • the server can provide different services to the clients according to different priorities. Therefore, after receiving the registration request including the process identifier, the server can first determine the priority corresponding to the process identifier, and provide the client with a service corresponding to the priority according to the priority.
  • the log processing method provided in this embodiment judges whether the process identifier is included in the preset process blacklist, if it does not exist, apply for shared memory for the process, and if it exists, refuse to apply for shared memory for the process , So that the server can selectively apply for shared memory for the client, and then can ensure the security of the server on the basis of ensuring the efficiency of log processing.
  • the registration request is generated according to a preset log writing configuration
  • the applying for shared memory for the client according to the registration request includes:
  • the client may first determine the log writing configuration, and generate a registration request according to the log writing configuration.
  • the log writing configuration may specifically be input by the user according to current requirements, or may be a default writing configuration, which is not limited in the present invention.
  • the server can apply for shared memory for the client according to the log writing configuration.
  • the log writing configuration includes at least one of memory size to be occupied, storage mode, storage location, storage subfolder division, and storage subfolder size.
  • the stored subfolders are used to divide the stored subfolders according to different functions of threads, and the stored subfolders may also be divided according to different types of logs.
  • different priorities can correspond to different log writing configurations. For example, the log writing configuration with a lower priority can only include the memory size to be occupied, while the log writing of the client with a higher priority
  • the configuration can also include other personalized demand parameters.
  • the method further includes:
  • the shared memory may be initialized to obtain a lock-free queue instance.
  • the lock-free queue instance can be a lock-free queue instance implemented by a Compare and Replace (Compare and Set, CAS for short) mechanism, or a lock-free queue instance implemented by any other mechanism, and the present invention is not limited here. .
  • Using a lock-free queue instance can save lock overhead on the basis of improving log processing efficiency.
  • the log processing method provided in this embodiment obtains a lock-free queue instance by initializing the shared memory, thereby improving the log processing effect, and further enabling log processing in a multi-process high concurrency scenario.
  • the method further includes:
  • the method further includes:
  • the client and the server need to be connected to the shared memory at the same time. Therefore, when the client detects that the server is disconnected from the shared memory, it can send a reconnection request to the server. Correspondingly, after receiving the reconnection request, the server can re-establish a communication connection with the shared memory according to the reconnection request.
  • the registration success information includes the identification code allocated by the server to the client;
  • the reconnection request includes the identification code;
  • the reconnection request to reconnect with the shared memory includes:
  • the server may send registration success information to the client, where the registration success information includes the identification code assigned by the server to the client.
  • the client detects that the server is disconnected from the shared memory, it can send a reconnection request including the identification code to the server. Therefore, the server can reconnect to the shared memory according to the identification code.
  • the log processing method provided in this embodiment connects to the shared memory according to the identification code in the reconnection request, so that the server can reconnect to the shared memory according to the identification code, and thus can ensure that the log is written On the basis of the effectiveness, the efficiency of log processing is further improved.
  • the method further includes:
  • the log writing status in the shared memory is monitored, and the client is managed and controlled according to the monitoring result.
  • the client can write log information in the shared memory after receiving the registration success information.
  • the server can monitor the log writing status in the shared memory, and control the client according to the monitoring results. For example, you can determine whether the client is a malicious client based on the log writing status, and whether the client is currently malfunctioning.
  • the log processing method provided in this embodiment monitors the log writing status in the shared memory, and manages and controls the client according to the monitoring result, so that the log processing efficiency can be improved on the basis of improving the log processing efficiency. Effective management and control.
  • the monitoring of the log writing status in the shared memory and the management and control of the client according to the monitoring result includes:
  • the current speed at which the client writes the log can be determined, and the status of the client can be determined according to the speed. Specifically, if it is detected that the speed at which the client writes the log exceeds a preset speed threshold, it can be determined that the client is currently malfunctioning, anyway, it means that the current client is operating normally.
  • the monitoring of the log writing status in the shared memory and the management and control of the client according to the monitoring result includes:
  • the number of logs currently written by the client can be determined, and the status of the client can be determined according to the number. Specifically, if it is detected that the number of logs written by the client exceeds a preset number threshold, it can be determined that the client is currently malfunctioning, otherwise, it means that the current client is operating normally.
  • the above two embodiments can be implemented separately or in combination.
  • it can be determined whether the number of logs currently written by the client exceeds the preset number threshold and whether the speed of the client currently writing logs exceeds the preset speed according to the number and speed of logs currently written by the client The threshold, if yes, it is determined that the client is currently malfunctioning, anyway, it means that the current client is operating normally.
  • the log processing method provided in this embodiment determines whether the client is currently malfunctioning by determining whether the number and/or speed of logs currently written by the client exceed the preset number and/or speed threshold, which can effectively achieve the End monitoring.
  • Fig. 9 is a schematic flowchart of a log processing method according to the ninth embodiment of the present invention. Based on any of the foregoing embodiments, as shown in Fig. 9, after determining that the client is faulty, the method further includes:
  • Step 901 Determine permission information corresponding to the client according to the process identifier.
  • Step 902 Manage and control the log information written by the client according to the authority information.
  • the permission information corresponding to the client can be determined according to the process identifier of the client, and the log information written by the client can be controlled according to the permission information.
  • the All log information is stored; accordingly, if the priority of the client currently writing to the log is lower, when it is detected that the number and/or speed of the current written log of the client exceeds the preset number and/or speed threshold, Part of the log information written by the client can be stored, or the client can be refused to continue to provide shared memory.
  • the authority information corresponding to the client is determined according to the process identifier, and the log information written by the client is controlled according to the authority information, so as to be effective for the client. Control.
  • the method further includes: acquiring the log information from the shared memory, and performing publishing processing on the log information.
  • the client writes the log information into the shared memory
  • the server can obtain the log information from the shared memory and perform publishing processing.
  • FIG. 10 is a schematic structural diagram of a client terminal device according to Embodiment 10 of the present invention. As shown in FIG. 10, the terminal device includes:
  • the memory 111 is used to store program codes
  • the processor 112 calls the program code, and when the program code is executed, is configured to perform the following operations:
  • the shared memory is a lock-free queue instance.
  • the shared memory is an example of a locked queue.
  • the registration request is sent by one of the threads of the client.
  • the processor when the processor writes the log information of the client into the shared memory, it is configured to:
  • the log of each thread in the client is written into the shared memory according to a predetermined thread storage sequence.
  • the processor when the processor writes the log information of the client into the shared memory, it is configured to:
  • the printing level of the log information includes OFF level, FATAL level, ERROR level, WARN level, INFO level, DEBUG level, and TRACE level in descending order of priority. And ALL level.
  • the processor when the processor writes the log information of the client to the shared memory, it is configured to:
  • the log information of the client is written into the shared memory in an asynchronous storage manner.
  • the registration information also includes the process identifier of the process that sent the registration request, so that the server can determine whether to provide the process for the process according to the process identifier.
  • Memory information
  • the processor before sending a registration request to the server through the calling interface preset by the client, the processor is further configured to:
  • the registration request is generated according to the preset log writing configuration.
  • the log writing configuration includes at least one of the size of the memory to be occupied, the storage mode, the storage location, the division of storage subfolders, and the size of the storage subfolders.
  • the processor writes the log information of the client into the shared memory when receiving the registration success information fed back by the server, it also uses in:
  • the processor when determining whether the server is disconnected from the shared memory according to the number of connections, the processor is configured to:
  • the client remains connected to the shared memory, and the number of connections is less than the preset total number of connections, it is determined that the server is disconnected from the shared memory; the total number of connections is a normal log The number of connections of the shared memory in the storage state;
  • the processor is further configured to:
  • a reconnection request is sent to the server at a preset frequency.
  • the registration success information includes an identification code allocated by the server to the client; the reconnection request includes the identification code; the identification code is used Therefore, the server can connect to the shared memory according to the identification code in the reconnection request.
  • FIG. 11 is a schematic structural diagram of a service terminal device according to Embodiment 11 of the present invention. As shown in FIG. 11, the service terminal device includes: a memory 121 and a processor 122;
  • the memory 121 is used to store program codes
  • the processor 122 calls the program code, and when the program code is executed, is used to perform the following operations:
  • the registration success information is sent to the client, so that the client writes log information in the shared memory according to the registration success information, and the registration success information includes all The shared memory;
  • the log information is obtained from the shared memory and stored in a preset storage path.
  • the processor when the processor obtains the log information from the shared memory and stores it in a preset storage path, it is configured to:
  • the printing level of the log information includes OFF level, FATAL level, ERROR level, WARN level, INFO level, DEBUG level, and TRACE level in descending order of priority. And ALL level.
  • the processor when the server obtains the log information from the shared memory and stores it in a preset storage path, the processor is configured to:
  • the server obtains the log information from the shared memory in a single-threaded manner and stores it in a preset storage path.
  • the registration request includes the amount of memory to be occupied, and when applying for shared memory for the client according to the registration request, the processor is configured to:
  • the processor when the processor applies for shared memory for the client according to the remaining amount of memory and the amount of memory to be occupied, the processor is configured to:
  • the registration request further includes the process identifier
  • the processor when applying for shared memory for the client according to the registration request, the processor is configured to:
  • the registration request is generated according to a preset log writing configuration
  • the processor When applying for shared memory for the client according to the registration request, the processor is configured to:
  • the log writing configuration includes at least one of the size of the memory to be occupied, the storage mode, the storage location, the division of storage subfolders, and the size of the storage subfolders.
  • the processor is further configured to:
  • an initialization operation is performed on the shared memory to obtain a locked queue instance.
  • the processor is further configured to:
  • the registration success information includes an identification code assigned by the server to the client;
  • the reconnection request includes the identification code;
  • the processor is When reconnecting to the shared memory according to the reconnection request, it is used to:
  • the processor after sending the registration success information to the client, the processor is further configured to:
  • the log writing status in the shared memory is monitored, and the client is managed and controlled according to the monitoring result.
  • the processor is configured to monitor the log writing status in the shared memory and to manage and control the client according to the monitoring result:
  • the processor when the processor monitors the log writing status in the shared memory, and controls the client according to the monitoring result, it is configured to:
  • the processor is further configured to:
  • the log information written by the client is managed and controlled according to the authority information.
  • the processor is further configured to: obtain the log information from the shared memory, and perform publishing processing on the log information.
  • the present invention also provides a log processing system, which includes
  • One or more processors are One or more processors;
  • One or more memories are One or more memories
  • the memory is used to store program codes
  • the processor is used to call the program code, and when the program code is executed, it is used to perform the following operations:
  • the server receives the registration request sent by the client
  • the server applies for shared memory for the client according to the registration request
  • the server After the shared memory application is successful, the server sends registration success information to the client;
  • the server obtains the log information from the shared memory and stores it in a preset storage path.
  • the above method can be completed by one processor or by multiple servers.
  • the client program and the server program are both set in the same device.
  • the client program corresponds to one processor for execution
  • the server program corresponds to one processor for execution.
  • the two can be set in the same device or in two independent devices.
  • the present invention is There is no restriction.
  • the shared memory is a lock-free queue instance.
  • the shared memory is a locked queue instance.
  • the registration request is sent by one of the threads of the client.
  • the processor when the processor writes the log information of the client into the shared memory through the client, it is configured to:
  • the log of each thread in the client is written into the shared memory through the client according to a predetermined thread storage sequence.
  • the processor when the processor writes the log information of the client into the shared memory through the client, it is configured to:
  • the log information whose priority is higher than the preset first printing level is stored in the shared memory through the client.
  • the printing level of the log information includes OFF level, FATAL level, ERROR level, WARN level, INFO level, DEBUG level, and TRACE level in descending order of priority. And ALL level.
  • the processor when the processor writes the log information of the client into the shared memory through the client, it is configured to:
  • the log information of the client is written into the shared memory through the client in an asynchronous storage manner.
  • the processor before sending a registration request to the server through the calling interface preset by the client, the processor is further configured to:
  • the registration request is generated by the client according to a preset log writing configuration.
  • the log writing configuration includes at least one of the size of the memory to be occupied, the storage mode, the storage location, the division of storage subfolders, and the size of the storage subfolders.
  • the processor when the processor receives the registration success information fed back by the server, writes the log information of the client into the shared memory through the client After the middle, it is also used for:
  • the client determines whether the server is disconnected from the shared memory according to the number of connections.
  • the processor determines whether the server is disconnected from the shared memory according to the number of connections through the client, it is configured to:
  • the client determines that the server is disconnected from the shared memory; wherein, The total number of connections is the number of connections of the shared memory in the normal log storage state;
  • the client maintains a connection with the shared memory, and the number of connections is not less than a preset total number of connections, it is determined by the client that the server is not disconnected from the shared memory.
  • the processor is further configured to:
  • the server When the server receives the reconnection request sent by the client, the server reconnects to the shared memory according to the reconnection request.
  • the registration success information includes the identification code allocated by the server to the client;
  • the reconnection request includes the identification code;
  • the processor is passing When the server reconnects to the shared memory according to the reconnection request, it is used to:
  • the processor when the processor obtains the log information from the shared memory through the server and stores it in a preset storage path, it is configured to:
  • the printing level of the log information includes OFF level, FATAL level, ERROR level, WARN level, INFO level, DEBUG level, and TRACE level in descending order of priority. And ALL level.
  • the processor when the processor obtains the log information from the shared memory through the server and stores it in a preset storage path, it is configured to:
  • the log information is obtained from the shared memory in a single-threaded manner through the server and stored in a preset storage path.
  • the registration request includes the amount of memory to be occupied
  • the processor uses the server to apply for shared memory for the client according to the registration request.
  • the server applies for shared memory for the client according to the remaining amount of memory and the amount of memory to be occupied.
  • the processor when the processor applies for shared memory for the client according to the remaining amount of memory and the amount of memory to be occupied through the server, the processor is configured to:
  • the registration request further includes the process identifier of the client
  • the processor when applying for shared memory for the client through the server according to the registration request, the processor is configured to:
  • the registration request is generated according to a preset log writing configuration
  • the processor applies for shared memory for the client according to the registration request through the server, it is configured to:
  • the server applies for shared memory for the client according to the log writing configuration.
  • the log writing configuration includes at least one of the size of the memory to be occupied, the storage mode, the storage location, the division of storage subfolders, and the size of the storage subfolders.
  • the processor after the processor receives the registration request sent by the client through the server, the processor further includes:
  • the server initializes the shared memory to obtain a locked queue instance.
  • the processor after the processor receives the registration request sent by the client through the server, the processor further includes:
  • the server initializes the shared memory to obtain a locked queue instance.
  • the processor after the processor sends registration success information to the client through the server, the processor further includes:
  • the log writing status in the shared memory is monitored by the server, and the client is managed and controlled according to the monitoring result.
  • the processor monitors the log writing status in the shared memory through the server, and controls the client according to the monitoring result. in:
  • the server determines whether the speed at which the client writes the log exceeds a preset speed threshold
  • the processor monitors the log writing status in the shared memory through the server, and controls the client according to the monitoring result. in:
  • the server determines whether the number of logs written by the client exceeds a preset number threshold
  • the processor is further configured to:
  • the server manages and controls the log information written by the client according to the authority information.
  • the processor is configured to:
  • the server obtains the log information from the shared memory, and publishes the log information.
  • this embodiment also provides a computer-readable storage medium on which a computer program is stored, and the computer program is executed by a processor to implement the log processing method described in the foregoing embodiment.
  • the disclosed device and method may be implemented in other ways.
  • the device embodiments described above are only illustrative.
  • the division of the units is only a logical function division, and there may be other divisions in actual implementation, for example, multiple units or components can be combined or It can be integrated into another system, or some features can be ignored or not implemented.
  • the displayed or discussed mutual coupling or direct coupling or communication connection may be indirect coupling or communication connection through some interfaces, devices or units, and may be in 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 achieve the objectives of the solutions of the embodiments.
  • the functional units in the various embodiments of the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units may be integrated into one unit.
  • the above-mentioned integrated unit may be implemented in the form of hardware, or may be implemented in the form of hardware plus software functional units.
  • the above-mentioned integrated unit implemented in the form of a software functional unit may be stored in a computer readable storage medium.
  • the above-mentioned software functional unit is stored in a storage medium and includes several instructions to make a computer device (which may be a personal computer, a server, or a network device, etc.) or a processor execute the method described in the various embodiments of the present invention. Part of the steps.
  • the aforementioned storage media include: U disk, mobile hard disk, read-only memory (Read-Only Memory, ROM), random access memory (Random Access Memory, RAM), magnetic disk or optical disk and other media that can store program code .

Landscapes

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

Abstract

Provided in the embodiments of the present invention are a log processing method and device, and a computer-readable storage medium. The method comprises: a client sending a registration request to a server by means of a preset calling interface; the server receiving the registration request sent by the client; the server applying for a shared memory for the client according to the registration request; after the shared memory is applied for successfully, the server sending registration success information to the client; when receiving the registration success information fed back by the server, the client writing log information of the client into the shared memory; and the server acquiring the log information from the shared memory, and storing the log information to a preset storage path. Since the server can apply for, according to at least one thread of at least one client, the shared memory for the client corresponding to the thread, the log processing method can be applied to a high concurrency scenario, and then can effectively manage logs of a plurality of processes.

Description

日志处理方法、设备及计算机可读存储介质Log processing method, equipment and computer readable storage medium 技术领域Technical field
本发明实施例涉及通信领域,尤其涉及一种日志处理方法、设备及计算机可读存储介质。The embodiments of the present invention relate to the field of communications, and in particular to a log processing method, device and computer-readable storage medium.
背景技术Background technique
网络设备、系统及服务程序等,在运作时都会产生log日志,每一日志都记载着日期、时间、使用者及动作等相关操作的描述。实际应用中,大型软件项目往往会产生大量的日志,由于日志数量较大,因此,如何快速实现日志的通信以及存储成为了亟待解决的问题。Network equipment, systems and service programs, etc., will generate log logs during operation, and each log records the description of related operations such as date, time, user, and action. In practical applications, large software projects often generate a large number of logs. Because of the large number of logs, how to quickly communicate and store logs has become an urgent problem to be solved.
现有技术中一般都是通过Syslog日志系统实现对日志的存储。具体地,Syslog日志系统通过提供调用接口、配置文件以及守护进程的方式,支持本地与远端的日志存储服务,远端的日志存储服务可以通过监听固定端口实现对日志的获取。In the prior art, the storage of logs is generally implemented through a Syslog log system. Specifically, the Syslog log system supports local and remote log storage services by providing calling interfaces, configuration files, and daemon processes. The remote log storage service can obtain logs by monitoring fixed ports.
但是,采用上述方法进行日志存储时,需要两个socket实现双向的数据交互,其不适用于高并发场景,且不能分开对多个进程的日志进行管理。However, when the above method is used for log storage, two sockets are required to realize two-way data interaction, which is not suitable for high-concurrency scenarios, and the logs of multiple processes cannot be managed separately.
发明内容Summary of the invention
本发明实施例提供一种日志处理方法、设备及计算机可读存储介质,以解决现有的日志处理方法不适用于高并发场景,且无法对多个进程的日志进行管理的技术问题。The embodiments of the present invention provide a log processing method, device, and computer-readable storage medium to solve the technical problem that the existing log processing method is not suitable for high-concurrency scenarios and cannot manage logs of multiple processes.
本发明实施例的第一方面是提供一种日志处理方法,包括:The first aspect of the embodiments of the present invention is to provide a log processing method, including:
客户端通过预设的调用接口向服务端发送注册请求;The client sends a registration request to the server through the preset calling interface;
所述服务端接收客户端发送的注册请求;The server receives the registration request sent by the client;
所述服务端根据所述注册请求为所述客户端申请共享内存;The server applies for shared memory for the client according to the registration request;
当所述共享内存申请成功后,所述服务端向所述客户端发送注册成功信息;After the shared memory application is successful, the server sends registration success information to the client;
所述客户端当接收到所述服务端反馈的注册成功信息时,将所述客户 端的日志信息写入所述共享内存中;When the client receives the registration success information fed back by the server, writes the log information of the client into the shared memory;
所述服务端从所述共享内存中获取所述日志信息,并存储至预设的存储路径。The server obtains the log information from the shared memory and stores it in a preset storage path.
本发明实施例的第二方面是提供一种日志处理方法,应用于客户端,所述方法包括:The second aspect of the embodiments of the present invention is to provide a log processing method applied to a client, and the method includes:
通过预设的调用接口向服务端发送注册请求Send a registration request to the server through the preset calling interface
当接收到所述服务端反馈的注册成功信息时,将所述客户端的日志信息写入所述客户端和所述服务端的共享内存中。When the registration success information fed back by the server is received, the log information of the client is written into the shared memory of the client and the server.
本发明实施例的第三方面是提供一种日志处理方法,应用于服务端,所述方法包括:The third aspect of the embodiments of the present invention is to provide a log processing method applied to the server, and the method includes:
接收客户端发送的注册请求;Receive the registration request sent by the client;
根据所述注册请求为所述客户端申请共享内存;Apply for shared memory for the client according to the registration request;
当所述共享内存申请成功后,向所述客户端发送注册成功信息;After the shared memory application is successful, send registration success information to the client;
从所述客户端和服务端的共享内存中获取所述客户端的日志信息,并存储至预设的存储路径。Obtain the log information of the client from the shared memory of the client and the server, and store it in a preset storage path.
本发明实施例的第四方面是提供一种日志处理系统,包括The fourth aspect of the embodiments of the present invention is to provide a log processing system, including
一个或多个处理器;One or more processors;
一个或多个存储器;One or more memories;
所述存储器用于存储程序代码;The memory is used to store program codes;
所述处理器,用于调用所述程序代码,当程序代码被执行时,用于执行以下操作:The processor is used to call the program code, and when the program code is executed, it is used to perform the following operations:
通过客户端预设的调用接口向服务端发送注册请求;Send a registration request to the server through the call interface preset by the client;
通过所述服务端接收客户端发送的注册请求;Receiving the registration request sent by the client through the server;
通过所述服务端根据所述注册请求为所述客户端申请共享内存;Apply for shared memory for the client through the server according to the registration request;
当所述共享内存申请成功后,通过所述服务端向所述客户端发送注册成功信息;After the shared memory application is successful, send registration success information to the client through the server;
当接收到所述服务端反馈的注册成功信息时,通过所述客户端将所述客户端的日志信息写入所述共享内存中;When receiving the registration success information fed back by the server, write the log information of the client into the shared memory through the client;
通过所述服务端从所述共享内存中获取所述日志信息,并存储至预设的存储路径。The log information is obtained from the shared memory through the server and stored in a preset storage path.
本发明实施例的第五方面是提供一种客户终端设备,所述终端设备包括:The fifth aspect of the embodiments of the present invention is to provide a client terminal device, and the terminal device includes:
存储器和处理器;Memory and processor;
所述存储器用于存储程序代码;The memory is used to store program codes;
所述处理器,调用所述程序代码,当程序代码被执行时,用于执行以下操作:The processor calls the program code, and when the program code is executed, is used to perform the following operations:
通过预设的调用接口向服务端发送注册请求Send a registration request to the server through the preset calling interface
当接收到所述服务端反馈的注册成功信息时,将日志信息写入所述客户端和所述服务端的共享内存中。When the registration success information fed back by the server is received, the log information is written into the shared memory of the client and the server.
本发明实施例的第六方面是提供一种服务终端设备,,所述服务终端设备包括:存储器和处理器;A sixth aspect of the embodiments of the present invention is to provide a service terminal device, where the service terminal device includes: a memory and a processor;
所述存储器用于存储程序代码;The memory is used to store program codes;
所述处理器,调用所述程序代码,当程序代码被执行时,用于执行以下操作:The processor calls the program code, and when the program code is executed, is used to perform the following operations:
接收客户端发送的注册请求;Receive the registration request sent by the client;
根据所述注册请求为所述客户端申请共享内存;Apply for shared memory for the client according to the registration request;
当所述共享内存申请成功后,向所述客户端发送注册成功信息;After the shared memory application is successful, send registration success information to the client;
从所述共享内存中获取所述客户端的日志信息,并存储至预设的存储路径。Obtain the log information of the client from the shared memory and store it in a preset storage path.
本发明实施例的第七方面是提供一种计算机可读存储介质,其上存储有计算机程序,所述计算机程序被处理器执行以实现第一方面或第二方面或第三方面所述的方法。A seventh aspect of the embodiments of the present invention is to provide a computer-readable storage medium on which a computer program is stored, and the computer program is executed by a processor to implement the method described in the first aspect or the second aspect or the third aspect .
本实施例提供的日志处理方法、设备及计算机可读存储介质,通过预设的调用接口向服务端发送注册请求,以使服务端根据该注册请求为客户端申请共享内存,并在共享内存申请成功后向客户端反馈注册成功信息,其中,客户端与服务端共享该共享内存。当接收到服务端反馈的注册成功信息之后,将客户端产生的日志信息写入该共享内存中,以使服务端可以从该共享内存中获取客户端写入的日志信息,并存储至预设的存储路径中。由于服务端可以根据至少一个客户端的至少一个线程申请共享内存,从而能够适用于高并发场景,进而能够对多个进程的日志进行有效管理。The log processing method, device, and computer-readable storage medium provided in this embodiment send a registration request to the server through a preset calling interface, so that the server applies for shared memory for the client according to the registration request, and applies for shared memory After success, the registration success information is fed back to the client, where the client and the server share the shared memory. After receiving the registration success information fed back by the server, the log information generated by the client is written into the shared memory so that the server can obtain the log information written by the client from the shared memory and store it in the preset In the storage path. Since the server can apply for shared memory according to at least one thread of at least one client, it can be applied to high-concurrency scenarios, and can effectively manage the logs of multiple processes.
附图说明Description of the drawings
为了更清楚地说明本发明实施例中的技术方案,下面将对实施例描述中所需要使用的附图作一简单地介绍,显而易见地,下面描述中的附图是本发明的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动性的前提下,还可以根据这些附图获得其他的附图。In order to explain the technical solutions in the embodiments of the present invention more clearly, the following will briefly introduce the drawings used in the description of the embodiments. Obviously, the drawings in the following description are some embodiments of the present invention. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative labor.
图1为本发明实施例一提供的日志处理方法的流程示意图;FIG. 1 is a schematic flowchart of a log processing method provided by Embodiment 1 of the present invention;
图2为本发明实施例二提供的日志处理方法的流程示意图;2 is a schematic flowchart of a log processing method provided by Embodiment 2 of the present invention;
图3为本发明实施例三提供的日志处理方法的流程示意图;3 is a schematic flowchart of a log processing method provided by Embodiment 3 of the present invention;
图4为本发明实施例四提供的日志处理方法的流程示意图;4 is a schematic flowchart of a log processing method provided by Embodiment 4 of the present invention;
图5为本发明实施例五提供的日志处理方法的流程示意图;FIG. 5 is a schematic flowchart of a log processing method according to Embodiment 5 of the present invention;
图6为本发明实施例六提供的日志处理方法的流程示意图;6 is a schematic flowchart of a log processing method provided by Embodiment 6 of the present invention;
图7为本发明实施例七提供的日志处理方法的流程示意图;FIG. 7 is a schematic flowchart of a log processing method provided by Embodiment 7 of the present invention;
图8为本发明实施例八提供的日志处理方法的流程示意图;FIG. 8 is a schematic flowchart of a log processing method provided by Embodiment 8 of the present invention;
图9为本发明实施例九提供的日志处理方法的流程示意图;9 is a schematic flowchart of a log processing method provided by Embodiment 9 of the present invention;
图10为本发明实施例十提供的客户终端设备的结构示意图;FIG. 10 is a schematic structural diagram of a client terminal device according to Embodiment 10 of the present invention;
图11为本发明实施例十一提供的服务终端设备的结构示意图。FIG. 11 is a schematic structural diagram of a service terminal device provided by Embodiment 11 of the present invention.
具体实施方式Detailed ways
下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚地描述,显然,所描述的实施例仅仅是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。The technical solutions in the embodiments of the present invention will be clearly described below in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative work shall fall within the protection scope of the present invention.
需要说明的是,当组件被称为“固定于”另一个组件,它可以直接在另一个组件上或者也可以存在居中的组件。当一个组件被认为是“连接”另一个组件,它可以是直接连接到另一个组件或者可能同时存在居中组件。It should be noted that when a component is said to be "fixed to" another component, it can be directly on the other component or a central component may also exist. When a component is considered to be "connected" to another component, it can be directly connected to another component or there may be a centered component at the same time.
除非另有定义,本文所使用的所有的技术和科学术语与属于本发明的技术领域的技术人员通常理解的含义相同。本文中在本发明的说明书中所使用的术语只是为了描述具体的实施例的目的,不是旨在于限制本发明。本文所使用的术语“及/或”包括一个或多个相关的所列项目的任意的 和所有的组合。Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by those skilled in the technical field of the present invention. The terms used in the description of the present invention herein are only for the purpose of describing specific embodiments, and are not intended to limit the present invention. The term "and/or" as used herein includes any and all combinations of one or more of the related listed items.
下面结合附图,对本发明的一些实施方式作详细说明。在不冲突的情况下,下述的实施例及实施例中的特征可以相互组合。Hereinafter, some embodiments of the present invention will be described in detail with reference to the accompanying drawings. In the case of no conflict, the following embodiments and features in the embodiments can be combined with each other.
为了解决现有的日志处理方法不适用于高并发场景,且无法对多个进程的日志进行管理的技术问题,本发明提供了一种日志处理方法、设备及计算机可读存储介质,本发明提供的日志处理方法、设备及计算机可读存储介质能够应用于任意一种日志处理场景中。In order to solve the technical problem that the existing log processing method is not suitable for high concurrency scenarios and cannot manage the logs of multiple processes, the present invention provides a log processing method, device, and computer-readable storage medium. The present invention provides The log processing method, device, and computer-readable storage medium can be applied to any log processing scenario.
图1为本发明实施例一提供的日志处理方法的流程示意图,如图1所示,所述日志处理方法包括:FIG. 1 is a schematic flowchart of a log processing method provided in Embodiment 1 of the present invention. As shown in FIG. 1, the log processing method includes:
步骤101、客户端通过预设的调用接口向服务端发送注册请求;Step 101: The client sends a registration request to the server through a preset calling interface;
步骤102、所述服务端接收客户端发送的注册请求;Step 102: The server receives the registration request sent by the client.
步骤103、所述服务端根据所述注册请求为所述客户端申请共享内存;Step 103: The server applies for shared memory for the client according to the registration request;
步骤104、当所述共享内存申请成功后,所述服务端向所述客户端发送注册成功信息;Step 104: After the shared memory application is successful, the server sends registration success information to the client;
步骤105、所述客户端当接收到所述服务端反馈的注册成功信息时,将所述客户端的日志信息写入所述共享内存中;Step 105: When receiving the registration success information fed back by the server, the client writes the log information of the client into the shared memory;
步骤106、所述服务端从所述共享内存中获取所述日志信息,并存储至预设的存储路径。Step 106: The server obtains the log information from the shared memory and stores it in a preset storage path.
本实施例的执行主体为日志处理系统,其中,日志处理系统中包括客户端以及服务端。为了实现对日志信息的存储,客户端可以通过预设的调用接口向服务端发送注册请求。相应地,服务端接收到该注册请求之后,可以根据该注册请求确定是否为该客户端申请共享内存。举例来说,若服务端当前存储空间不足、处理能力较弱,则可以不根据该注册请求为客户端申请共享内存;若服务端当前存储空间较多,且处理能力较强,则可以根据该注册请求为客户端申请共享内存。其中,客户端和服务端共享该共享内存,具体地,客户端可以将产生的日志信息写入至该共享内存中,服务端可以从该共享内存中取出日志信息。进一步地,当服务端根据该注册请求确定可以为客户端申请共享内存之后,可以向客户端反馈注册成功信息,以使客户端对当前注册请求的状态进行及时了解。客户端在接收到服务端发送的注册成功信息时,可以将需要进行存储的日志信息写入至该共 享内存中。其中,该注册成功信息中可以包括该共享内存的存储地址,该注册成功信息可以由服务端通过预设或新增的调用接口向客户端发送。因此,服务端可以从该共享内存中获取客户端存储的日志信息并存储至预设的存储路径。The execution subject of this embodiment is a log processing system, where the log processing system includes a client and a server. In order to realize the storage of log information, the client can send a registration request to the server through a preset calling interface. Correspondingly, after receiving the registration request, the server can determine whether to apply for shared memory for the client according to the registration request. For example, if the server’s current storage space is insufficient and its processing capacity is weak, it is not necessary to apply for shared memory for the client according to the registration request; if the server’s current storage space is large and its processing capacity is strong, it can be The registration request applies for shared memory for the client. The client and the server share the shared memory. Specifically, the client can write the generated log information into the shared memory, and the server can take out the log information from the shared memory. Further, after the server determines that it can apply for shared memory for the client according to the registration request, it can feed back registration success information to the client, so that the client can understand the status of the current registration request in time. When the client receives the registration success message sent by the server, it can write the log information that needs to be stored into the shared memory. Wherein, the registration success information may include the storage address of the shared memory, and the registration success information may be sent by the server to the client through a preset or newly added calling interface. Therefore, the server can obtain the log information stored by the client from the shared memory and store it in a preset storage path.
可选地,在上述任一实施例的基础上,所述共享内存为有锁队列实例。Optionally, on the basis of any of the foregoing embodiments, the shared memory is a locked queue instance.
进一步地,在上述任一实施例的基础上,所述注册请求由所述客户端的其中一个线程发送。Further, on the basis of any of the foregoing embodiments, the registration request is sent by one of the threads of the client.
在本实施例中,该注册请求具体可以是客户端中的其中一个线程发送。由于客户端中具有多个线程,每一线程均可以向服务端发送注册请求,相应地,服务端可以根据各线程发送的注册请求分别为该线程所在的客户端申请共享内存。通过分别为客户端的多个线程申请共享内存,从而能够实现在高并发情况下的日志存储。In this embodiment, the registration request may specifically be sent by one of the threads in the client. Since there are multiple threads in the client, each thread can send a registration request to the server. Accordingly, the server can apply for shared memory for the client where the thread is located according to the registration request sent by each thread. By separately applying for shared memory for multiple threads of the client, it is possible to realize log storage under high concurrency.
本实施例提供的日志处理方法,客户端通过预设的调用接口向服务端发送注册请求;服务端接收客户端发送的注册请求;服务端根据注册请求为客户端申请共享内存;当共享内存申请成功后,服务端向客户端发送注册成功信息;客户端当接收到服务端反馈的注册成功信息时,将客户端的日志信息写入共享内存中;服务端从共享内存中获取日志信息,并存储至预设的存储路径。由于服务端可以根据至少一个客户端的至少一个线程为该线程对应的客户端申请共享内存,从而能够适用于高并发场景,进而能够对多个进程的日志进行有效管理。In the log processing method provided in this embodiment, the client sends a registration request to the server through a preset calling interface; the server receives the registration request sent by the client; the server applies for shared memory for the client according to the registration request; when the shared memory applies After success, the server sends the registration success information to the client; when the client receives the registration success information fed back by the server, it writes the log information of the client to the shared memory; the server obtains the log information from the shared memory and stores it To the preset storage path. Since the server can apply for shared memory for the client corresponding to the thread according to at least one thread of at least one client, it can be applied to high-concurrency scenarios, and can effectively manage the logs of multiple processes.
进一步地,在上述任一实施例的基础上,所述共享内存为无锁队列实例。Further, on the basis of any of the foregoing embodiments, the shared memory is a lock-free queue instance.
在本实施例中,该共享内存具体可以为无锁队列实例,该无锁队列实例可以是由比较与替换(Compare and Set,简称CAS)机制实现的无锁队列实例,也可以采用其他任意一种机制实现的无锁队列实例,本发明在此不做限制。使用无锁队列实例能够在提高日志处理效率的基础上,节省锁开销。In this embodiment, the shared memory may specifically be a lock-free queue instance. The lock-free queue instance may be a lock-free queue instance implemented by a compare and replace (Compare and Set, CAS for short) mechanism, or any other one may be used. An example of a lock-free queue implemented by this mechanism is not limited in the present invention. Using a lock-free queue instance can save lock overhead on the basis of improving log processing efficiency.
本实施例提供的日志处理方法,通过采用无锁队列实例作为共享内存,从而能够提高日志处理效果,进而能够实现对多进程高并发场景下的日志处理。The log processing method provided in this embodiment uses a lock-free queue instance as a shared memory, thereby improving the log processing effect, and further enabling log processing in a multi-process high-concurrency scenario.
进一步地,在上述任一实施例的基础上,所述将所述客户端的日志信息写入所述共享内存中,包括:Further, on the basis of any of the foregoing embodiments, the writing the log information of the client into the shared memory includes:
将所述客户端中每一线程的日志按照预定的线程存储顺序写入所述共享内存中。The log of each thread in the client is written into the shared memory according to a predetermined thread storage sequence.
在本实施例中,为了提高日志处理效率,可以预先设置一个线程存储顺序,该线程存储顺序可以由各线程的优先级、紧急程度、数据量大小、发送时间等因素中的一项或多项进行确定,此外,还可以由用户根据当前需求进行实时调整,本发明在此不做限制。当同时接收到客户端中的多个线程发送的多个注册请求,并申请共享内存之后,可以按照上述线程存储顺序,将各线程写入的日志信息写入共享内存中。In this embodiment, in order to improve the efficiency of log processing, a thread storage order can be preset. The thread storage order can be determined by one or more of the priority, urgency, data size, and sending time of each thread. In addition, the user can also make real-time adjustments according to current needs, and the present invention is not limited here. After receiving multiple registration requests sent by multiple threads in the client at the same time and applying for shared memory, the log information written by each thread can be written into the shared memory according to the above-mentioned thread storage order.
本实施例提供的日志处理方法,通过将所述客户端中每一线程的日志按照预定的线程存储顺序写入所述共享内存中,能够有效地提高日志处理的效率。The log processing method provided in this embodiment can effectively improve the efficiency of log processing by writing the log of each thread in the client into the shared memory in a predetermined thread storage sequence.
进一步地,在上述任一实施例的基础上,所述将所述客户端的日志信息写入所述共享内存中,包括:Further, on the basis of any of the foregoing embodiments, the writing the log information of the client into the shared memory includes:
将优先级高于预设的第一打印级别的日志信息存入所述共享内存中。Store log information with a priority higher than the preset first printing level in the shared memory.
在本实施例中,由于客户端写入的日志信息数量较多,而不同的日志信息具有不同的优先级。因此,为了优化日志信息质量,减小存储空间,在接收到写入的日志信息之后,可以首先确定日志信息的优先级,并将优先级高于预设的第一打印级别的日志信息写入共享内存中,其中,该第一打印级别可以为用户根据实际需求设置,也可以为系统预设的打印级别,本发明在此不做限制。In this embodiment, since the number of log information written by the client is large, different log information has different priorities. Therefore, in order to optimize the quality of log information and reduce storage space, after receiving the written log information, the priority of the log information can be determined first, and the log information with a priority higher than the preset first printing level can be written into the log information. In the shared memory, the first printing level may be set by the user according to actual needs, or may be a printing level preset by the system, which is not limited in the present invention.
具体地,在上述任一实施例的基础上,所述日志信息的打印级别包括优先级由高到低依次排列的OFF级别、FATAL级别、ERROR级别、WARN级别、INFO级别、DEBUG级别、TRACE级别和ALL级别。Specifically, on the basis of any of the foregoing embodiments, the printing level of the log information includes OFF level, FATAL level, ERROR level, WARN level, INFO level, DEBUG level, and TRACE level in descending order of priority. And ALL level.
本实施例提供的日志处理方法,通过将优先级高于预设的第一打印级别的日志信息存入所述共享内存中,从而能够在优化日志信息质量,减小存储空间的基础上,提高日志处理效率。In the log processing method provided in this embodiment, log information with a priority higher than the preset first print level is stored in the shared memory, so that the quality of log information can be optimized and the storage space can be reduced. Log processing efficiency.
进一步地,在上述任一实施例的基础上,所述将所述客户端的日志信息写入所述共享内存中包括:Further, on the basis of any of the foregoing embodiments, the writing the log information of the client to the shared memory includes:
所述客户端以异步存储的方式将所述客户端的日志信息写入所述共享内存中。The client writes the log information of the client into the shared memory in an asynchronous storage manner.
在本实施例中,由于现有的日志处理方法一般都是在客户端在服务端写入日志信息之后,等待服务端反馈日志信息存储成功,在进行后续的日志写入操作,因此,往往较为耗费时间,造成日志处理效率较低。为了提高日志处理效率,可以以异步存储的方式将客户端的日志信息写入至共享内存中。具体地,在客户端在共享内存中写入日志信息之后,无需等待服务端反馈的存储成功信息,即可进行后续日志的写入操作。In this embodiment, since the existing log processing method generally waits for the server to feedback that the log information is stored successfully after the client writes the log information on the server, and performs subsequent log write operations, it is often more Time-consuming, resulting in low log processing efficiency. In order to improve the efficiency of log processing, the log information of the client can be written to the shared memory in the manner of asynchronous storage. Specifically, after the client writes the log information in the shared memory, the subsequent log writing operation can be performed without waiting for the storage success information fed back by the server.
本实施例提供的日志处理方法,通过以异步存储的方式将所述客户端的日志信息写入所述共享内存中,能够有效地提高日志写入速度,进而能够提高日志处理效率。此外,区别于现有技术中Zlog日志存储技术方案,通过异步存储的方式进行日志信息的存储,能够有效解决现有技术中采用同步Zlog存储容易造成IO卡顿的问题,适用于对实时性要求较高的系统。The log processing method provided in this embodiment can effectively increase the log writing speed by writing the log information of the client into the shared memory in an asynchronous storage manner, thereby improving log processing efficiency. In addition, different from the Zlog log storage technical solution in the prior art, the storage of log information through asynchronous storage can effectively solve the problem of IO stuck in the prior art using synchronous Zlog storage, which is suitable for real-time requirements. Higher system.
进一步地,在上述任一实施例的基础上,所述通过所述客户端预设的调用接口向服务端发送注册请求之前,还包括:Further, on the basis of any of the foregoing embodiments, before sending a registration request to the server through the calling interface preset by the client, the method further includes:
所述客户端根据预设的日志写入配置生成所述注册请求。The client generates the registration request according to a preset log writing configuration.
在本实施例中,在向服务端发送注册请求之前,可以首先确定日志写入配置。该日志写入配置具体可以是用户根据当前需求输入的,也可以为默认的写入配置,本发明在此不做限制。根据该日志写入配置生成注册请求,并将该注册请求发送至服务端,从而服务端可以根据该日志写入配置为客户端申请共享内存。该日志写入配置包括待占用内存大小、存储模式、存储位置、存储的子文件夹划分和存储的子文件夹大小中的至少一种。可选地,不同的优先级可以对应不同的日志写入配置,举例来说,优先级较低的日志写入配置中可以只包括待占用内存大小,而优先级较高的客户端的日志写入配置中还可以包括其他个性化的需求参数。In this embodiment, before sending the registration request to the server, the log writing configuration may be determined first. The log writing configuration may specifically be input by the user according to current requirements, or may be a default writing configuration, which is not limited in the present invention. Generate a registration request according to the log writing configuration, and send the registration request to the server, so that the server can apply for shared memory for the client according to the log writing configuration. The log writing configuration includes at least one of memory size to be occupied, storage mode, storage location, storage subfolder division, and storage subfolder size. Optionally, different priorities can correspond to different log writing configurations. For example, the log writing configuration with a lower priority can only include the memory size to be occupied, while the log writing of the client with a higher priority The configuration can also include other personalized demand parameters.
本实施例提供的日志处理方法,通过根据预设的日志写入配置生成所述注册请求,从而能够在提高日志处理效率的基础上,满足客户端在日志写入过程中的个性化需求。The log processing method provided in this embodiment generates the registration request according to a preset log writing configuration, so that on the basis of improving the log processing efficiency, the client's personalized requirements in the log writing process can be met.
图2为本发明实施例二提供的日志处理方法的流程示意图,在上述任一实施例的基础上,如图2所示,所述当接收到所述服务端反馈的注册成 功信息时,将所述客户端的日志信息写入所述共享内存中之后,还包括:Figure 2 is a schematic flow chart of the log processing method provided by the second embodiment of the present invention. On the basis of any of the above embodiments, as shown in Figure 2, when the registration success information fed back by the server is received, the After the log information of the client is written into the shared memory, it further includes:
步骤201、所述客户端获取所述共享内存的连接数;Step 201: The client obtains the number of connections of the shared memory;
步骤202、所述客户端根据所述连接数确定所述服务端与所述共享内存是否断开连接。Step 202: The client determines whether the server is disconnected from the shared memory according to the number of connections.
在本实施例中,为了实现日志信息的成功写入以及取出存储,客户端和服务端需要同时连接至共享内存。因此,为了保证服务端在日志处理过程中没有掉线,可以获取共享内存的连接数。需要说明的是,当没有服务端掉线的情况下,共享内存的连接总量为当前连接至共享内存的服务端与客户端的总数,因此,可以根据连接数确定服务端当前的状态。确定连接数之后,可以根据该连接数确定服务端是否与共享内存断开连接。In this embodiment, in order to achieve successful writing and storage of log information, the client and the server need to be connected to the shared memory at the same time. Therefore, in order to ensure that the server is not dropped during log processing, the number of shared memory connections can be obtained. It should be noted that when no server is disconnected, the total number of shared memory connections is the total number of servers and clients currently connected to the shared memory. Therefore, the current status of the server can be determined according to the number of connections. After determining the number of connections, you can determine whether the server is disconnected from the shared memory according to the number of connections.
本实施例提供的日志处理方法,通过获取所述共享内存的连接数,根据所述连接数确定所述服务端与所述共享内存是否断开连接。从而能够保证日志写入的有效性,进一步地提高日志处理的效率。In the log processing method provided in this embodiment, by acquiring the number of connections of the shared memory, it is determined whether the server is disconnected from the shared memory according to the number of connections. Thereby, the effectiveness of log writing can be ensured, and the efficiency of log processing can be further improved.
进一步地,在上述任一实施例的基础上,所述根据所述连接数确定所述服务端与所述共享内存是否断开连接,包括:Further, on the basis of any of the foregoing embodiments, the determining whether the server is disconnected from the shared memory according to the number of connections includes:
若所述客户端与所述共享内存保持连接,且所述连接数小于预设的连接总量时,则判定所述服务端与所述共享内存断开连接;其中,所述连接总量为正常日志存储状态下所述共享内存的连接数;If the client remains connected to the shared memory, and the number of connections is less than the preset total number of connections, it is determined that the server is disconnected from the shared memory; wherein, the total number of connections is The number of connections to the shared memory in the normal log storage state;
若所述客户端与所述共享内存保持连接,且所述连接数不小于预设的连接总量,则判定所述服务端与所述共享内存未断开连接。If the client remains connected to the shared memory and the number of connections is not less than the preset total number of connections, it is determined that the server is not disconnected from the shared memory.
在本实施例中,若客户端当前与共享内存连接,且连接数小于预设的连接总量,则可以判定服务端与共享内存断开连接,其中,连接总量为正常日志存储状态下,共享内存的连接数。反之,若客户端当前与共享内存连接,且连接数不小于预设的连接总量,则可以判定服务端当前未断开连接。以实际应用举例来说,若当前有一个客户端和一个服务端连接至共享内存,那么共享内存的连接数即为2。若客户端检测到共享内存当前的连接数为2,则可以确定当前服务端正常运行未掉线,相应地,若客户端检测到共享内存当前的连接数为1,则可以判定服务端已经掉线,此时为了保证日志信息的正常处理,需要对服务端进行提醒。In this embodiment, if the client is currently connected to the shared memory and the number of connections is less than the preset total number of connections, it can be determined that the server is disconnected from the shared memory, where the total number of connections is in the normal log storage state. The number of shared memory connections. Conversely, if the client is currently connected to the shared memory and the number of connections is not less than the preset total number of connections, it can be determined that the server is not currently disconnected. Taking a practical application as an example, if there is currently a client and a server connected to the shared memory, then the number of shared memory connections is 2. If the client detects that the current number of connections in the shared memory is 2, it can be determined that the current server is running normally and not disconnected. Correspondingly, if the client detects that the current number of connections in the shared memory is 1, it can be determined that the server has dropped In order to ensure the normal processing of log information, the server needs to be reminded.
本实施例提供的日志处理方法,通过若所述客户端与所述共享内存保 持连接,且所述连接数小于预设的连接总量时,则判定所述服务端与所述共享内存断开连接;所述连接总量为正常日志存储状态下所述共享内存的连接数,若所述客户端与所述共享内存保持连接,且所述连接数不小于预设的连接总量,则判定所述服务端与所述共享内存未断开连接。从而能够保证日志写入的有效性,进一步地提高日志处理的效率。The log processing method provided in this embodiment determines that the server is disconnected from the shared memory if the client remains connected to the shared memory and the number of connections is less than the preset total number of connections Connection; the total number of connections is the number of connections to the shared memory in the normal log storage state, if the client is connected to the shared memory, and the number of connections is not less than the preset total number of connections, it is determined The server is not disconnected from the shared memory. Thereby, the effectiveness of log writing can be ensured, and the efficiency of log processing can be further improved.
图3为本发明实施例三提供的日志处理方法的流程示意图,在上述任一实施例的基础上,如图3所示,所述方法还包括:FIG. 3 is a schematic flowchart of a log processing method provided in Embodiment 3 of the present invention. Based on any of the above embodiments, as shown in FIG. 3, the method further includes:
步骤301、当判定所述服务端断开连接时,按照预设的频率向所述服务端发送重新连接请求;Step 301: When it is determined that the server is disconnected, send a reconnection request to the server according to a preset frequency;
步骤302、当所述服务端接收到所述客户端发送的重新连接请求,所述服务端根据所述重新连接请求重新与所述共享内存连接。Step 302: When the server receives the reconnection request sent by the client, the server reconnects to the shared memory according to the reconnection request.
在本实施例中,如果通过连接数检测到服务端当前与共享内存断开连接,则表征服务端无法及时从共享内存中获取日志信息并进行存储,导致日志处理效率较低,且导致客户端占用共享内存时间过长。因此,当判定服务端断开连接时,可以按照预设的频率向服务端发送重新连接请求,以使服务端能够根据该重新连接请求重新与共享内存建立通信连接。该预设的频率可以为预设的频率,也可以根据实际需求进行设置,举例来说,若客户端对应的优先级较高,则可以按照较高的频率发送重新连接请求;若该客户端占用的共享内存较大,也可以按照较高的频率发送重新连接请求,本发明在此不做限制。In this embodiment, if it is detected by the number of connections that the server is currently disconnected from the shared memory, it means that the server cannot obtain log information from the shared memory and store it in time, resulting in low log processing efficiency and causing the client to The shared memory is occupied for too long. Therefore, when it is determined that the server is disconnected, a reconnection request can be sent to the server at a preset frequency, so that the server can re-establish a communication connection with the shared memory according to the reconnection request. The preset frequency can be a preset frequency, or it can be set according to actual needs. For example, if the client has a higher priority, it can send a reconnection request at a higher frequency; if the client The occupied shared memory is relatively large, and the reconnection request can also be sent at a higher frequency, which is not limited in the present invention.
本实施例提供的日志处理方法,通过当判定所述服务端断开连接时,按照预设的频率向所述服务端发送重新连接请求,服务端能够根据所述重新连接请求连接所述共享内存,从而能够保证日志写入的有效性,进一步地提高日志处理的效率。In the log processing method provided in this embodiment, by sending a reconnection request to the server at a preset frequency when it is determined that the server is disconnected, the server can connect to the shared memory according to the reconnection request , Which can ensure the effectiveness of log writing, and further improve the efficiency of log processing.
进一步地,在上述任一实施例的基础上,所述注册成功信息包括所述服务端给所述客户端分配的识别码;所述重新连接请求包括所述识别码;所述服务端根据所述重新连接请求重新与所述共享内存连接,包括:Further, on the basis of any of the above embodiments, the registration success information includes the identification code allocated by the server to the client; the reconnection request includes the identification code; The reconnection request to reconnect with the shared memory includes:
所述服务端根据所述重新连接请求中的识别码连接至所述共享内存。The server connects to the shared memory according to the identification code in the reconnection request.
在本实施例中,服务端在成功申请共享内存之后,可以向客户端发送注册成功信息,其中,该注册成功信息中包括服务端给客户端分配的识别 码。当客户端检测到服务端与共享内存断开连接之后,可以向服务端发送包括该识别码的重新连接请求,因此,服务端可以根据该识别码重新连接至共享内存中。In this embodiment, after successfully applying for shared memory, the server can send a registration success message to the client, where the registration success message includes the identification code assigned by the server to the client. After the client detects that the server is disconnected from the shared memory, it can send a reconnection request including the identification code to the server. Therefore, the server can reconnect to the shared memory according to the identification code.
本实施例提供的日志处理方法,通过将接收到的注册成功信息中的识别码放置在重新连接请求中发送给服务端,从而服务端能够根据该识别码重新连接至共享内存中,进而能够在保证日志写入的有效性的基础上,进一步地提高日志处理的效率。In the log processing method provided in this embodiment, the identification code in the received registration success message is placed in the reconnection request and sent to the server, so that the server can reconnect to the shared memory according to the identification code, and then be able to On the basis of ensuring the validity of log writing, the efficiency of log processing is further improved.
进一步地,在上述任一实施例的基础上,所述服务端从所述共享内存中获取所述日志信息,并存储至预设的存储路径,包括:Further, on the basis of any of the foregoing embodiments, the server obtains the log information from the shared memory and stores it in a preset storage path, including:
所述服务端从所述共享内存中获取优先级高于预设的第二打印级别的日志信息,并存储至预设的存储路径。The server obtains log information with a priority higher than a preset second printing level from the shared memory, and stores it in a preset storage path.
在本实施例中,由于客户端写入的日志信息数量较多,而不同的日志信息具有不同的优先级。因此,为了优化日志信息质量,减小存储空间,服务端在从共享内存中获取日志信息时,首先需要确定日志信息的优先级,并将优先级高于预设的第二打印级别的日志信息,存储至预设的存储路径中。其中,该第二打印级别可以为用户根据实际需求设置,也可以为系统预设的打印级别,本发明在此不做限制。In this embodiment, since the number of log information written by the client is large, different log information has different priorities. Therefore, in order to optimize the quality of log information and reduce storage space, when the server obtains the log information from the shared memory, it first needs to determine the priority of the log information and set the priority higher than the preset second printing level of the log information , Save to the preset storage path. Wherein, the second printing level can be set by the user according to actual needs, or can be a printing level preset by the system, which is not limited in the present invention.
具体地,在上述任一实施例的基础上,所述日志信息的打印级别包括优先级由高到低依次排列的OFF级别、FATAL级别、ERROR级别、WARN级别、INFO级别、DEBUG级别、TRACE级别和ALL级别。Specifically, on the basis of any of the foregoing embodiments, the printing level of the log information includes OFF level, FATAL level, ERROR level, WARN level, INFO level, DEBUG level, and TRACE level in descending order of priority. And ALL level.
本实施例提供的日志处理方法,通过从所述共享内存中获取优先级高于预设的第二打印级别的日志信息,并存储至预设的存储路径,从而能够在优化日志信息质量,减小存储空间的基础上,提高日志处理效率。The log processing method provided in this embodiment obtains log information with a priority higher than the preset second printing level from the shared memory and stores it in a preset storage path, thereby optimizing the quality of log information and reducing Improve log processing efficiency based on small storage space.
进一步地,在上述任一实施例的基础上,所述服务端从所述共享内存中获取所述日志信息,并存储至预设的存储路径,包括:Further, on the basis of any of the foregoing embodiments, the server obtains the log information from the shared memory and stores it in a preset storage path, including:
所述服务端以单线程的方式从所述共享内存中获取所述日志信息并存储至预设的存储路径中。The server obtains the log information from the shared memory in a single-threaded manner and stores it in a preset storage path.
在本实施例中,为了提高日志处理效率,在客户端将日志信息写入共享内存中之后,服务端可以以单进程的方式从共享内存中获取日志信息并存储至预设的存储路径中。In this embodiment, in order to improve log processing efficiency, after the client writes the log information into the shared memory, the server can obtain the log information from the shared memory in a single process and store it in a preset storage path.
本实施例提供的日志处理方法,通过以单线程的方式从所述共享内存中获取所述日志信息并存储至预设的存储路径中,能够有效地提高日志写入速度,进而能够提高日志处理效率。The log processing method provided in this embodiment can effectively increase the log writing speed by acquiring the log information from the shared memory in a single-threaded manner and storing it in a preset storage path, thereby improving log processing. effectiveness.
进一步地,在上述任一实施例的基础上,所述注册请求中包括待占用内存量,所述根据所述注册请求为所述客户端申请共享内存,包括:Further, on the basis of any of the foregoing embodiments, the registration request includes the amount of memory to be occupied, and the application for shared memory for the client according to the registration request includes:
确定所述服务端当前内存剩余量;Determine the current remaining amount of memory on the server;
所述服务端根据所述内存剩余量以及所述待占用内存量为所述客户端申请共享内存。The server applies for shared memory for the client according to the remaining amount of memory and the amount of memory to be occupied.
在本实施例中,注册请求中可以包括待占用内存量。具体地,客户端在向服务端发送注册请求时,可以确定待占用内存量,并根据待占用内存量生成注册请求。服务端在接收到注册请求之后,首先可以确定当前的内存剩余量,并根据内存剩余量以及待占用内存量为客户端申请共享内存。In this embodiment, the registration request may include the amount of memory to be occupied. Specifically, when the client sends a registration request to the server, it can determine the amount of memory to be occupied, and generate a registration request according to the amount of memory to be occupied. After receiving the registration request, the server can first determine the current remaining amount of memory, and apply for shared memory for the client according to the remaining amount of memory and the amount of memory to be occupied.
具体地,在上述任一实施例的基础上,所述根据所述内存剩余量以及所述待占用内存量为所述客户端申请共享内存,包括:Specifically, on the basis of any of the foregoing embodiments, the applying for shared memory for the client according to the remaining amount of memory and the amount of memory to be occupied includes:
若所述待占用内存量小于所述内存剩余量,则为所述客户端申请与所述待占用内存量对应的共享内存;If the amount of memory to be occupied is less than the remaining amount of memory, apply for a shared memory corresponding to the amount of memory to be occupied for the client;
若所述待占用内存量不小于所述内存剩余量,则拒绝为所述客户端申请共享内存。If the amount of memory to be occupied is not less than the remaining amount of memory, refuse to apply for shared memory for the client.
在本实施例中,若检测到待占用内存量小于内存剩余量,则可以为该客户端申请与待占用内存量对应的共享内存;反之,若待占用内存量不小于内存剩余量,则表征服务端当前剩余内存不足以为客户端申请共享内存,此时,可以拒绝为客户端申请共享内存。In this embodiment, if it is detected that the amount of memory to be occupied is less than the remaining amount of memory, the client can apply for shared memory corresponding to the amount of memory to be occupied; otherwise, if the amount of memory to be occupied is not less than the remaining amount of memory, it means The current remaining memory of the server is insufficient to apply for shared memory for the client. At this time, it can refuse to apply for shared memory for the client.
本实施例提供的日志处理方法,通过确定所述服务端当前内存剩余量,根据所述内存剩余量以及所述待占用内存量为所述客户端申请共享内存,从而能够快速地为客户端申请共享内存,提高日志处理效率。The log processing method provided in this embodiment determines the current remaining amount of memory on the server, and applies for shared memory for the client based on the remaining amount of memory and the amount of memory to be occupied, so that it can quickly apply for the client Shared memory improves log processing efficiency.
进一步地,在上述任一实施例的基础上,所述注册请求还包括所述客户端的进程标识;Further, on the basis of any of the foregoing embodiments, the registration request further includes the process identifier of the client;
相应地,所述根据所述注册请求为所述客户端申请共享内存,包括:Correspondingly, the applying for shared memory for the client according to the registration request includes:
判断预设的进程黑名单中是否包括所述进程标识;Determine whether the process identifier is included in the preset process blacklist;
若不存在,则为所述客户端申请共享内存;If it does not exist, apply for shared memory for the client;
若存在,则拒绝为所述客户端申请共享内存。If it exists, refuse to apply for shared memory for the client.
在本实施例中,注册请求中还包括进程标识以实际应用举例来说,可能某些客户端存在恶意写入日志的操作等,因此,服务端可以根据历史经验生成黑名单,其中,黑名单中包括进程标识。因此,服务端在接收到包括进程标识的注册请求之后,可以检测黑名单中是否包括该进程标识,若是,则可以拒绝为该客户端申请共享内存,反之,则可以根据该注册请求为客户端申请共享内存。可选地,可能某些客户端生成的日志信息较为重要或者某些客户端的优先级较高等,因此,服务端还可以根据历史经验生成白名单,其中,白名单中包括进程标识。因此,服务端在接收到包括进程标识的注册请求之后,可以检测白名单中是否包括该进程标识,若是,则可以为该进程标识对应的客户端提供更大的共享内存、或者可以为该进程标识对应的客户端存储优先级更低的日志信息。In this embodiment, the registration request also includes the process identification. For example, in actual applications, some clients may have maliciously written to logs. Therefore, the server can generate a blacklist based on historical experience. The blacklist Include the process ID. Therefore, after the server receives the registration request that includes the process ID, it can detect whether the process ID is included in the blacklist. If so, it can refuse to apply for shared memory for the client. Otherwise, it can be the client according to the registration request. Apply for shared memory. Optionally, the log information generated by some clients may be more important or some clients have higher priority. Therefore, the server may also generate a whitelist based on historical experience, where the whitelist includes the process identifier. Therefore, after the server receives the registration request including the process ID, it can detect whether the process ID is included in the whitelist. If so, it can provide the client corresponding to the process ID with larger shared memory, or can provide the process Identifies the corresponding client to store log information with lower priority.
作为一种可以实施的方式,不同的客户端具有不同的优先级,服务端可以根据不同的优先级为客户端提供不同的服务。因此,服务端在接收到包括进程标识的注册请求之后,首先可以确定该进程标识对应的优先级,并根据优先级为客户端提供与优先级对应的服务。As an implementable way, different clients have different priorities, and the server can provide different services to the clients according to different priorities. Therefore, after receiving the registration request including the process identifier, the server can first determine the priority corresponding to the process identifier, and provide the client with a service corresponding to the priority according to the priority.
本实施例提供的日志处理方法,通过判断预设的进程黑名单中是否包括所述进程标识,若不存在,则为所述进程申请共享内存,若存在,则拒绝为所述进程申请共享内存,从而服务端可以有选择地为客户端申请共享内存,进而能够在保证日志处理效率的基础上,保障服务端的安全。The log processing method provided in this embodiment judges whether the process identifier is included in the preset process blacklist, if it does not exist, apply for shared memory for the process, and if it exists, refuse to apply for shared memory for the process , So that the server can selectively apply for shared memory for the client, and then can ensure the security of the server on the basis of ensuring the efficiency of log processing.
进一步地,在上述任一实施例的基础上,所述注册请求是根据预设的日志写入配置生成的;Further, on the basis of any of the foregoing embodiments, the registration request is generated according to a preset log writing configuration;
所述根据所述注册请求为所述客户端申请共享内存,包括:The applying for shared memory for the client according to the registration request includes:
所述服务端根据所述日志写入配置为所述客户端申请共享内存。The server applies for shared memory for the client according to the log writing configuration.
在本实施例中,客户端在在向服务端发送注册请求之前,可以首先确定日志写入配置,并根据该日志写入配置生成注册请求。该日志写入配置具体可以是用户根据当前需求输入的,也可以为默认的写入配置,本发明在此不做限制。服务端可以根据该日志写入配置为客户端申请共享内存。该日志写入配置包括待占用内存大小、存储模式、存储位置、存储的子文件夹划分和存储的子文件夹大小中的至少一种。所述存储的子文件夹用于 根据线程的不同功能划分存储的子文件夹,也可根据日志的不同类型划分存储的子文件夹。可选地,不同的优先级可以对应不同的日志写入配置,举例来说,优先级较低的日志写入配置中可以只包括待占用内存大小,而优先级较高的客户端的日志写入配置中还可以包括其他个性化的需求参数。In this embodiment, before sending a registration request to the server, the client may first determine the log writing configuration, and generate a registration request according to the log writing configuration. The log writing configuration may specifically be input by the user according to current requirements, or may be a default writing configuration, which is not limited in the present invention. The server can apply for shared memory for the client according to the log writing configuration. The log writing configuration includes at least one of memory size to be occupied, storage mode, storage location, storage subfolder division, and storage subfolder size. The stored subfolders are used to divide the stored subfolders according to different functions of threads, and the stored subfolders can also be divided according to different types of logs. Optionally, different priorities can correspond to different log writing configurations. For example, the log writing configuration with a lower priority can only include the memory size to be occupied, while the log writing of the client with a higher priority The configuration can also include other personalized demand parameters.
本实施例提供的日志处理方法,通过根据所述日志写入配置为所述客户端申请共享内存,从而能够在提高日志处理效率的基础上,满足客户端在日志写入过程中的个性化需求。According to the log processing method provided in this embodiment, by applying for shared memory for the client according to the log writing configuration, it is possible to improve the log processing efficiency and meet the client's personalized needs in the log writing process. .
进一步地,在上述任一实施例的基础上,所述根据所述注册请求为所述客户端申请共享内存之后,还包括:Further, on the basis of any of the foregoing embodiments, after the application for shared memory for the client according to the registration request, the method further includes:
所述服务端对所述共享内存进行初始化操作,获得无锁队列实例。The server performs an initialization operation on the shared memory to obtain a lock-free queue instance.
在本实施例中,服务端在根据注册请求为客户端申请共享内存之后,可以对该共享内存进行初始化操作,获得无锁队列实例。,该无锁队列实例可以是由比较与替换(Compare and Set,简称CAS)机制实现的无锁队列实例,也可以采用其他任意一种机制实现的无锁队列实例,本发明在此不做限制。使用无锁队列实例能够在提高日志处理效率的基础上,节省锁开销。In this embodiment, after the server applies for shared memory for the client according to the registration request, the shared memory may be initialized to obtain a lock-free queue instance. The lock-free queue instance can be a lock-free queue instance implemented by a Compare and Replace (Compare and Set, CAS for short) mechanism, or a lock-free queue instance implemented by any other mechanism, and the present invention is not limited here. . Using a lock-free queue instance can save lock overhead on the basis of improving log processing efficiency.
本实施例提供的日志处理方法,通过对所述共享内存进行初始化操作,获得无锁队列实例,从而能够提高日志处理效果,进而能够实现对多进程高并发场景下的日志处理。The log processing method provided in this embodiment obtains a lock-free queue instance by initializing the shared memory, thereby improving the log processing effect, and further enabling log processing in a multi-process high concurrency scenario.
可选地,在上述任一实施例的基础上,所述根据所述注册请求为所述客户端申请共享内存之后,还包括:Optionally, on the basis of any of the foregoing embodiments, after applying for shared memory for the client according to the registration request, the method further includes:
对所述共享内存进行初始化操作,获得有锁队列实例。Perform an initialization operation on the shared memory to obtain a locked queue instance.
进一步地,在上述任一实施例的基础上,所述服务端向所述客户端发送注册成功信息之后,还包括:Further, on the basis of any of the foregoing embodiments, after the server sends registration success information to the client, the method further includes:
所述服务端对所述共享内存中的日志写入状况进行监控,根据监控结果对所述客户端进行管控。The server monitors the log writing status in the shared memory, and manages the client according to the monitoring result.
在本实施例中,客户端在接收到注册成功信息之后,可以在共享内存中写入日志信息。为了进一步地提高日志处理效率,服务端可以对共享内存中的日志写入状态进行监控,根据监控结果对客户端进行管控。举例来 说,可以根据日志写入状态确定客户端是否为恶意客户端,以及客户端当前是否发生故障等。In this embodiment, the client can write log information in the shared memory after receiving the registration success information. In order to further improve the log processing efficiency, the server can monitor the log writing status in the shared memory, and control the client according to the monitoring results. For example, you can determine whether the client is a malicious client based on the log writing status, and whether the client is currently malfunctioning.
本实施例提供的日志处理方法,通过对所述共享内存中的日志写入状况进行监控,根据监控结果对所述客户端进行管控,从而能够在提高日志处理效率的基础上,实现对客户端的有效管控。The log processing method provided in this embodiment monitors the log writing status in the shared memory, and manages and controls the client according to the monitoring result, so that the log processing efficiency can be improved on the basis of improving the log processing efficiency. Effective management and control.
进一步地,在上述任一实施例的基础上,所述服务端对所述共享内存中的日志写入状况进行监控,根据监控结果对所述客户端进行管控,包括:Further, on the basis of any of the above embodiments, the server monitors the log writing status in the shared memory, and manages the client according to the monitoring result, including:
所述服务端判断所述客户端写入日志的速度是否超过预设的速度阈值;The server determines whether the speed at which the client writes the log exceeds a preset speed threshold;
若是,则判定所述客户端出现故障。If yes, it is determined that the client is faulty.
在本实施例中,可以确定客户端当前写入日志的速度,并根据该速度对客户端的状态进行确定。具体地,若检测到客户端写入日志的速度超过预设的速度阈值,则可以判定客户端当前发生故障,反正,则表征当前客户端正常运行。In this embodiment, the current speed at which the client writes the log can be determined, and the status of the client can be determined according to the speed. Specifically, if it is detected that the speed at which the client writes the log exceeds a preset speed threshold, it can be determined that the client is currently malfunctioning, anyway, it means that the current client is operating normally.
可选地,在上述任一实施例的基础上,所述对所述共享内存中的日志写入状况进行监控,根据监控结果对所述客户端进行管控,包括:Optionally, on the basis of any of the foregoing embodiments, the monitoring of the log writing status in the shared memory and the management and control of the client according to the monitoring result includes:
判断所述客户端写入日志的数量是否超过预设的数量阈值;Judging whether the number of logs written by the client exceeds a preset number threshold;
若是,则判定所述客户端出现故障。If yes, it is determined that the client is faulty.
在本实施例中,可以确定客户端当前写入日志的数量,并根据该数量对客户端的状态进行确定。具体地,若检测到客户端写入日志的数量超过预设的数量阈值,则可以判定客户端当前发生故障,反之,则表征当前客户端正常运行。In this embodiment, the number of logs currently written by the client can be determined, and the status of the client can be determined according to the number. Specifically, if it is detected that the number of logs written by the client exceeds a preset number threshold, it can be determined that the client is currently malfunctioning, otherwise, it means that the current client is operating normally.
需要说明的是,上述两个实施例可以单独实施,也可以结合实施。当其结合实施时,可以根据客户端当前写入日志的数量以及速度,确定客户端当前写入日志的数量是否超过预设的数量阈值以及客户端当前写入日志的速度是否超过预设的速度阈值,若是,则判定客户端当前发生故障,反正,则表征当前客户端正常运行。It should be noted that the above two embodiments can be implemented separately or in combination. When it is implemented in combination, it can be determined whether the number of logs currently written by the client exceeds the preset number threshold and whether the speed of the client currently writing logs exceeds the preset speed according to the number and speed of logs currently written by the client The threshold, if yes, it is determined that the client is currently malfunctioning, anyway, it means that the current client is operating normally.
本实施例提供的日志处理方法,通过判断客户端当前写入日志的数量和/或速度是否超过预设的数量和/或速度阈值,确定客户端当前是否发生故障,则可以有效地实现对客户端的监控。The log processing method provided in this embodiment determines whether the client is currently malfunctioning by determining whether the number and/or speed of logs currently written by the client exceed the preset number and/or speed threshold, which can effectively achieve the End monitoring.
进一步地,在上述任一实施例的基础上,所述判定所述客户端出现故障之后,还包括:Further, on the basis of any of the foregoing embodiments, after determining that the client is faulty, the method further includes:
所述服务端根据所述客户端的进程标识确定所述客户端对应的权限信息;Determining, by the server, the authority information corresponding to the client according to the process identifier of the client;
所述服务端根据所述权限信息对所述客户端写入的日志信息进行管控。The server manages and controls the log information written by the client according to the authority information.
在本实施例中,在判定客户端出现故障之后,可以根据客户端的进程标识确定客户端对应的权限信息,根据权限信息对客户端写入的日志信息进行管控。以实际应用举例来说,若当前写入日志的客户端的优先级较高,在检测到该客户端当前写入日志的数量和/或速度超过预设的数量和/或速度阈值时,可以对全部日志信息进行存储;相应地,若当前写入日志的客户端的优先级较低,在检测到该客户端当前写入日志的数量和/或速度超过预设的数量和/或速度阈值时,可以对该客户端写入的日志信息进行部分存储,或者可以拒绝为该客户端继续提供共享内存。In this embodiment, after determining that the client is faulty, the permission information corresponding to the client can be determined according to the process identifier of the client, and the log information written by the client can be controlled according to the permission information. Take a practical application as an example, if the priority of the client currently writing logs is higher, when it is detected that the number and/or speed of the client currently writing logs exceeds the preset number and/or speed threshold, the All log information is stored; accordingly, if the priority of the client currently writing to the log is lower, when it is detected that the number and/or speed of the current written log of the client exceeds the preset number and/or speed threshold, Part of the log information written by the client can be stored, or the client can be refused to continue to provide shared memory.
本实施例提供的日志处理方法,通过根据所述进程标识确定所述客户端对应的权限信息,根据所述权限信息对所述客户端写入的日志信息进行管控,从而能够实现对客户端的有效管控。In the log processing method provided in this embodiment, the authority information corresponding to the client is determined according to the process identifier, and the log information written by the client is controlled according to the authority information, so as to be effective for the client. Control.
进一步地,在上述任一实施例的基础上,所述方法包括:Further, on the basis of any of the foregoing embodiments, the method includes:
所述服务端从所述共享内存中获取所述日志信息,对所述日志信息进行发布处理。The server obtains the log information from the shared memory, and publishes the log information.
在本实施例中,客户端将日志信息写入至共享内存中,服务端可以从共享内存中获取日志信息并进行发布处理。In this embodiment, the client writes the log information into the shared memory, and the server can obtain the log information from the shared memory and perform publishing processing.
图4为本发明实施例四提供的日志处理方法的流程示意图,应用于客户端,如图4所示,所述方法包括:FIG. 4 is a schematic flow chart of a log processing method provided by Embodiment 4 of the present invention, which is applied to a client terminal. As shown in FIG. 4, the method includes:
步骤401、通过预设的调用接口向服务端发送注册请求。Step 401: Send a registration request to the server through a preset calling interface.
本实施例的执行主体为客户端,其中,该客户端可以是一种应用程序、进程,也可以为一种终端设备。为了实现对日志信息的存储,客户端可以通过预设的调用接口向服务端发送注册请求。相应地,服务端接收到该注册请求之后,可以根据该注册请求确定是否为该客户端申请共享内存。举例来说,若服务端当前存储空间不足、处理能力较弱,则可以不根据该注 册请求为客户端申请共享内存;若服务端当前存储空间较多,且处理能力较强,则可以根据该注册请求为客户端申请共享内存。其中,客户端和服务端共享该共享内存,具体地,客户端可以将产生的日志信息写入至该共享内存中,服务端可以从该共享内存中取出日志信息。进一步地,当服务端根据该注册请求确定可以为客户端申请共享内存之后,可以向客户端反馈注册成功信息,以使客户端对当前注册请求的状态进行及时了解。The execution subject of this embodiment is a client, where the client may be an application, a process, or a terminal device. In order to realize the storage of log information, the client can send a registration request to the server through a preset calling interface. Correspondingly, after receiving the registration request, the server can determine whether to apply for shared memory for the client according to the registration request. For example, if the server’s current storage space is insufficient and its processing capacity is weak, it is not necessary to apply for shared memory for the client according to the registration request; if the server’s current storage space is large and its processing capacity is strong, it can be The registration request applies for shared memory for the client. The client and the server share the shared memory. Specifically, the client can write the generated log information into the shared memory, and the server can take out the log information from the shared memory. Further, after the server determines that it can apply for shared memory for the client according to the registration request, it can feed back registration success information to the client, so that the client can understand the status of the current registration request in time.
进一步地,在上述任一实施例的基础上,所述注册请求由所述客户端的其中一个线程发送。Further, on the basis of any of the foregoing embodiments, the registration request is sent by one of the threads of the client.
在本实施例中,该注册请求具体可以是客户端中的其中一个线程发送。由于客户端中具有多个线程,每一线程均可以向服务端发送注册请求,相应地,服务端可以根据各线程发送的注册请求分别为该线程所在的客户端申请共享内存。通过分别为客户端的多个线程申请共享内存,从而能够实现在高并发情况下的日志存储。In this embodiment, the registration request may specifically be sent by one of the threads in the client. Since there are multiple threads in the client, each thread can send a registration request to the server. Accordingly, the server can apply for shared memory for the client where the thread is located according to the registration request sent by each thread. By separately applying for shared memory for multiple threads of the client, it is possible to realize log storage under high concurrency.
步骤402、当接收到所述服务端反馈的注册成功信息时,将所述客户端的日志信息写入所述共享内存中。Step 402: When the registration success information fed back by the server is received, the log information of the client is written into the shared memory.
在本实施方式中,客户端在接收到服务端发送的注册成功信息时,可以将需要进行存储的日志信息写入至该共享内存中。其中,该注册成功信息中可以包括该共享内存的存储地址,该注册成功信息可以由服务端通过预设或新增的调用接口向客户端发送。因此,服务端可以从该共享内存中获取客户端存储的日志信息并存储至预设的存储路径。In this embodiment, when the client receives the registration success information sent by the server, it can write the log information that needs to be stored into the shared memory. Wherein, the registration success information may include the storage address of the shared memory, and the registration success information may be sent by the server to the client through a preset or newly added calling interface. Therefore, the server can obtain the log information stored by the client from the shared memory and store it in a preset storage path.
本实施例提供的日志处理方法,通过预设的调用接口向服务端发送注册请求,以使服务端根据该注册请求为客户端申请共享内存,并在共享内存申请成功后向客户端反馈注册成功信息,其中,客户端与服务端共享该共享内存。当接收到服务端反馈的注册成功信息之后,将客户端产生的日志信息写入该共享内存中,以使服务端可以从该共享内存中获取客户端写入的日志信息,并存储至预设的存储路径中。由于服务端可以根据至少一个客户端的至少一个线程申请共享内存,从而能够适用于高并发场景,进而能够对多个进程的日志进行有效管理。The log processing method provided in this embodiment sends a registration request to the server through a preset calling interface, so that the server applies for shared memory for the client according to the registration request, and reports the successful registration to the client after the shared memory application is successful Information, where the client and server share the shared memory. After receiving the registration success information fed back by the server, the log information generated by the client is written into the shared memory so that the server can obtain the log information written by the client from the shared memory and store it in the preset In the storage path. Since the server can apply for shared memory according to at least one thread of at least one client, it can be applied to high-concurrency scenarios, and can effectively manage the logs of multiple processes.
进一步地,在上述任一实施例的基础上,所述共享内存为无锁队列实例。Further, on the basis of any of the foregoing embodiments, the shared memory is a lock-free queue instance.
在本实施例中,该共享内存具体可以为无锁队列实例,该无锁队列实例可以是由比较与替换(Compare and Set,简称CAS)机制实现的无锁队列实例,也可以采用其他任意一种机制实现的无锁队列实例,本发明在此不做限制。使用无锁队列实例能够在提高日志处理效率的基础上,节省锁开销。In this embodiment, the shared memory may specifically be a lock-free queue instance. The lock-free queue instance may be a lock-free queue instance implemented by a compare and replace (Compare and Set, CAS for short) mechanism, or any other one may be used. An example of a lock-free queue implemented by this mechanism is not limited in the present invention. Using a lock-free queue instance can save lock overhead on the basis of improving log processing efficiency.
本实施例提供的日志处理方法,通过采用无锁队列实例作为共享内存,从而能够提高日志处理效果,进而能够实现对多进程高并发场景下的日志处理。The log processing method provided in this embodiment uses a lock-free queue instance as a shared memory, thereby improving the log processing effect, and further enabling log processing in a multi-process high-concurrency scenario.
可选地,在上述任一实施例的基础上,所述共享内存为有锁队列实例。Optionally, on the basis of any of the foregoing embodiments, the shared memory is a locked queue instance.
进一步地,在上述任一实施例的基础上,所述将所述客户端的日志信息写入所述共享内存中,包括:Further, on the basis of any of the foregoing embodiments, the writing the log information of the client into the shared memory includes:
将所述客户端中每一线程的日志按照预定的线程存储顺序写入所述共享内存中。The log of each thread in the client is written into the shared memory according to a predetermined thread storage sequence.
在本实施例中,为了提高日志处理效率,可以预先设置一个线程存储顺序,该线程存储顺序可以由各线程的优先级、紧急程度、数据量大小、发送时间等因素中的一项或多项进行确定,此外,还可以由用户根据当前需求进行实时调整,本发明在此不做限制。当同时接收到客户端中的多个线程发送的多个注册请求,并申请共享内存之后,可以按照上述线程存储顺序,将各线程写入的日志信息写入共享内存中。In this embodiment, in order to improve the efficiency of log processing, a thread storage order can be preset. The thread storage order can be determined by one or more of the priority, urgency, data size, and sending time of each thread. In addition, the user can also make real-time adjustments according to current needs, and the present invention is not limited here. After receiving multiple registration requests sent by multiple threads in the client at the same time and applying for shared memory, the log information written by each thread can be written into the shared memory according to the above-mentioned thread storage order.
本实施例提供的日志处理方法,通过将所述客户端中每一线程的日志按照预定的线程存储顺序写入所述共享内存中,能够有效地提高日志处理的效率。The log processing method provided in this embodiment can effectively improve the efficiency of log processing by writing the log of each thread in the client into the shared memory in a predetermined thread storage sequence.
进一步地,在上述任一实施例的基础上,所述将所述客户端的日志信息写入所述共享内存中,包括:Further, on the basis of any of the foregoing embodiments, the writing the log information of the client into the shared memory includes:
将优先级高于预设的第一打印级别的日志信息存入所述共享内存中。Store log information with a priority higher than the preset first printing level in the shared memory.
在本实施例中,由于客户端写入的日志信息数量较多,而不同的日志信息具有不同的优先级。因此,为了优化日志信息质量,减小存储空间,在接收到写入的日志信息之后,可以首先确定日志信息的优先级,并将优先级高于预设的第一打印级别的日志信息写入共享内存中,其中,该第一打印级别可以为用户根据实际需求设置,也可以为系统预设的打印级别, 本发明在此不做限制。In this embodiment, since the number of log information written by the client is large, different log information has different priorities. Therefore, in order to optimize the quality of log information and reduce storage space, after receiving the written log information, the priority of the log information can be determined first, and the log information with a priority higher than the preset first printing level can be written into the log information. In the shared memory, the first printing level may be set by the user according to actual needs, or may be a printing level preset by the system, which is not limited in the present invention.
具体地,在上述任一实施例的基础上,所述日志信息的打印级别包括优先级由高到低依次排列的OFF级别、FATAL级别、ERROR级别、WARN级别、INFO级别、DEBUG级别、TRACE级别和ALL级别。Specifically, on the basis of any of the foregoing embodiments, the printing level of the log information includes OFF level, FATAL level, ERROR level, WARN level, INFO level, DEBUG level, and TRACE level in descending order of priority. And ALL level.
本实施例提供的日志处理方法,通过将优先级高于预设的第一打印级别的日志信息存入所述共享内存中,从而能够在优化日志信息质量,减小存储空间的基础上,提高日志处理效率。In the log processing method provided in this embodiment, log information with a priority higher than the preset first print level is stored in the shared memory, so that the quality of log information can be optimized and the storage space can be reduced. Log processing efficiency.
进一步地,在上述任一实施例的基础上,所述将所述客户端的日志信息写入所述共享内存中包括:Further, on the basis of any of the foregoing embodiments, the writing the log information of the client to the shared memory includes:
以异步存储的方式将所述客户端的日志信息写入所述共享内存中。The log information of the client is written into the shared memory in an asynchronous storage manner.
在本实施例中,由于现有的日志处理方法一般都是在客户端在服务端写入日志信息之后,等待服务端反馈日志信息存储成功,在进行后续的日志写入操作,因此,往往较为耗费时间,造成日志处理效率较低。为了提高日志处理效率,可以以异步存储的方式将客户端的日志信息写入至共享内存中。具体地,在客户端在共享内存中写入日志信息之后,无需等待服务端反馈的存储成功信息,即可进行后续日志的写入操作。In this embodiment, since the existing log processing method generally waits for the server to feedback that the log information is stored successfully after the client writes the log information on the server, and performs subsequent log write operations, it is often more Time-consuming, resulting in low log processing efficiency. In order to improve the efficiency of log processing, the log information of the client can be written to the shared memory in the manner of asynchronous storage. Specifically, after the client writes the log information in the shared memory, the subsequent log writing operation can be performed without waiting for the storage success information fed back by the server.
本实施例提供的日志处理方法,通过以异步存储的方式将所述客户端的日志信息写入所述共享内存中,能够有效地提高日志写入速度,进而能够提高日志处理效率。此外,区别于现有技术中Zlog日志存储技术方案,通过异步存储的方式进行日志信息的存储,能够有效解决现有技术中采用同步Zlog存储容易造成IO卡顿的问题,适用于对实时性要求较高的系统。The log processing method provided in this embodiment can effectively increase the log writing speed by writing the log information of the client into the shared memory in an asynchronous storage manner, thereby improving log processing efficiency. In addition, different from the Zlog log storage technical solution in the prior art, the storage of log information through asynchronous storage can effectively solve the problem of IO stuck in the prior art using synchronous Zlog storage, which is suitable for real-time requirements. Higher system.
进一步地,在上述任一实施例的基础上,所述注册信息中还包括发送所述注册请求的进程的进程标识,以使所述服务端能够根据所述进程标识确定是否为所述进程提供内存信息。Further, on the basis of any of the foregoing embodiments, the registration information also includes the process identifier of the process that sent the registration request, so that the server can determine whether to provide the process for the process according to the process identifier. Memory information.
在本实施例中,注册信息中还包括发送该注册请求的进程的进程标识。以实际应用举例来说,可能某些客户端存在恶意写入日志的操作等,因此,服务端可以根据历史经验生成黑名单,其中,黑名单中包括进程标识。因此,服务端在接收到包括进程标识的注册请求之后,可以检测黑名单中是否包括该进程标识,若是,则可以拒绝为该客户端申请共享内存,反之,则可以根据该注册请求为客户端申请共享内存。可选地,可能某些客户端 生成的日志信息较为重要或者某些客户端的优先级较高等,因此,服务端还可以根据历史经验生成白名单,其中,白名单中包括进程标识。因此,服务端在接收到包括进程标识的注册请求之后,可以检测白名单中是否包括该进程标识,若是,则可以为该进程标识对应的客户端提供更大的共享内存、或者可以为该进程标识对应的客户端存储优先级更低的日志信息。In this embodiment, the registration information also includes the process identifier of the process that sent the registration request. Taking a practical application as an example, some clients may have malicious write operations to logs. Therefore, the server can generate a blacklist based on historical experience, where the blacklist includes the process identifier. Therefore, after the server receives the registration request that includes the process ID, it can detect whether the process ID is included in the blacklist. If so, it can refuse to apply for shared memory for the client. Otherwise, it can be the client according to the registration request. Apply for shared memory. Optionally, the log information generated by some clients may be more important or some clients have a higher priority. Therefore, the server may also generate a whitelist based on historical experience, where the whitelist includes the process identifier. Therefore, after the server receives the registration request including the process ID, it can detect whether the process ID is included in the whitelist. If so, it can provide the client corresponding to the process ID with larger shared memory, or can provide the process Identifies the corresponding client to store log information with lower priority.
作为一种可以实施的方式,不同的客户端具有不同的优先级,服务端可以根据不同的优先级为客户端提供不同的服务。因此,服务端在接收到包括进程标识的注册请求之后,首先可以确定该进程标识对应的优先级,并根据优先级为客户端提供与优先级对应的服务。As an implementable way, different clients have different priorities, and the server can provide different services to the clients according to different priorities. Therefore, after receiving the registration request including the process identifier, the server can first determine the priority corresponding to the process identifier, and provide the client with a service corresponding to the priority according to the priority.
本实施例提供的日志处理方法,通过注册信息中还包括发送所述注册请求的进程的进程标识,从而服务端可以有选择地为客户端申请共享内存,进而能够在保证日志处理效率的基础上,保障服务端的安全。In the log processing method provided in this embodiment, the registration information also includes the process identification of the process that sent the registration request, so that the server can selectively apply for shared memory for the client, thereby ensuring log processing efficiency. , To ensure the security of the server.
进一步地,在上述任一实施例的基础上,所述通过所述客户端预设的调用接口向服务端发送注册请求之前,还包括:Further, on the basis of any of the foregoing embodiments, before sending a registration request to the server through the calling interface preset by the client, the method further includes:
根据预设的日志写入配置生成所述注册请求。The registration request is generated according to the preset log writing configuration.
在本实施例中,在向服务端发送注册请求之前,可以首先确定日志写入配置。该日志写入配置具体可以是用户根据当前需求输入的,也可以为默认的写入配置,本发明在此不做限制。根据该日志写入配置生成注册请求,并将该注册请求发送至服务端,从而服务端可以根据该日志写入配置为客户端申请共享内存。该日志写入配置包括待占用内存大小、存储模式、存储位置、存储的子文件夹划分和存储的子文件夹大小中的至少一种。可选地,不同的优先级可以对应不同的日志写入配置,举例来说,优先级较低的日志写入配置中可以只包括待占用内存大小,而优先级较高的客户端的日志写入配置中还可以包括其他个性化的需求参数。In this embodiment, before sending the registration request to the server, the log writing configuration may be determined first. The log writing configuration may specifically be input by the user according to current requirements, or may be a default writing configuration, which is not limited in the present invention. Generate a registration request according to the log writing configuration, and send the registration request to the server, so that the server can apply for shared memory for the client according to the log writing configuration. The log writing configuration includes at least one of memory size to be occupied, storage mode, storage location, storage subfolder division, and storage subfolder size. Optionally, different priorities can correspond to different log writing configurations. For example, the log writing configuration with a lower priority can only include the memory size to be occupied, while the log writing of the client with a higher priority The configuration can also include other personalized demand parameters.
本实施例提供的日志处理方法,通过根据预设的日志写入配置生成所述注册请求,从而能够在提高日志处理效率的基础上,满足客户端在日志写入过程中的个性化需求。The log processing method provided in this embodiment generates the registration request according to a preset log writing configuration, so that on the basis of improving the log processing efficiency, the client's personalized requirements in the log writing process can be met.
图5为本发明实施例五提供的日志处理方法的流程示意图,在上述任一实施例的基础上,如图5所示,所述当接收到所述服务端反馈的注册成功信息时,将所述客户端的日志信息写入所述共享内存中之后,还包括:FIG. 5 is a schematic flowchart of a log processing method provided by Embodiment 5 of the present invention. On the basis of any of the above embodiments, as shown in FIG. 5, when the registration success information fed back by the server is received, the After the log information of the client is written into the shared memory, it further includes:
步骤501、获取所述共享内存的连接数;Step 501: Obtain the number of connections of the shared memory.
步骤502、根据所述连接数确定所述服务端与所述共享内存是否断开连接。Step 502: Determine whether the server is disconnected from the shared memory according to the number of connections.
在本实施例中,为了实现日志信息的成功写入以及取出存储,客户端和服务端需要同时连接至共享内存。因此,为了保证服务端在日志处理过程中没有掉线,可以获取共享内存的连接数。需要说明的是,当没有服务端掉线的情况下,共享内存的连接总量为当前连接至共享内存的服务端与客户端的总数,因此,可以根据连接数确定服务端当前的状态。确定连接数之后,可以根据该连接数确定服务端是否与共享内存断开连接。In this embodiment, in order to achieve successful writing and storage of log information, the client and the server need to be connected to the shared memory at the same time. Therefore, in order to ensure that the server is not dropped during log processing, the number of shared memory connections can be obtained. It should be noted that when no server is disconnected, the total number of shared memory connections is the total number of servers and clients currently connected to the shared memory. Therefore, the current status of the server can be determined according to the number of connections. After determining the number of connections, you can determine whether the server is disconnected from the shared memory according to the number of connections.
本实施例提供的日志处理方法,通过获取所述共享内存的连接数,根据所述连接数确定所述服务端与所述共享内存是否断开连接。从而能够保证日志写入的有效性,进一步地提高日志处理的效率。In the log processing method provided in this embodiment, by acquiring the number of connections of the shared memory, it is determined whether the server is disconnected from the shared memory according to the number of connections. Thereby, the effectiveness of log writing can be ensured, and the efficiency of log processing can be further improved.
进一步地,在上述任一实施例的基础上,所述根据所述连接数确定所述服务端与所述共享内存是否断开连接,包括:Further, on the basis of any of the foregoing embodiments, the determining whether the server is disconnected from the shared memory according to the number of connections includes:
若所述客户端与所述共享内存保持连接,且所述连接数小于预设的连接总量时,则判定所述服务端与所述共享内存断开连接;所述连接总量为正常日志存储状态下所述共享内存的连接数;If the client remains connected to the shared memory, and the number of connections is less than the preset total number of connections, it is determined that the server is disconnected from the shared memory; the total number of connections is a normal log The number of connections of the shared memory in the storage state;
若所述客户端与所述共享内存保持连接,且所述连接数不小于预设的连接总量,则判定所述服务端与所述共享内存未断开连接。If the client remains connected to the shared memory and the number of connections is not less than the preset total number of connections, it is determined that the server is not disconnected from the shared memory.
在本实施例中,若客户端当前与共享内存连接,且连接数小于预设的连接总量,则可以判定服务端与共享内存断开连接,其中,连接总量为正常日志存储状态下,共享内存的连接数。反之,若客户端当前与共享内存连接,且连接数不小于预设的连接总量,则可以判定服务端当前未断开连接。以实际应用举例来说,若当前有一个客户端和一个服务端连接至共享内存,那么共享内存的连接数即为2。若客户端检测到共享内存当前的连接数为2,则可以确定当前服务端正常运行未掉线,相应地,若客户端检测到共享内存当前的连接数为1,则可以判定服务端已经掉线,此时为了保证日志信息的正常处理,需要对服务端进行提醒。In this embodiment, if the client is currently connected to the shared memory and the number of connections is less than the preset total number of connections, it can be determined that the server is disconnected from the shared memory, where the total number of connections is in the normal log storage state. The number of shared memory connections. Conversely, if the client is currently connected to the shared memory and the number of connections is not less than the preset total number of connections, it can be determined that the server is not currently disconnected. Taking a practical application as an example, if there is currently a client and a server connected to the shared memory, then the number of shared memory connections is 2. If the client detects that the current number of connections in the shared memory is 2, it can be determined that the current server is running normally and not disconnected. Correspondingly, if the client detects that the current number of connections in the shared memory is 1, it can be determined that the server has dropped In order to ensure the normal processing of log information, the server needs to be reminded.
本实施例提供的日志处理方法,通过若所述客户端与所述共享内存保持连接,且所述连接数小于预设的连接总量时,则判定所述服务端与所述 共享内存断开连接;所述连接总量为正常日志存储状态下所述共享内存的连接数,若所述客户端与所述共享内存保持连接,且所述连接数不小于预设的连接总量,则判定所述服务端与所述共享内存未断开连接。从而能够保证日志写入的有效性,进一步地提高日志处理的效率。The log processing method provided in this embodiment determines that the server is disconnected from the shared memory if the client remains connected to the shared memory and the number of connections is less than the preset total number of connections Connection; the total number of connections is the number of connections to the shared memory in the normal log storage state, if the client is connected to the shared memory, and the number of connections is not less than the preset total number of connections, it is determined The server is not disconnected from the shared memory. Thereby, the effectiveness of log writing can be ensured, and the efficiency of log processing can be further improved.
进一步地,在上述任一实施例的基础上,所述方法还包括:Further, on the basis of any of the foregoing embodiments, the method further includes:
当判定所述服务端断开连接时,按照预设的频率向所述服务端发送重新连接请求。When it is determined that the server is disconnected, a reconnection request is sent to the server at a preset frequency.
在本实施例中,如果通过连接数检测到服务端当前与共享内存断开连接,则表征服务端无法及时从共享内存中获取日志信息并进行存储,导致日志处理效率较低,且导致客户端占用共享内存时间过长。因此,当判定服务端断开连接时,可以按照预设的频率向服务端发送重新连接请求,以使服务端能够根据该重新连接请求重新与共享内存建立通信连接。该预设的频率可以为预设的频率,也可以根据实际需求进行设置,举例来说,若客户端对应的优先级较高,则可以按照较高的频率发送重新连接请求;若该客户端占用的共享内存较大,也可以按照较高的频率发送重新连接请求,本发明在此不做限制。In this embodiment, if it is detected by the number of connections that the server is currently disconnected from the shared memory, it means that the server cannot obtain log information from the shared memory and store it in time, resulting in low log processing efficiency and causing the client to The shared memory is occupied for too long. Therefore, when it is determined that the server is disconnected, a reconnection request can be sent to the server at a preset frequency, so that the server can re-establish a communication connection with the shared memory according to the reconnection request. The preset frequency can be a preset frequency, or it can be set according to actual needs. For example, if the client has a higher priority, it can send a reconnection request at a higher frequency; if the client The occupied shared memory is relatively large, and the reconnection request can also be sent at a higher frequency, which is not limited in the present invention.
本实施例提供的日志处理方法,通过当判定所述服务端断开连接时,按照预设的频率向所述服务端发送重新连接请求,以使得所述服务端能够根据所述重新连接请求连接所述共享内存,从而能够保证日志写入的有效性,进一步地提高日志处理的效率。In the log processing method provided in this embodiment, when it is determined that the server is disconnected, a reconnection request is sent to the server at a preset frequency, so that the server can connect according to the reconnection request. The shared memory can ensure the effectiveness of log writing, and further improve the efficiency of log processing.
进一步地,在上述任一实施例的基础上,所述注册成功信息包括所述服务端给所述客户端分配的识别码;所述重新连接请求中包括所述识别码;所述识别码用于使得所述服务端能够根据所述重新连接请求中的识别码连接至所述共享内存。Further, on the basis of any of the foregoing embodiments, the registration success information includes an identification code allocated by the server to the client; the reconnection request includes the identification code; the identification code is used Therefore, the server can connect to the shared memory according to the identification code in the reconnection request.
在本实施例中,服务端在成功申请共享内存之后,可以向客户端发送注册成功信息,其中,该注册成功信息中包括服务端给客户端分配的识别码。当客户端检测到服务端与共享内存断开连接之后,可以向服务端发送包括该识别码的重新连接请求,因此,服务端可以根据该识别码重新连接至共享内存中。In this embodiment, after successfully applying for shared memory, the server may send registration success information to the client, where the registration success information includes the identification code assigned by the server to the client. After the client detects that the server is disconnected from the shared memory, it can send a reconnection request including the identification code to the server. Therefore, the server can reconnect to the shared memory according to the identification code.
本实施例提供的日志处理方法,通过将接收到的注册成功信息中的识 别码放置在重新连接请求中发送给服务端,从而能够使服务端根据该识别码重新连接至共享内存中,进而能够在保证日志写入的有效性的基础上,进一步地提高日志处理的效率。In the log processing method provided in this embodiment, the identification code in the received registration success message is placed in the reconnection request and sent to the server, so that the server can reconnect to the shared memory according to the identification code, thereby enabling On the basis of ensuring the validity of log writing, the efficiency of log processing is further improved.
图6为本发明实施例六提供的日志处理方法的流程示意图,应用于服务端,如图6所示,所述方法包括:FIG. 6 is a schematic flowchart of a log processing method provided by Embodiment 6 of the present invention, which is applied to the server side. As shown in FIG. 6, the method includes:
步骤601、接收客户端发送的注册请求;Step 601: Receive a registration request sent by the client.
步骤602、根据所述注册请求为所述客户端申请共享内存;Step 602: Apply for shared memory for the client according to the registration request;
步骤603、当所述共享内存申请成功后,向所述客户端发送注册成功信息;Step 603: After the shared memory application is successful, send registration success information to the client;
步骤604、从所述共享内存中获取所述日志信息,并存储至预设的存储路径。Step 604: Obtain the log information from the shared memory and store it in a preset storage path.
本实施例的执行主体为服务端,其中,该服务端可以是一种应用程序、进程,也可以为一种终端设备,为了实现对日志信息的存储,客户端可以通过预设的调用接口向服务端发送注册请求。相应地,服务端可以接收客户端发送的注册请求,并根据该注册请求为客户端申请共享内存。举例来说,若服务端当前存储空间不足、处理能力较弱,则可以不根据该注册请求为客户端申请共享内存;若服务端当前存储空间较多,且处理能力较强,则可以根据该注册请求为客户端申请共享内存。为客户端成功申请共享内存之后,可以向客户端发送注册成功信息。客户端在接收到服务端发送的注册成功信息时,可以将需要进行存储的日志信息写入至该共享内存中,其中,该注册成功信息中可以包括该共享内存的存储地址。由于客户端与服务端同时连接至共享内存,因此,在客户端在共享内存中写入日志信息之后,服务端可以从共享内存中获取日志信息,并存储至预设的存储路径中。The execution body of this embodiment is the server, where the server can be an application, a process, or a terminal device. In order to store log information, the client can use a preset calling interface to The server sends a registration request. Correspondingly, the server can receive the registration request sent by the client, and apply for shared memory for the client according to the registration request. For example, if the server’s current storage space is insufficient and its processing capacity is weak, it is not necessary to apply for shared memory for the client according to the registration request; if the server’s current storage space is large and its processing capacity is strong, it can be The registration request applies for shared memory for the client. After successfully applying for shared memory for the client, the registration success message can be sent to the client. When receiving the registration success information sent by the server, the client can write log information that needs to be stored into the shared memory, where the registration success information can include the storage address of the shared memory. Since the client and the server are connected to the shared memory at the same time, after the client writes the log information in the shared memory, the server can obtain the log information from the shared memory and store it in a preset storage path.
进一步地,所述注册请求由所述客户端的其中一个线程发送。Further, the registration request is sent by one of the threads of the client.
在本实施例中,该注册请求具体可以是客户端中的其中一个线程发送。由于客户端中具有多个线程,每一线程均可以向服务端发送注册请求,相应地,服务端可以根据各线程发送的注册请求为该线程对应的客户端申请共享内存。通过分别为客户端的多个线程申请共享内存,从而能够实现在高并发情况下的日志存储。In this embodiment, the registration request may specifically be sent by one of the threads in the client. Since there are multiple threads in the client, each thread can send a registration request to the server. Accordingly, the server can apply for shared memory for the client corresponding to the thread according to the registration request sent by each thread. By separately applying for shared memory for multiple threads of the client, it is possible to realize log storage under high concurrency.
进一步地,当客户端完成全部的日志信息的写入时,客户端与共享内存断开连接,服务端可以对该客户端当前使用的共享内存进行回收,以便后续未其他客户端申请。Further, when the client finishes writing all the log information, the client disconnects from the shared memory, and the server can reclaim the shared memory currently used by the client so that no other clients can apply for it later.
本实施例提供的日志处理方法,通过接收客户端发送的注册请求,根据所述注册请求为所述客户端申请共享内存,当所述共享内存申请成功后,向所述客户端发送注册成功信息,以使所述客户端根据所述注册成功信息在所述共享内存中写入日志信息,从所述共享内存中获取所述日志信息,并存储至预设的存储路径。由于服务端可以根据至少一个客户端的至少一个线程申请共享内存,客户端中所有进程产生的日志信息都能够存储在该共享内存中,从而能够适用于一个应用程序里多个线程高并发的情况,进而能够对多个进程的日志进行有效管理。The log processing method provided in this embodiment receives a registration request sent by a client, applies for shared memory for the client according to the registration request, and sends a registration success message to the client after the shared memory application is successful , So that the client writes log information in the shared memory according to the registration success information, acquires the log information from the shared memory, and stores it in a preset storage path. Since the server can apply for shared memory according to at least one thread of at least one client, the log information generated by all processes in the client can be stored in the shared memory, which can be applied to the high concurrency of multiple threads in an application. In turn, the logs of multiple processes can be effectively managed.
进一步地,在上述任一实施例的基础上,所述从所述共享内存中获取所述日志信息,并存储至预设的存储路径,包括:Further, on the basis of any of the foregoing embodiments, the acquiring the log information from the shared memory and storing it in a preset storage path includes:
从所述共享内存中获取优先级高于预设的第二打印级别的日志信息,并存储至预设的存储路径。Obtain log information with a priority higher than the preset second printing level from the shared memory, and store it in a preset storage path.
在本实施例中,由于客户端写入的日志信息数量较多,而不同的日志信息具有不同的优先级。因此,为了优化日志信息质量,减小存储空间,服务端在从共享内存中获取日志信息时,首先需要确定日志信息的优先级,并将优先级高于预设的第二打印级别的日志信息,存储至预设的存储路径中。其中,该第二打印级别可以为用户根据实际需求设置,也可以为系统预设的打印级别,本发明在此不做限制。In this embodiment, since the number of log information written by the client is large, different log information has different priorities. Therefore, in order to optimize the quality of log information and reduce storage space, when the server obtains the log information from the shared memory, it first needs to determine the priority of the log information and set the priority higher than the preset second printing level of the log information , Save to the preset storage path. Wherein, the second printing level can be set by the user according to actual needs, or can be a printing level preset by the system, which is not limited in the present invention.
具体地,在上述任一实施例的基础上,所述日志信息的打印级别包括优先级由高到低依次排列的OFF级别、FATAL级别、ERROR级别、WARN级别、INFO级别、DEBUG级别、TRACE级别和ALL级别。Specifically, on the basis of any of the foregoing embodiments, the printing level of the log information includes OFF level, FATAL level, ERROR level, WARN level, INFO level, DEBUG level, and TRACE level in descending order of priority. And ALL level.
本实施例提供的日志处理方法,通过从所述共享内存中获取优先级高于预设的第二打印级别的日志信息,并存储至预设的存储路径,从而能够在优化日志信息质量,减小存储空间的基础上,提高日志处理效率。The log processing method provided in this embodiment obtains log information with a priority higher than the preset second printing level from the shared memory and stores it in a preset storage path, thereby optimizing the quality of log information and reducing Improve log processing efficiency based on small storage space.
进一步地,在上述任一实施例的基础上,所述服务端从所述共享内存中获取所述日志信息并存储至预设的存储路径中,包括:Further, on the basis of any of the foregoing embodiments, the server acquiring the log information from the shared memory and storing it in a preset storage path includes:
所述服务端以单线程的方式从所述共享内存中获取所述日志信息并 存储至预设的存储路径中。The server obtains the log information from the shared memory in a single-threaded manner and stores it in a preset storage path.
在本实施例中,为了提高日志处理效率,在客户端将日志信息写入共享内存中之后,服务端可以以单进程的方式从共享内存中获取日志信息并存储至预设的存储路径中。In this embodiment, in order to improve log processing efficiency, after the client writes the log information into the shared memory, the server can obtain the log information from the shared memory in a single process and store it in a preset storage path.
本实施例提供的日志处理方法,通过以单线程的方式从所述共享内存中获取所述日志信息并存储至预设的存储路径中,能够有效地提高日志写入速度,进而能够提高日志处理效率。The log processing method provided in this embodiment can effectively increase the log writing speed by acquiring the log information from the shared memory in a single-threaded manner and storing it in a preset storage path, thereby improving log processing. effectiveness.
图7为本发明实施例七提供的日志处理方法的流程示意图,在上述任一实施例的基础上,如图7所示,所述注册请求中包括待占用内存量,所述根据所述注册请求为所述客户端申请共享内存,包括:FIG. 7 is a schematic flow chart of a log processing method provided by Embodiment 7 of the present invention. Based on any of the foregoing embodiments, as shown in FIG. 7, the registration request includes the amount of memory to be occupied, and the The request to apply for shared memory for the client includes:
步骤701、确定所述服务端当前内存剩余量;Step 701: Determine the current remaining amount of memory on the server;
步骤702、根据所述内存剩余量以及所述待占用内存量为所述客户端申请共享内存。Step 702: Apply for shared memory for the client according to the remaining amount of memory and the amount of memory to be occupied.
在本实施例中,注册请求中可以包括待占用内存量。具体地,客户端在向服务端发送注册请求时,可以确定待占用内存量,并根据待占用内存量生成注册请求。服务端在接收到注册请求之后,首先可以确定当前的内存剩余量,并根据内存剩余量以及待占用内存量为客户端申请共享内存。In this embodiment, the registration request may include the amount of memory to be occupied. Specifically, when the client sends a registration request to the server, it can determine the amount of memory to be occupied, and generate a registration request according to the amount of memory to be occupied. After receiving the registration request, the server can first determine the current remaining amount of memory, and apply for shared memory for the client according to the remaining amount of memory and the amount of memory to be occupied.
具体地,在上述任一实施例的基础上,所述根据所述内存剩余量以及所述待占用内存量为所述客户端申请共享内存,包括:Specifically, on the basis of any of the foregoing embodiments, the applying for shared memory for the client according to the remaining amount of memory and the amount of memory to be occupied includes:
若所述待占用内存量小于所述内存剩余量,则为所述客户端申请与所述待占用内存量对应的共享内存;If the amount of memory to be occupied is less than the remaining amount of memory, apply for a shared memory corresponding to the amount of memory to be occupied for the client;
若所述待占用内存量不小于所述内存剩余量,则拒绝为所述客户端申请共享内存。If the amount of memory to be occupied is not less than the remaining amount of memory, refuse to apply for shared memory for the client.
在本实施例中,若检测到待占用内存量小于内存剩余量,则可以为该客户端申请与待占用内存量对应的共享内存;反之,若待占用内存量不小于内存剩余量,则表征服务端当前剩余内存不足以为客户端申请共享内存,此时,可以拒绝为客户端申请共享内存。In this embodiment, if it is detected that the amount of memory to be occupied is less than the remaining amount of memory, the client can apply for shared memory corresponding to the amount of memory to be occupied; otherwise, if the amount of memory to be occupied is not less than the remaining amount of memory, the The current remaining memory of the server is insufficient to apply for shared memory for the client. At this time, it can refuse to apply for shared memory for the client.
本实施例提供的日志处理方法,通过确定所述服务端当前内存剩余量,根据所述内存剩余量以及所述待占用内存量为所述客户端申请共享内存,从而能够快速地为客户端申请共享内存,提高日志处理效率。The log processing method provided in this embodiment determines the current remaining amount of memory on the server, and applies for shared memory for the client based on the remaining amount of memory and the amount of memory to be occupied, so that it can quickly apply for the client Shared memory improves log processing efficiency.
图8为本发明实施例八提供的日志处理方法的流程示意图,在上述任一实施例的基础上,如图8所示,所述注册请求中还包括所述进程标识;相应地,所述根据所述注册请求为所述客户端申请共享内存,包括:FIG. 8 is a schematic flowchart of a log processing method provided by Embodiment 8 of the present invention. On the basis of any of the above embodiments, as shown in FIG. 8, the registration request also includes the process identifier; accordingly, the Applying for shared memory for the client according to the registration request includes:
步骤801、判断预设的进程黑名单中是否包括所述进程标识;Step 801: Determine whether the process identifier is included in the preset process blacklist;
步骤802、若不存在,则为所述进程申请共享内存;Step 802: If it does not exist, apply for shared memory for the process;
步骤803、若存在,则拒绝为所述进程申请共享内存。Step 803: If it exists, refuse to apply for shared memory for the process.
在本实施例中,注册请求中还包括进程标识以实际应用举例来说,可能某些客户端存在恶意写入日志的操作等,因此,服务端可以根据历史经验生成黑名单,其中,黑名单中包括进程标识。因此,服务端在接收到包括进程标识的注册请求之后,可以检测黑名单中是否包括该进程标识,若是,则可以拒绝为该客户端申请共享内存,反之,则可以根据该注册请求为客户端申请共享内存。可选地,可能某些客户端生成的日志信息较为重要或者某些客户端的优先级较高等,因此,服务端还可以根据历史经验生成白名单,其中,白名单中包括进程标识。因此,服务端在接收到包括进程标识的注册请求之后,可以检测白名单中是否包括该进程标识,若是,则可以为该进程标识对应的客户端提供更大的共享内存、或者可以为该进程标识对应的客户端存储优先级更低的日志信息。In this embodiment, the registration request also includes the process identification. For example, in actual applications, some clients may have maliciously written to logs. Therefore, the server can generate a blacklist based on historical experience. The blacklist Include the process ID. Therefore, after the server receives the registration request that includes the process ID, it can detect whether the process ID is included in the blacklist. If so, it can refuse to apply for shared memory for the client. Otherwise, it can be the client according to the registration request. Apply for shared memory. Optionally, the log information generated by some clients may be more important or some clients have higher priority. Therefore, the server may also generate a whitelist based on historical experience, where the whitelist includes the process identifier. Therefore, after the server receives the registration request including the process ID, it can detect whether the process ID is included in the whitelist. If so, it can provide the client corresponding to the process ID with larger shared memory, or can provide the process Identifies the corresponding client to store log information with lower priority.
作为一种可以实施的方式,不同的客户端具有不同的优先级,服务端可以根据不同的优先级为客户端提供不同的服务。因此,服务端在接收到包括进程标识的注册请求之后,首先可以确定该进程标识对应的优先级,并根据优先级为客户端提供与优先级对应的服务。As an implementable way, different clients have different priorities, and the server can provide different services to the clients according to different priorities. Therefore, after receiving the registration request including the process identifier, the server can first determine the priority corresponding to the process identifier, and provide the client with a service corresponding to the priority according to the priority.
本实施例提供的日志处理方法,通过判断预设的进程黑名单中是否包括所述进程标识,若不存在,则为所述进程申请共享内存,若存在,则拒绝为所述进程申请共享内存,从而服务端可以有选择地为客户端申请共享内存,进而能够在保证日志处理效率的基础上,保障服务端的安全。The log processing method provided in this embodiment judges whether the process identifier is included in the preset process blacklist, if it does not exist, apply for shared memory for the process, and if it exists, refuse to apply for shared memory for the process , So that the server can selectively apply for shared memory for the client, and then can ensure the security of the server on the basis of ensuring the efficiency of log processing.
进一步地,在上述任一实施例的基础上,所述注册请求是根据预设的日志写入配置生成的;Further, on the basis of any of the foregoing embodiments, the registration request is generated according to a preset log writing configuration;
所述根据所述注册请求为所述客户端申请共享内存,包括:The applying for shared memory for the client according to the registration request includes:
根据所述日志写入配置为所述客户端申请共享内存。Apply for shared memory for the client according to the log writing configuration.
在本实施例中,客户端在在向服务端发送注册请求之前,可以首先确 定日志写入配置,并根据该日志写入配置生成注册请求。该日志写入配置具体可以是用户根据当前需求输入的,也可以为默认的写入配置,本发明在此不做限制。服务端可以根据该日志写入配置为客户端申请共享内存。该日志写入配置包括待占用内存大小、存储模式、存储位置、存储的子文件夹划分和存储的子文件夹大小中的至少一种。其中,存储的子文件夹用于根据线程的不同功能划分存储的子文件夹,也可根据日志的不同类型划分存储的子文件夹。可选地,不同的优先级可以对应不同的日志写入配置,举例来说,优先级较低的日志写入配置中可以只包括待占用内存大小,而优先级较高的客户端的日志写入配置中还可以包括其他个性化的需求参数。In this embodiment, before sending a registration request to the server, the client may first determine the log writing configuration, and generate a registration request according to the log writing configuration. The log writing configuration may specifically be input by the user according to current requirements, or may be a default writing configuration, which is not limited in the present invention. The server can apply for shared memory for the client according to the log writing configuration. The log writing configuration includes at least one of memory size to be occupied, storage mode, storage location, storage subfolder division, and storage subfolder size. Among them, the stored subfolders are used to divide the stored subfolders according to different functions of threads, and the stored subfolders may also be divided according to different types of logs. Optionally, different priorities can correspond to different log writing configurations. For example, the log writing configuration with a lower priority can only include the memory size to be occupied, while the log writing of the client with a higher priority The configuration can also include other personalized demand parameters.
本实施例提供的日志处理方法,通过根据所述日志写入配置为所述客户端申请共享内存,从而能够在提高日志处理效率的基础上,满足客户端在日志写入过程中的个性化需求。According to the log processing method provided in this embodiment, by applying for shared memory for the client according to the log writing configuration, it is possible to improve the log processing efficiency and meet the client's personalized needs in the log writing process. .
进一步地,在上述任一实施例的基础上,所述根据所述注册请求为所述客户端申请共享内存之后,还包括:Further, on the basis of any of the foregoing embodiments, after the application for shared memory for the client according to the registration request, the method further includes:
对所述共享内存进行初始化操作,获得无锁队列实例。Perform an initialization operation on the shared memory to obtain a lock-free queue instance.
在本实施例中,服务端在根据注册请求为客户端申请共享内存之后,可以对该共享内存进行初始化操作,获得无锁队列实例。,该无锁队列实例可以是由比较与替换(Compare and Set,简称CAS)机制实现的无锁队列实例,也可以采用其他任意一种机制实现的无锁队列实例,本发明在此不做限制。使用无锁队列实例能够在提高日志处理效率的基础上,节省锁开销。In this embodiment, after the server applies for shared memory for the client according to the registration request, the shared memory may be initialized to obtain a lock-free queue instance. The lock-free queue instance can be a lock-free queue instance implemented by a Compare and Replace (Compare and Set, CAS for short) mechanism, or a lock-free queue instance implemented by any other mechanism, and the present invention is not limited here. . Using a lock-free queue instance can save lock overhead on the basis of improving log processing efficiency.
本实施例提供的日志处理方法,通过对所述共享内存进行初始化操作,获得无锁队列实例,从而能够提高日志处理效果,进而能够实现对多进程高并发场景下的日志处理。The log processing method provided in this embodiment obtains a lock-free queue instance by initializing the shared memory, thereby improving the log processing effect, and further enabling log processing in a multi-process high concurrency scenario.
可选地,在上述任一实施例的基础上,所述根据所述注册请求为所述客户端申请共享内存之后,还包括:Optionally, on the basis of any of the foregoing embodiments, after applying for shared memory for the client according to the registration request, the method further includes:
对所述共享内存进行初始化操作,获得有锁队列实例。Perform an initialization operation on the shared memory to obtain a locked queue instance.
进一步地,在上述任一实施例的基础上,所述方法还包括:Further, on the basis of any of the foregoing embodiments, the method further includes:
当接收到所述客户端发送的重新连接请求,根据所述重新连接请求重 新与所述共享内存连接。When receiving the reconnection request sent by the client, reconnect with the shared memory according to the reconnection request.
在本实施例中,为了实现日志信息的成功写入以及取出存储,客户端和服务端需要同时连接至共享内存。因此,在客户端检测到服务端与共享内存断开连接时,可以给服务端发送重新连接请求。相应地,当服务端接收到重新连接请求之后,可以根据该重新连接请求重新与共享内存建立通信连接。In this embodiment, in order to achieve successful writing and storage of log information, the client and the server need to be connected to the shared memory at the same time. Therefore, when the client detects that the server is disconnected from the shared memory, it can send a reconnection request to the server. Correspondingly, after receiving the reconnection request, the server can re-establish a communication connection with the shared memory according to the reconnection request.
本实施例提供的日志处理方法,通过当接收到所述客户端发送的重新连接请求,根据所述重新连接请求重新与所述共享内存连接。从而能够保证日志写入的有效性,进一步地提高日志处理的效率。In the log processing method provided in this embodiment, when a reconnection request sent by the client is received, it reconnects to the shared memory according to the reconnection request. Thereby, the effectiveness of log writing can be ensured, and the efficiency of log processing can be further improved.
进一步地,在上述任一实施例的基础上,所述注册成功信息包括所述服务端给所述客户端分配的识别码;所述重新连接请求中包括所述识别码;所述根据所述重新连接请求重新与所述共享内存连接,包括:Further, on the basis of any of the foregoing embodiments, the registration success information includes the identification code allocated by the server to the client; the reconnection request includes the identification code; The reconnection request to reconnect with the shared memory includes:
根据所述重新连接请求中的识别码连接至所述共享内存。Connect to the shared memory according to the identification code in the reconnection request.
在本实施例中,服务端在成功申请共享内存之后,可以向客户端发送注册成功信息,其中,该注册成功信息中包括服务端给客户端分配的识别码。当客户端检测到服务端与共享内存断开连接之后,可以向服务端发送包括该识别码的重新连接请求,因此,服务端可以根据该识别码重新连接至共享内存中。In this embodiment, after successfully applying for shared memory, the server may send registration success information to the client, where the registration success information includes the identification code assigned by the server to the client. After the client detects that the server is disconnected from the shared memory, it can send a reconnection request including the identification code to the server. Therefore, the server can reconnect to the shared memory according to the identification code.
本实施例提供的日志处理方法,通过根据所述重新连接请求中的识别码连接至所述共享内存,从而能够使服务端根据该识别码重新连接至共享内存中,进而能够在保证日志写入的有效性的基础上,进一步地提高日志处理的效率。The log processing method provided in this embodiment connects to the shared memory according to the identification code in the reconnection request, so that the server can reconnect to the shared memory according to the identification code, and thus can ensure that the log is written On the basis of the effectiveness, the efficiency of log processing is further improved.
进一步地,在上述任一实施例的基础上,所述向所述客户端发送注册成功信息之后,还包括:Further, on the basis of any of the foregoing embodiments, after the sending of registration success information to the client, the method further includes:
对所述共享内存中的日志写入状况进行监控,根据监控结果对所述客户端进行管控。The log writing status in the shared memory is monitored, and the client is managed and controlled according to the monitoring result.
在本实施例中,客户端在接收到注册成功信息之后,可以在共享内存中写入日志信息。为了进一步地提高日志处理效率,服务端可以对共享内存中的日志写入状态进行监控,根据监控结果对客户端进行管控。举例来说,可以根据日志写入状态确定客户端是否为恶意客户端,以及客户端当 前是否发生故障等。In this embodiment, the client can write log information in the shared memory after receiving the registration success information. In order to further improve the log processing efficiency, the server can monitor the log writing status in the shared memory, and control the client according to the monitoring results. For example, you can determine whether the client is a malicious client based on the log writing status, and whether the client is currently malfunctioning.
本实施例提供的日志处理方法,通过对所述共享内存中的日志写入状况进行监控,根据监控结果对所述客户端进行管控,从而能够在提高日志处理效率的基础上,实现对客户端的有效管控。The log processing method provided in this embodiment monitors the log writing status in the shared memory, and manages and controls the client according to the monitoring result, so that the log processing efficiency can be improved on the basis of improving the log processing efficiency. Effective management and control.
进一步地,在上述任一实施例的基础上,所述对所述共享内存中的日志写入状况进行监控,根据监控结果对所述客户端进行管控,包括:Further, on the basis of any of the foregoing embodiments, the monitoring of the log writing status in the shared memory and the management and control of the client according to the monitoring result includes:
判断所述客户端写入日志的速度是否超过预设的速度阈值;Determining whether the speed at which the client writes the log exceeds a preset speed threshold;
若是,则判定所述客户端出现故障。If yes, it is determined that the client is faulty.
在本实施例中,可以确定客户端当前写入日志的速度,并根据该速度对客户端的状态进行确定。具体地,若检测到客户端写入日志的速度超过预设的速度阈值,则可以判定客户端当前发生故障,反正,则表征当前客户端正常运行。In this embodiment, the current speed at which the client writes the log can be determined, and the status of the client can be determined according to the speed. Specifically, if it is detected that the speed at which the client writes the log exceeds a preset speed threshold, it can be determined that the client is currently malfunctioning, anyway, it means that the current client is operating normally.
可选地,在上述任一实施例的基础上,所述对所述共享内存中的日志写入状况进行监控,根据监控结果对所述客户端进行管控,包括:Optionally, on the basis of any of the foregoing embodiments, the monitoring of the log writing status in the shared memory and the management and control of the client according to the monitoring result includes:
判断所述客户端写入日志的数量是否超过预设的数量阈值;Judging whether the number of logs written by the client exceeds a preset number threshold;
若是,则判定所述客户端出现故障。If yes, it is determined that the client is faulty.
在本实施例中,可以确定客户端当前写入日志的数量,并根据该数量对客户端的状态进行确定。具体地,若检测到客户端写入日志的数量超过预设的数量阈值,则可以判定客户端当前发生故障,反之,则表征当前客户端正常运行。In this embodiment, the number of logs currently written by the client can be determined, and the status of the client can be determined according to the number. Specifically, if it is detected that the number of logs written by the client exceeds a preset number threshold, it can be determined that the client is currently malfunctioning, otherwise, it means that the current client is operating normally.
需要说明的是,上述两个实施例可以单独实施,也可以结合实施。当其结合实施时,可以根据客户端当前写入日志的数量以及速度,确定客户端当前写入日志的数量是否超过预设的数量阈值以及客户端当前写入日志的速度是否超过预设的速度阈值,若是,则判定客户端当前发生故障,反正,则表征当前客户端正常运行。It should be noted that the above two embodiments can be implemented separately or in combination. When it is implemented in combination, it can be determined whether the number of logs currently written by the client exceeds the preset number threshold and whether the speed of the client currently writing logs exceeds the preset speed according to the number and speed of logs currently written by the client The threshold, if yes, it is determined that the client is currently malfunctioning, anyway, it means that the current client is operating normally.
本实施例提供的日志处理方法,通过判断客户端当前写入日志的数量和/或速度是否超过预设的数量和/或速度阈值,确定客户端当前是否发生故障,则可以有效地实现对客户端的监控。The log processing method provided in this embodiment determines whether the client is currently malfunctioning by determining whether the number and/or speed of logs currently written by the client exceed the preset number and/or speed threshold, which can effectively achieve the End monitoring.
图9为本发明实施例九提供的日志处理方法的流程示意图,在上述任一实施例的基础上,如图9所示,所述判定所述客户端出现故障之后,还 包括:Fig. 9 is a schematic flowchart of a log processing method according to the ninth embodiment of the present invention. Based on any of the foregoing embodiments, as shown in Fig. 9, after determining that the client is faulty, the method further includes:
步骤901、根据所述进程标识确定所述客户端对应的权限信息;Step 901: Determine permission information corresponding to the client according to the process identifier.
步骤902、根据所述权限信息对所述客户端写入的日志信息进行管控。Step 902: Manage and control the log information written by the client according to the authority information.
在本实施例中,在判定客户端出现故障之后,可以根据客户端的进程标识确定客户端对应的权限信息,根据权限信息对客户端写入的日志信息进行管控。以实际应用举例来说,若当前写入日志的客户端的优先级较高,在检测到该客户端当前写入日志的数量和/或速度超过预设的数量和/或速度阈值时,可以对全部日志信息进行存储;相应地,若当前写入日志的客户端的优先级较低,在检测到该客户端当前写入日志的数量和/或速度超过预设的数量和/或速度阈值时,可以对该客户端写入的日志信息进行部分存储,或者可以拒绝为该客户端继续提供共享内存。In this embodiment, after determining that the client is faulty, the permission information corresponding to the client can be determined according to the process identifier of the client, and the log information written by the client can be controlled according to the permission information. Take a practical application as an example, if the priority of the client currently writing logs is higher, when it is detected that the number and/or speed of the client currently writing logs exceeds the preset number and/or speed threshold, the All log information is stored; accordingly, if the priority of the client currently writing to the log is lower, when it is detected that the number and/or speed of the current written log of the client exceeds the preset number and/or speed threshold, Part of the log information written by the client can be stored, or the client can be refused to continue to provide shared memory.
本实施例提供的日志处理方法,通过根据所述进程标识确定所述客户端对应的权限信息,根据所述权限信息对所述客户端写入的日志信息进行管控,从而能够实现对客户端的有效管控。In the log processing method provided in this embodiment, the authority information corresponding to the client is determined according to the process identifier, and the log information written by the client is controlled according to the authority information, so as to be effective for the client. Control.
进一步地,在上述任一实施例的基础上,所述方法还包括:从所述共享内存中获取所述日志信息,对所述日志信息进行发布处理。Further, on the basis of any of the foregoing embodiments, the method further includes: acquiring the log information from the shared memory, and performing publishing processing on the log information.
在本实施例中,客户端将日志信息写入至共享内存中,服务端可以从共享内存中获取日志信息并进行发布处理。In this embodiment, the client writes the log information into the shared memory, and the server can obtain the log information from the shared memory and perform publishing processing.
图10为本发明实施例十提供的客户终端设备的结构示意图,如图10所示,所述终端设备包括:FIG. 10 is a schematic structural diagram of a client terminal device according to Embodiment 10 of the present invention. As shown in FIG. 10, the terminal device includes:
存储器111和处理器112; Memory 111 and processor 112;
所述存储器111用于存储程序代码;The memory 111 is used to store program codes;
所述处理器112,调用所述程序代码,当程序代码被执行时,用于执行以下操作:The processor 112 calls the program code, and when the program code is executed, is configured to perform the following operations:
通过预设的调用接口向服务端发送注册请求;Send a registration request to the server through the preset calling interface;
当接收到所述服务端反馈的注册成功信息时,将所述客户端的日志信息写入所述共享内存中。When the registration success information fed back by the server is received, the log information of the client is written into the shared memory.
进一步地,在上述任一实施例的基础上,所述共享内存为无锁队列实例。Further, on the basis of any of the foregoing embodiments, the shared memory is a lock-free queue instance.
进一步地,在上述任一实施例的基础上,所述共享内存为有锁队列实 例。Further, on the basis of any of the foregoing embodiments, the shared memory is an example of a locked queue.
进一步地,在上述任一实施例的基础上,所述注册请求由所述客户端的其中一个线程发送。Further, on the basis of any of the foregoing embodiments, the registration request is sent by one of the threads of the client.
进一步地,在上述任一实施例的基础上,所述处理器在将所述客户端的日志信息写入所述共享内存中时,用于:Further, on the basis of any of the foregoing embodiments, when the processor writes the log information of the client into the shared memory, it is configured to:
将所述客户端中每一线程的日志按照预定的线程存储顺序写入所述共享内存中。The log of each thread in the client is written into the shared memory according to a predetermined thread storage sequence.
进一步地,在上述任一实施例的基础上,所述处理器在将所述客户端的日志信息写入所述共享内存中时,用于:Further, on the basis of any of the foregoing embodiments, when the processor writes the log information of the client into the shared memory, it is configured to:
将优先级高于预设的第一打印级别的日志信息存入所述共享内存中。Store log information with a priority higher than the preset first printing level in the shared memory.
进一步地,在上述任一实施例的基础上,所述日志信息的打印级别包括优先级由高到低依次排列的OFF级别、FATAL级别、ERROR级别、WARN级别、INFO级别、DEBUG级别、TRACE级别和ALL级别。Further, on the basis of any of the foregoing embodiments, the printing level of the log information includes OFF level, FATAL level, ERROR level, WARN level, INFO level, DEBUG level, and TRACE level in descending order of priority. And ALL level.
进一步地,在上述任一实施例的基础上,所述处理器在将所述客户端的日志信息写入所述共享内存时,用于:Further, on the basis of any of the foregoing embodiments, when the processor writes the log information of the client to the shared memory, it is configured to:
以异步存储的方式将所述客户端的日志信息写入所述共享内存中。The log information of the client is written into the shared memory in an asynchronous storage manner.
进一步地,在上述任一实施例的基础上,所述注册信息中还包括发送所述注册请求的进程的进程标识,以使所述服务端能够根据所述进程标识确定是否为所述进程提供内存信息。Further, on the basis of any of the foregoing embodiments, the registration information also includes the process identifier of the process that sent the registration request, so that the server can determine whether to provide the process for the process according to the process identifier. Memory information.
进一步地,在上述任一实施例的基础上,所述处理器在通过所述客户端预设的调用接口向服务端发送注册请求之前,还用于:Further, on the basis of any of the foregoing embodiments, before sending a registration request to the server through the calling interface preset by the client, the processor is further configured to:
根据预设的日志写入配置生成所述注册请求。The registration request is generated according to the preset log writing configuration.
进一步地,在上述任一实施例的基础上,所述日志写入配置包括待占用内存大小、存储模式、存储位置、存储的子文件夹划分和存储的子文件夹大小中的至少一种。Further, on the basis of any of the foregoing embodiments, the log writing configuration includes at least one of the size of the memory to be occupied, the storage mode, the storage location, the division of storage subfolders, and the size of the storage subfolders.
进一步地,在上述任一实施例的基础上,所述处理器在当接收到所述服务端反馈的注册成功信息时,将所述客户端的日志信息写入所述共享内存中之后,还用于:Further, on the basis of any of the foregoing embodiments, after the processor writes the log information of the client into the shared memory when receiving the registration success information fed back by the server, it also uses in:
获取所述共享内存的连接数;Acquiring the number of connections of the shared memory;
根据所述连接数确定所述服务端与所述共享内存是否断开连接。Determine whether the server is disconnected from the shared memory according to the number of connections.
进一步地,在上述任一实施例的基础上,所述处理器在根据所述连接数确定所述服务端与所述共享内存是否断开连接时,用于:Further, on the basis of any of the foregoing embodiments, when determining whether the server is disconnected from the shared memory according to the number of connections, the processor is configured to:
若所述客户端与所述共享内存保持连接,且所述连接数小于预设的连接总量时,则判定所述服务端与所述共享内存断开连接;所述连接总量为正常日志存储状态下所述共享内存的连接数;If the client remains connected to the shared memory, and the number of connections is less than the preset total number of connections, it is determined that the server is disconnected from the shared memory; the total number of connections is a normal log The number of connections of the shared memory in the storage state;
若所述客户端与所述共享内存保持连接,且所述连接数不小于预设的连接总量,则判定所述服务端与所述共享内存未断开连接。If the client remains connected to the shared memory and the number of connections is not less than the preset total number of connections, it is determined that the server is not disconnected from the shared memory.
进一步地,在上述任一实施例的基础上,所述处理器还用于:Further, on the basis of any of the foregoing embodiments, the processor is further configured to:
当判定所述服务端断开连接时,按照预设的频率向所述服务端发送重新连接请求。When it is determined that the server is disconnected, a reconnection request is sent to the server at a preset frequency.
进一步地,在上述任一实施例的基础上,所述注册成功信息包括所述服务端给所述客户端分配的识别码;所述重新连接请求中包括所述识别码;所述识别码用于使得所述服务端能够根据所述重新连接请求中的识别码连接至所述共享内存。Further, on the basis of any of the foregoing embodiments, the registration success information includes an identification code allocated by the server to the client; the reconnection request includes the identification code; the identification code is used Therefore, the server can connect to the shared memory according to the identification code in the reconnection request.
图11为本发明实施例十一提供的服务终端设备的结构示意图,如图11所示,所述服务终端设备包括:存储器121和处理器122;FIG. 11 is a schematic structural diagram of a service terminal device according to Embodiment 11 of the present invention. As shown in FIG. 11, the service terminal device includes: a memory 121 and a processor 122;
所述存储器121用于存储程序代码;The memory 121 is used to store program codes;
所述处理器122,调用所述程序代码,当程序代码被执行时,用于执行以下操作:The processor 122 calls the program code, and when the program code is executed, is used to perform the following operations:
接收客户端发送的注册请求;Receive the registration request sent by the client;
根据所述注册请求为所述客户端申请共享内存;Apply for shared memory for the client according to the registration request;
当所述共享内存申请成功后,向所述客户端发送注册成功信息,以使所述客户端根据所述注册成功信息在所述共享内存中写入日志信息,所述注册成功信息中包括所述共享内存;After the shared memory application is successful, the registration success information is sent to the client, so that the client writes log information in the shared memory according to the registration success information, and the registration success information includes all The shared memory;
从所述共享内存中获取所述日志信息,并存储至预设的存储路径。The log information is obtained from the shared memory and stored in a preset storage path.
进一步地,在上述任一实施例的基础上,所述处理器在从所述共享内存中获取所述日志信息,并存储至预设的存储路径时,用于:Further, on the basis of any of the foregoing embodiments, when the processor obtains the log information from the shared memory and stores it in a preset storage path, it is configured to:
从所述共享内存中获取优先级高于预设的第二打印级别的日志信息,并存储至预设的存储路径。Obtain log information with a priority higher than the preset second printing level from the shared memory, and store it in a preset storage path.
进一步地,在上述任一实施例的基础上,所述日志信息的打印级别包 括优先级由高到低依次排列的OFF级别、FATAL级别、ERROR级别、WARN级别、INFO级别、DEBUG级别、TRACE级别和ALL级别。Further, on the basis of any of the foregoing embodiments, the printing level of the log information includes OFF level, FATAL level, ERROR level, WARN level, INFO level, DEBUG level, and TRACE level in descending order of priority. And ALL level.
进一步地,在上述任一实施例的基础上,所述处理器在服务端从所述共享内存中获取所述日志信息并存储至预设的存储路径中时,用于:Further, on the basis of any of the foregoing embodiments, when the server obtains the log information from the shared memory and stores it in a preset storage path, the processor is configured to:
所述服务端以单线程的方式从所述共享内存中获取所述日志信息并存储至预设的存储路径中。The server obtains the log information from the shared memory in a single-threaded manner and stores it in a preset storage path.
进一步地,在上述任一实施例的基础上,所述注册请求中包括待占用内存量,所述处理器在根据所述注册请求为所述客户端申请共享内存时,用于:Further, on the basis of any of the foregoing embodiments, the registration request includes the amount of memory to be occupied, and when applying for shared memory for the client according to the registration request, the processor is configured to:
确定所述服务端当前内存剩余量;Determine the current remaining amount of memory on the server;
根据所述内存剩余量以及所述待占用内存量为所述客户端申请共享内存。Apply for shared memory for the client according to the remaining amount of memory and the amount of memory to be occupied.
进一步地,在上述任一实施例的基础上,所述处理器在根据所述内存剩余量以及所述待占用内存量为所述客户端申请共享内存时,用于:Further, on the basis of any of the foregoing embodiments, when the processor applies for shared memory for the client according to the remaining amount of memory and the amount of memory to be occupied, the processor is configured to:
若所述待占用内存量小于所述内存剩余量,则为所述客户端申请与所述待占用内存量对应的共享内存;If the amount of memory to be occupied is less than the remaining amount of memory, apply for a shared memory corresponding to the amount of memory to be occupied for the client;
若所述待占用内存量不小于所述内存剩余量,则拒绝为所述客户端申请共享内存。If the amount of memory to be occupied is not less than the remaining amount of memory, refuse to apply for shared memory for the client.
进一步地,在上述任一实施例的基础上,所述注册请求中还包括所述进程标识;Further, on the basis of any of the foregoing embodiments, the registration request further includes the process identifier;
相应地,所述处理器在根据所述注册请求为所述客户端申请共享内存时,用于:Correspondingly, when applying for shared memory for the client according to the registration request, the processor is configured to:
判断预设的进程黑名单中是否包括所述进程标识;Determine whether the process identifier is included in the preset process blacklist;
若不存在,则为所述进程申请共享内存;If it does not exist, apply for shared memory for the process;
若存在,则拒绝为所述进程申请共享内存。If it exists, refuse to apply for shared memory for the process.
进一步地,在上述任一实施例的基础上,所述注册请求是根据预设的日志写入配置生成的;Further, on the basis of any of the foregoing embodiments, the registration request is generated according to a preset log writing configuration;
所述处理器在根据所述注册请求为所述客户端申请共享内存时,用于:When applying for shared memory for the client according to the registration request, the processor is configured to:
根据所述日志写入配置为所述客户端申请共享内存。Apply for shared memory for the client according to the log writing configuration.
进一步地,在上述任一实施例的基础上,所述日志写入配置包括待占 用内存大小、存储模式、存储位置、存储的子文件夹划分和存储的子文件夹大小中的至少一种。Further, on the basis of any of the foregoing embodiments, the log writing configuration includes at least one of the size of the memory to be occupied, the storage mode, the storage location, the division of storage subfolders, and the size of the storage subfolders.
进一步地,在上述任一实施例的基础上,所述处理器在根据所述注册请求为所述客户端申请共享内存之后,还用于:Further, on the basis of any of the foregoing embodiments, after applying for shared memory for the client according to the registration request, the processor is further configured to:
对所述共享内存进行初始化操作,获得无锁队列实例。Perform an initialization operation on the shared memory to obtain a lock-free queue instance.
进一步地,在上述任一实施例的基础上,对所述共享内存进行初始化操作,获得有锁队列实例。Further, on the basis of any of the foregoing embodiments, an initialization operation is performed on the shared memory to obtain a locked queue instance.
进一步地,在上述任一实施例的基础上,所述处理器还用于:Further, on the basis of any of the foregoing embodiments, the processor is further configured to:
当接收到所述客户端发送的重新连接请求,根据所述重新连接请求重新与所述共享内存连接。When receiving the reconnection request sent by the client, reconnect with the shared memory according to the reconnection request.
进一步地,在上述任一实施例的基础上,所述注册成功信息包括所述服务端给所述客户端分配的识别码;所述重新连接请求中包括所述识别码;所述处理器在根据所述重新连接请求重新与所述共享内存连接时,用于:Further, on the basis of any of the foregoing embodiments, the registration success information includes an identification code assigned by the server to the client; the reconnection request includes the identification code; the processor is When reconnecting to the shared memory according to the reconnection request, it is used to:
根据所述重新连接请求中的识别码连接至所述共享内存。Connect to the shared memory according to the identification code in the reconnection request.
进一步地,在上述任一实施例的基础上,所述处理器在向所述客户端发送注册成功信息之后,还用于:Further, on the basis of any of the foregoing embodiments, after sending the registration success information to the client, the processor is further configured to:
对所述共享内存中的日志写入状况进行监控,根据监控结果对所述客户端进行管控。The log writing status in the shared memory is monitored, and the client is managed and controlled according to the monitoring result.
进一步地,在上述任一实施例的基础上,所述处理器在对所述共享内存中的日志写入状况进行监控,根据监控结果对所述客户端进行管控时,用于:Further, on the basis of any one of the foregoing embodiments, the processor is configured to monitor the log writing status in the shared memory and to manage and control the client according to the monitoring result:
判断所述客户端写入日志的速度是否超过预设的速度阈值;Determining whether the speed at which the client writes the log exceeds a preset speed threshold;
若是,则判定所述客户端出现故障。If yes, it is determined that the client is faulty.
进一步地,在上述任一实施例的基础上,所述处理器在对所述共享内存中的日志写入状况进行监控,根据监控结果对所述客户端进行管控时,用于:Further, on the basis of any of the foregoing embodiments, when the processor monitors the log writing status in the shared memory, and controls the client according to the monitoring result, it is configured to:
判断所述客户端写入日志的数量是否超过预设的数量阈值;Judging whether the number of logs written by the client exceeds a preset number threshold;
若是,则判定所述客户端出现故障。If yes, it is determined that the client is faulty.
进一步地,在上述任一实施例的基础上,所述处理器在判定所述客户端出现故障之后,还用于:Further, on the basis of any of the foregoing embodiments, after determining that the client has a fault, the processor is further configured to:
根据所述进程标识确定所述客户端对应的权限信息;Determining the authority information corresponding to the client according to the process identifier;
根据所述权限信息对所述客户端写入的日志信息进行管控。The log information written by the client is managed and controlled according to the authority information.
进一步地,在上述任一实施例的基础上,所述处理器还用于:从所述共享内存中获取所述日志信息,对所述日志信息进行发布处理。Further, on the basis of any of the foregoing embodiments, the processor is further configured to: obtain the log information from the shared memory, and perform publishing processing on the log information.
本发明还提供了一种日志处理系统,所述系统包括The present invention also provides a log processing system, which includes
一个或多个处理器;One or more processors;
一个或多个存储器;One or more memories;
所述存储器用于存储程序代码;The memory is used to store program codes;
所述处理器,用于调用所述程序代码,当程序代码被执行时,用于执行以下操作:The processor is used to call the program code, and when the program code is executed, it is used to perform the following operations:
通过客户端预设的调用接口向服务端发送注册请求;Send a registration request to the server through the call interface preset by the client;
所述服务端接收客户端发送的注册请求;The server receives the registration request sent by the client;
所述服务端根据所述注册请求为所述客户端申请共享内存;The server applies for shared memory for the client according to the registration request;
当所述共享内存申请成功后,所述服务端向所述客户端发送注册成功信息;After the shared memory application is successful, the server sends registration success information to the client;
所述客户端当接收到所述服务端反馈的注册成功信息时,将所述客户端的日志信息写入所述共享内存中;When the client receives the registration success information fed back by the server, writes the log information of the client into the shared memory;
所述服务端从所述共享内存中获取所述日志信息,并存储至预设的存储路径。The server obtains the log information from the shared memory and stores it in a preset storage path.
需要说明的是,上述方法可以由一个处理器完成,也可以由多个服务器完成。当由一个处理器完成时,客户端程序与服务端程序都设置在同一个设备中。当由多个服务器完成时,客户端程序对应一个处理器执行,服务端程序对应一个处理器执行,二者可以设置在同一个设备中,也可以设置在两个独立的设备中,本发明在此不做限制。It should be noted that the above method can be completed by one processor or by multiple servers. When completed by a processor, the client program and the server program are both set in the same device. When completed by multiple servers, the client program corresponds to one processor for execution, and the server program corresponds to one processor for execution. The two can be set in the same device or in two independent devices. The present invention is There is no restriction.
进一步地,在上述任一实施例的基础上,所述共享内存为无锁队列实例。Further, on the basis of any of the foregoing embodiments, the shared memory is a lock-free queue instance.
进一步地,在上述任一实施例的基础上,所述共享内存为有锁队列实例。Further, on the basis of any of the foregoing embodiments, the shared memory is a locked queue instance.
进一步地,在上述任一实施例的基础上,所述注册请求由所述客户端的其中一个线程发送。Further, on the basis of any of the foregoing embodiments, the registration request is sent by one of the threads of the client.
进一步地,在上述任一实施例的基础上,所述处理器在通过所述客户端将所述客户端的日志信息写入所述共享内存中时,用于:Further, on the basis of any of the foregoing embodiments, when the processor writes the log information of the client into the shared memory through the client, it is configured to:
通过所述客户端将所述客户端中每一线程的日志按照预定的线程存储顺序写入所述共享内存中。The log of each thread in the client is written into the shared memory through the client according to a predetermined thread storage sequence.
进一步地,在上述任一实施例的基础上,所述处理器在通过所述客户端将所述客户端的日志信息写入所述共享内存中时,用于:Further, on the basis of any of the foregoing embodiments, when the processor writes the log information of the client into the shared memory through the client, it is configured to:
通过所述客户端将优先级高于预设的第一打印级别的日志信息存入所述共享内存中。The log information whose priority is higher than the preset first printing level is stored in the shared memory through the client.
进一步地,在上述任一实施例的基础上,所述日志信息的打印级别包括优先级由高到低依次排列的OFF级别、FATAL级别、ERROR级别、WARN级别、INFO级别、DEBUG级别、TRACE级别和ALL级别。Further, on the basis of any of the foregoing embodiments, the printing level of the log information includes OFF level, FATAL level, ERROR level, WARN level, INFO level, DEBUG level, and TRACE level in descending order of priority. And ALL level.
进一步地,在上述任一实施例的基础上,所述处理器在通过所述客户端将所述客户端的日志信息写入所述共享内存中时,用于:Further, on the basis of any of the foregoing embodiments, when the processor writes the log information of the client into the shared memory through the client, it is configured to:
通过所述客户端以异步存储的方式将所述客户端的日志信息写入所述共享内存中。The log information of the client is written into the shared memory through the client in an asynchronous storage manner.
进一步地,在上述任一实施例的基础上,所述处理器在通过所述客户端预设的调用接口向服务端发送注册请求之前,还用于:Further, on the basis of any of the foregoing embodiments, before sending a registration request to the server through the calling interface preset by the client, the processor is further configured to:
通过所述客户端根据预设的日志写入配置生成所述注册请求。The registration request is generated by the client according to a preset log writing configuration.
进一步地,在上述任一实施例的基础上,所述日志写入配置包括待占用内存大小、存储模式、存储位置、存储的子文件夹划分和存储的子文件夹大小中的至少一种。Further, on the basis of any of the foregoing embodiments, the log writing configuration includes at least one of the size of the memory to be occupied, the storage mode, the storage location, the division of storage subfolders, and the size of the storage subfolders.
进一步地,在上述任一实施例的基础上,所述处理器在当接收到所述服务端反馈的注册成功信息时,通过所述客户端将所述客户端的日志信息写入所述共享内存中之后,还用于:Further, on the basis of any of the foregoing embodiments, when the processor receives the registration success information fed back by the server, writes the log information of the client into the shared memory through the client After the middle, it is also used for:
通过所述客户端获取所述共享内存的连接数;Acquiring the number of connections of the shared memory through the client;
通过所述客户端根据所述连接数确定所述服务端与所述共享内存是否断开连接。The client determines whether the server is disconnected from the shared memory according to the number of connections.
进一步地,在上述任一实施例的基础上,所述处理器在通过所述客户端根据所述连接数确定所述服务端与所述共享内存是否断开连接时,用于:Further, on the basis of any of the foregoing embodiments, when the processor determines whether the server is disconnected from the shared memory according to the number of connections through the client, it is configured to:
若所述客户端与所述共享内存保持连接,且所述连接数小于预设的连 接总量时,则通过所述客户端判定所述服务端与所述共享内存断开连接;其中,所述连接总量为正常日志存储状态下所述共享内存的连接数;If the client remains connected to the shared memory, and the number of connections is less than the preset total number of connections, the client determines that the server is disconnected from the shared memory; wherein, The total number of connections is the number of connections of the shared memory in the normal log storage state;
若所述客户端与所述共享内存保持连接,且所述连接数不小于预设的连接总量,则通过所述客户端判定所述服务端与所述共享内存未断开连接。If the client maintains a connection with the shared memory, and the number of connections is not less than a preset total number of connections, it is determined by the client that the server is not disconnected from the shared memory.
进一步地,在上述任一实施例的基础上,所述处理器还用于:Further, on the basis of any of the foregoing embodiments, the processor is further configured to:
当判定所述服务端断开连接时,通过所述客户端按照预设的频率向所述服务端发送重新连接请求;When it is determined that the server is disconnected, sending a reconnection request to the server through the client according to a preset frequency;
当所述服务端接收到所述客户端发送的重新连接请求,通过所述服务端根据所述重新连接请求重新与所述共享内存连接。When the server receives the reconnection request sent by the client, the server reconnects to the shared memory according to the reconnection request.
进一步地,在上述任一实施例的基础上,所述注册成功信息包括所述服务端给所述客户端分配的识别码;所述重新连接请求包括所述识别码;所述处理器在通过所述服务端根据所述重新连接请求重新与所述共享内存连接时,用于:Further, on the basis of any of the foregoing embodiments, the registration success information includes the identification code allocated by the server to the client; the reconnection request includes the identification code; the processor is passing When the server reconnects to the shared memory according to the reconnection request, it is used to:
通过所述服务端根据所述重新连接请求中的识别码连接至所述共享内存。Connect to the shared memory through the server according to the identification code in the reconnection request.
进一步地,在上述任一实施例的基础上,所述处理器在通过所述服务端从所述共享内存中获取所述日志信息,并存储至预设的存储路径时,用于:Further, on the basis of any of the foregoing embodiments, when the processor obtains the log information from the shared memory through the server and stores it in a preset storage path, it is configured to:
通过所述服务端从所述共享内存中获取优先级高于预设的第二打印级别的日志信息,并存储至预设的存储路径。Obtain log information with a priority higher than a preset second printing level from the shared memory through the server, and store it in a preset storage path.
进一步地,在上述任一实施例的基础上,所述日志信息的打印级别包括优先级由高到低依次排列的OFF级别、FATAL级别、ERROR级别、WARN级别、INFO级别、DEBUG级别、TRACE级别和ALL级别。Further, on the basis of any of the foregoing embodiments, the printing level of the log information includes OFF level, FATAL level, ERROR level, WARN level, INFO level, DEBUG level, and TRACE level in descending order of priority. And ALL level.
进一步地,在上述任一实施例的基础上,所述处理器在通过所述服务端从所述共享内存中获取所述日志信息,并存储至预设的存储路径时,用于:Further, on the basis of any of the foregoing embodiments, when the processor obtains the log information from the shared memory through the server and stores it in a preset storage path, it is configured to:
通过所述服务端以单线程的方式从所述共享内存中获取所述日志信息并存储至预设的存储路径中。The log information is obtained from the shared memory in a single-threaded manner through the server and stored in a preset storage path.
进一步地,在上述任一实施例的基础上,所述注册请求中包括待占用内存量,所述处理器在通过所述服务端根据所述注册请求为所述客户端申 请共享内存时,用于:Further, on the basis of any of the foregoing embodiments, the registration request includes the amount of memory to be occupied, and the processor uses the server to apply for shared memory for the client according to the registration request. in:
确定所述服务端当前内存剩余量;Determine the current remaining amount of memory on the server;
通过所述服务端根据所述内存剩余量以及所述待占用内存量为所述客户端申请共享内存。The server applies for shared memory for the client according to the remaining amount of memory and the amount of memory to be occupied.
进一步地,在上述任一实施例的基础上,所述处理器在通过所述服务端根据所述内存剩余量以及所述待占用内存量为所述客户端申请共享内存时,用于:Further, on the basis of any of the foregoing embodiments, when the processor applies for shared memory for the client according to the remaining amount of memory and the amount of memory to be occupied through the server, the processor is configured to:
若所述待占用内存量小于所述内存剩余量,则为所述客户端申请与所述待占用内存量对应的共享内存;If the amount of memory to be occupied is less than the remaining amount of memory, apply for a shared memory corresponding to the amount of memory to be occupied for the client;
若所述待占用内存量不小于所述内存剩余量,则拒绝为所述客户端申请共享内存。If the amount of memory to be occupied is not less than the remaining amount of memory, refuse to apply for shared memory for the client.
进一步地,在上述任一实施例的基础上,所述注册请求还包括所述客户端的进程标识;Further, on the basis of any of the foregoing embodiments, the registration request further includes the process identifier of the client;
相应地,所述处理器在通过所述服务端根据所述注册请求为所述客户端申请共享内存时,用于:Correspondingly, when applying for shared memory for the client through the server according to the registration request, the processor is configured to:
判断预设的进程黑名单中是否包括所述进程标识;Determine whether the process identifier is included in the preset process blacklist;
若不存在,则为所述客户端申请共享内存;If it does not exist, apply for shared memory for the client;
若存在,则拒绝为所述客户端申请共享内存。If it exists, refuse to apply for shared memory for the client.
进一步地,在上述任一实施例的基础上,所述注册请求是根据预设的日志写入配置生成的;Further, on the basis of any of the foregoing embodiments, the registration request is generated according to a preset log writing configuration;
所述处理器在通过所述服务端根据所述注册请求为所述客户端申请共享内存时,用于:When the processor applies for shared memory for the client according to the registration request through the server, it is configured to:
所述服务端根据所述日志写入配置为所述客户端申请共享内存。The server applies for shared memory for the client according to the log writing configuration.
进一步地,在上述任一实施例的基础上,所述日志写入配置包括待占用内存大小、存储模式、存储位置、存储的子文件夹划分和存储的子文件夹大小中的至少一种。Further, on the basis of any of the foregoing embodiments, the log writing configuration includes at least one of the size of the memory to be occupied, the storage mode, the storage location, the division of storage subfolders, and the size of the storage subfolders.
进一步地,在上述任一实施例的基础上,所述处理器在通过所述服务端接收客户端发送的注册请求之后,还包括:Further, on the basis of any of the foregoing embodiments, after the processor receives the registration request sent by the client through the server, the processor further includes:
通过所述服务端对所述共享内存进行初始化操作,获得有锁队列实例。The server initializes the shared memory to obtain a locked queue instance.
进一步地,在上述任一实施例的基础上,所述处理器在通过所述服务 端接收客户端发送的注册请求之后,还包括:Further, on the basis of any of the foregoing embodiments, after the processor receives the registration request sent by the client through the server, the processor further includes:
通过所述服务端对所述共享内存进行初始化操作,获得有锁队列实例。The server initializes the shared memory to obtain a locked queue instance.
进一步地,在上述任一实施例的基础上,所述处理器在通过所述服务端向所述客户端发送注册成功信息之后,还包括:Further, on the basis of any of the foregoing embodiments, after the processor sends registration success information to the client through the server, the processor further includes:
通过所述服务端对所述共享内存中的日志写入状况进行监控,根据监控结果对所述客户端进行管控。The log writing status in the shared memory is monitored by the server, and the client is managed and controlled according to the monitoring result.
进一步地,在上述任一实施例的基础上,所述处理器在通过所述服务端对所述共享内存中的日志写入状况进行监控,根据监控结果对所述客户端进行管控时,用于:Further, on the basis of any of the foregoing embodiments, the processor monitors the log writing status in the shared memory through the server, and controls the client according to the monitoring result. in:
所述服务端判断所述客户端写入日志的速度是否超过预设的速度阈值;The server determines whether the speed at which the client writes the log exceeds a preset speed threshold;
若是,则判定所述客户端出现故障。If yes, it is determined that the client is faulty.
进一步地,在上述任一实施例的基础上,所述处理器在通过所述服务端对所述共享内存中的日志写入状况进行监控,根据监控结果对所述客户端进行管控时,用于:Further, on the basis of any of the foregoing embodiments, the processor monitors the log writing status in the shared memory through the server, and controls the client according to the monitoring result. in:
所述服务端判断所述客户端写入日志的数量是否超过预设的数量阈值;The server determines whether the number of logs written by the client exceeds a preset number threshold;
若是,则判定所述客户端出现故障。If yes, it is determined that the client is faulty.
进一步地,在上述任一实施例的基础上,所述处理器在判定所述客户端出现故障之后,还用于:Further, on the basis of any of the foregoing embodiments, after determining that the client has a fault, the processor is further configured to:
所述服务端根据所述客户端的进程标识确定所述客户端对应的权限信息;Determining, by the server, the authority information corresponding to the client according to the process identifier of the client;
所述服务端根据所述权限信息对所述客户端写入的日志信息进行管控。The server manages and controls the log information written by the client according to the authority information.
进一步地,在上述任一实施例的基础上,所述处理器用于:Further, on the basis of any of the foregoing embodiments, the processor is configured to:
所述服务端从所述共享内存中获取所述日志信息,对所述日志信息进行发布处理。The server obtains the log information from the shared memory, and publishes the log information.
另外,本实施例还提供一种计算机可读存储介质,其上存储有计算机程序,所述计算机程序被处理器执行以实现上述实施例所述的日志处理方法。In addition, this embodiment also provides a computer-readable storage medium on which a computer program is stored, and the computer program is executed by a processor to implement the log processing method described in the foregoing embodiment.
在本发明所提供的几个实施例中,应该理解到,所揭露的装置和方法,可以通过其它的方式实现。例如,以上所描述的装置实施例仅仅是示意性的,例如,所述单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,装置或单元的间接耦合或通信连接,可以是电性,机械或其它的形式。In the several embodiments provided by the present invention, it should be understood that the disclosed device and method may be implemented in other ways. For example, the device embodiments described above are only illustrative. For example, the division of the units is only a logical function division, and there may be other divisions in actual implementation, for example, multiple units or components can be combined or It can be integrated into another system, or some features can be ignored or not implemented. In addition, the displayed or discussed mutual coupling or direct coupling or communication connection may be indirect coupling or communication connection through some interfaces, devices or units, and may be in 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 achieve the objectives of the solutions of the embodiments.
另外,在本发明各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。上述集成的单元既可以采用硬件的形式实现,也可以采用硬件加软件功能单元的形式实现。In addition, the functional units in the various embodiments of the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware, or may be implemented in the form of hardware plus software functional units.
上述以软件功能单元的形式实现的集成的单元,可以存储在一个计算机可读取存储介质中。上述软件功能单元存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)或处理器(processor)执行本发明各个实施例所述方法的部分步骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(Read-Only Memory,ROM)、随机存取存储器(Random Access Memory,RAM)、磁碟或者光盘等各种可以存储程序代码的介质。The above-mentioned integrated unit implemented in the form of a software functional unit may be stored in a computer readable storage medium. The above-mentioned software functional unit is stored in a storage medium and includes several instructions to make a computer device (which may be a personal computer, a server, or a network device, etc.) or a processor execute the method described in the various embodiments of the present invention. Part of the steps. The aforementioned storage media include: U disk, mobile hard disk, read-only memory (Read-Only Memory, ROM), random access memory (Random Access Memory, RAM), magnetic disk or optical disk and other media that can store program code .
本领域技术人员可以清楚地了解到,为描述的方便和简洁,仅以上述各功能模块的划分进行举例说明,实际应用中,可以根据需要而将上述功能分配由不同的功能模块完成,即将装置的内部结构划分成不同的功能模块,以完成以上描述的全部或者部分功能。上述描述的装置的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。Those skilled in the art can clearly understand that, for the convenience and conciseness of the description, only the division of the above-mentioned functional modules is used as an example. In practical applications, the above-mentioned functions can be allocated by different functional modules as required, namely, the device The internal structure is divided into different functional modules to complete all or part of the functions described above. For the specific working process of the device described above, reference may be made to the corresponding process in the foregoing method embodiment, which is not repeated here.
最后应说明的是:以上各实施例仅用以说明本发明的技术方案,而非对其限制;尽管参照前述各实施例对本发明进行了详细的说明,本领域的普通技术人员应当理解:其依然可以对前述各实施例所记载的技术方案进 行修改,或者对其中部分或者全部技术特征进行等同替换;而这些修改或者替换,并不使相应技术方案的本质脱离本发明各实施例技术方案的范围。Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, but not to limit it; although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand: It is still possible to modify the technical solutions described in the foregoing embodiments, or equivalently replace some or all of the technical features; these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the technical solutions of the embodiments of the present invention range.

Claims (125)

  1. 一种日志处理方法,其特征在于,包括:A log processing method, characterized by comprising:
    客户端通过预设的调用接口向服务端发送注册请求;The client sends a registration request to the server through the preset calling interface;
    所述服务端接收客户端发送的注册请求;The server receives the registration request sent by the client;
    所述服务端根据所述注册请求为所述客户端申请共享内存;The server applies for shared memory for the client according to the registration request;
    当所述共享内存申请成功后,所述服务端向所述客户端发送注册成功信息;After the shared memory application is successful, the server sends registration success information to the client;
    所述客户端当接收到所述服务端反馈的注册成功信息时,将所述客户端的日志信息写入所述共享内存中;When the client receives the registration success information fed back by the server, writes the log information of the client into the shared memory;
    所述服务端从所述共享内存中获取所述日志信息,并存储至预设的存储路径。The server obtains the log information from the shared memory and stores it in a preset storage path.
  2. 根据权利要求1所述的方法,其特征在于,所述共享内存为无锁队列实例。The method according to claim 1, wherein the shared memory is a lock-free queue instance.
  3. 根据权利要求1所述的方法,其特征在于,所述共享内存为有锁队列实例。The method according to claim 1, wherein the shared memory is a locked queue instance.
  4. 根据权利要求1所述的方法,其特征在于,所述注册请求由所述客户端的其中一个线程发送。The method according to claim 1, wherein the registration request is sent by one of the threads of the client.
  5. 根据权利要求4所述的方法,其特征在于,所述将所述客户端的日志信息写入所述共享内存中,包括:The method according to claim 4, wherein the writing the log information of the client into the shared memory comprises:
    将所述客户端中每一线程的日志按照预定的线程存储顺序写入所述共享内存中。The log of each thread in the client is written into the shared memory according to a predetermined thread storage sequence.
  6. 根据权利要求1-5任一项所述的方法,其特征在于,所述将所述客户端的日志信息写入所述共享内存中,包括:The method according to any one of claims 1-5, wherein the writing the log information of the client into the shared memory comprises:
    将优先级高于预设的第一打印级别的日志信息存入所述共享内存中。Store log information with a priority higher than the preset first printing level in the shared memory.
  7. 根据权利要求1-5任一项所述的方法,其特征在于,所述日志信息的打印级别包括优先级由高到低依次排列的OFF级别、FATAL级别、ERROR级别、WARN级别、INFO级别、DEBUG级别、TRACE级别和ALL级别。The method according to any one of claims 1-5, wherein the printing level of the log information includes OFF level, FATAL level, ERROR level, WARN level, INFO level, DEBUG level, TRACE level and ALL level.
  8. 根据权利要求1-5任一项所述的方法,其特征在于,所述将所述客户端的日志信息写入所述共享内存中包括:The method according to any one of claims 1-5, wherein the writing the log information of the client into the shared memory comprises:
    所述客户端以异步存储的方式将所述客户端的日志信息写入所述共 享内存中。The client writes the log information of the client into the shared memory in an asynchronous storage manner.
  9. 根据权利要求1所述的方法,其特征在于,所述通过所述客户端预设的调用接口向服务端发送注册请求之前,还包括:The method according to claim 1, wherein before the sending a registration request to the server through the calling interface preset by the client, the method further comprises:
    所述客户端根据预设的日志写入配置生成所述注册请求。The client generates the registration request according to a preset log writing configuration.
  10. 根据权利要求9所述的方法,其特征在于,所述日志写入配置包括待占用内存大小、存储模式、存储位置、存储的子文件夹划分和存储的子文件夹大小中的至少一种。The method according to claim 9, wherein the log writing configuration includes at least one of a memory size to be occupied, a storage mode, a storage location, a storage subfolder division, and a storage subfolder size.
  11. 根据权利要求1-5、9-10任一项所述的方法,其特征在于,所述当接收到所述服务端反馈的注册成功信息时,将所述客户端的日志信息写入所述共享内存中之后,还包括:The method according to any one of claims 1-5 and 9-10, wherein when the registration success information fed back by the server is received, the log information of the client is written into the shared After in memory, it also includes:
    所述客户端获取所述共享内存的连接数;Acquiring, by the client, the number of connections of the shared memory;
    所述客户端根据所述连接数确定所述服务端与所述共享内存是否断开连接。The client determines whether the server is disconnected from the shared memory according to the number of connections.
  12. 根据权利要求11所述的方法,其特征在于,所述根据所述连接数确定所述服务端与所述共享内存是否断开连接,包括:The method according to claim 11, wherein the determining whether the server is disconnected from the shared memory according to the number of connections comprises:
    若所述客户端与所述共享内存保持连接,且所述连接数小于预设的连接总量时,则判定所述服务端与所述共享内存断开连接;其中,所述连接总量为正常日志存储状态下所述共享内存的连接数;If the client remains connected to the shared memory, and the number of connections is less than the preset total number of connections, it is determined that the server is disconnected from the shared memory; wherein, the total number of connections is The number of connections to the shared memory in the normal log storage state;
    若所述客户端与所述共享内存保持连接,且所述连接数不小于预设的连接总量,则判定所述服务端与所述共享内存未断开连接。If the client remains connected to the shared memory and the number of connections is not less than the preset total number of connections, it is determined that the server is not disconnected from the shared memory.
  13. 根据权利要求12所述的方法,其特征在于,所述方法还包括:The method of claim 12, wherein the method further comprises:
    当判定所述服务端断开连接时,按照预设的频率向所述服务端发送重新连接请求;When it is determined that the server is disconnected, send a reconnection request to the server according to a preset frequency;
    当所述服务端接收到所述客户端发送的重新连接请求,所述服务端根据所述重新连接请求重新与所述共享内存连接。When the server receives the reconnection request sent by the client, the server reconnects to the shared memory according to the reconnection request.
  14. 根据权利要求13所述的方法,其特征在于,所述注册成功信息包括所述服务端给所述客户端分配的识别码;所述重新连接请求包括所述识别码;所述服务端根据所述重新连接请求重新与所述共享内存连接,包括:The method according to claim 13, wherein the registration success information includes an identification code assigned by the server to the client; the reconnection request includes the identification code; The reconnection request to reconnect with the shared memory includes:
    所述服务端根据所述重新连接请求中的识别码连接至所述共享内存。The server connects to the shared memory according to the identification code in the reconnection request.
  15. 根据权利要求1所述的方法,其特征在于,所述服务端从所述共享内存中获取所述日志信息,并存储至预设的存储路径,包括:The method according to claim 1, wherein the server obtains the log information from the shared memory and stores it in a preset storage path, comprising:
    所述服务端从所述共享内存中获取优先级高于预设的第二打印级别的日志信息,并存储至预设的存储路径。The server obtains log information with a priority higher than a preset second printing level from the shared memory, and stores it in a preset storage path.
  16. 根据权利要求15所述的方法,其特征在于,所述日志信息的打印级别包括优先级由高到低依次排列的OFF级别、FATAL级别、ERROR级别、WARN级别、INFO级别、DEBUG级别、TRACE级别和ALL级别。The method according to claim 15, wherein the printing level of the log information includes OFF level, FATAL level, ERROR level, WARN level, INFO level, DEBUG level, TRACE level in descending order of priority. And ALL level.
  17. 根据权利要求15或16所述的方法,其特征在于,所述服务端从所述共享内存中获取所述日志信息,并存储至预设的存储路径,包括:The method according to claim 15 or 16, wherein the server obtains the log information from the shared memory and stores it in a preset storage path, comprising:
    所述服务端以单线程的方式从所述共享内存中获取所述日志信息并存储至预设的存储路径中。The server obtains the log information from the shared memory in a single-threaded manner and stores it in a preset storage path.
  18. 根据权利要求15或16所述的方法,其特征在于,所述注册请求中包括待占用内存量,所述根据所述注册请求为所述客户端申请共享内存,包括:The method according to claim 15 or 16, wherein the registration request includes an amount of memory to be occupied, and the application for shared memory for the client according to the registration request includes:
    确定所述服务端当前内存剩余量;Determine the current remaining amount of memory on the server;
    所述服务端根据所述内存剩余量以及所述待占用内存量为所述客户端申请共享内存。The server applies for shared memory for the client according to the remaining amount of memory and the amount of memory to be occupied.
  19. 根据权利要求18所述的方法,其特征在于,所述根据所述内存剩余量以及所述待占用内存量为所述客户端申请共享内存,包括:The method according to claim 18, wherein the applying for shared memory for the client according to the remaining amount of memory and the amount of memory to be occupied comprises:
    若所述待占用内存量小于所述内存剩余量,则为所述客户端申请与所述待占用内存量对应的共享内存;If the amount of memory to be occupied is less than the remaining amount of memory, apply for a shared memory corresponding to the amount of memory to be occupied for the client;
    若所述待占用内存量不小于所述内存剩余量,则拒绝为所述客户端申请共享内存。If the amount of memory to be occupied is not less than the remaining amount of memory, refuse to apply for shared memory for the client.
  20. 根据权利要求15-16、19任一项所述的方法,其特征在于,所述注册请求还包括所述客户端的进程标识;The method according to any one of claims 15-16, 19, wherein the registration request further includes the process identifier of the client;
    相应地,所述根据所述注册请求为所述客户端申请共享内存,包括:Correspondingly, the applying for shared memory for the client according to the registration request includes:
    判断预设的进程黑名单中是否包括所述进程标识;Determine whether the process identifier is included in the preset process blacklist;
    若不存在,则为所述客户端申请共享内存;If it does not exist, apply for shared memory for the client;
    若存在,则拒绝为所述客户端申请共享内存。If it exists, refuse to apply for shared memory for the client.
  21. 根据权利要求15-16、19任一项所述的方法,其特征在于,所述 注册请求是根据预设的日志写入配置生成的;The method according to any one of claims 15-16, 19, wherein the registration request is generated according to a preset log writing configuration;
    所述根据所述注册请求为所述客户端申请共享内存,包括:The applying for shared memory for the client according to the registration request includes:
    所述服务端根据所述日志写入配置为所述客户端申请共享内存。The server applies for shared memory for the client according to the log writing configuration.
  22. 根据权利要求21所述的方法,其特征在于,所述日志写入配置包括待占用内存大小、存储模式、存储位置、存储的子文件夹划分和存储的子文件夹大小中的至少一种。The method according to claim 21, wherein the log writing configuration includes at least one of a size of a memory to be occupied, a storage mode, a storage location, a storage subfolder division, and a storage subfolder size.
  23. 根据权利要求15-16、19、22任一项所述的方法,其特征在于,所述根据所述注册请求为所述客户端申请共享内存之后,还包括:The method according to any one of claims 15-16, 19, and 22, wherein after applying for shared memory for the client according to the registration request, the method further comprises:
    所述服务端对所述共享内存进行初始化操作,获得无锁队列实例。The server performs an initialization operation on the shared memory to obtain a lock-free queue instance.
  24. 根据权利要求15-16、19、22任一项所述的方法,其特征在于,所述根据所述注册请求为所述客户端申请共享内存之后,还包括:The method according to any one of claims 15-16, 19, and 22, wherein after applying for shared memory for the client according to the registration request, the method further comprises:
    所述服务端对所述共享内存进行初始化操作,获得有锁队列实例。The server performs an initialization operation on the shared memory to obtain a locked queue instance.
  25. 根据权利要求15-16、19、22任一项所述的方法,其特征在于,所述服务端向所述客户端发送注册成功信息之后,还包括:The method according to any one of claims 15-16, 19, 22, wherein after the server sends registration success information to the client, the method further comprises:
    所述服务端对所述共享内存中的日志写入状况进行监控,根据监控结果对所述客户端进行管控。The server monitors the log writing status in the shared memory, and manages the client according to the monitoring result.
  26. 根据权利要求25所述的方法,其特征在于,所述服务端对所述共享内存中的日志写入状况进行监控,根据监控结果对所述客户端进行管控,包括:The method according to claim 25, wherein the server monitoring the log writing status in the shared memory, and managing and controlling the client according to the monitoring result, comprises:
    所述服务端判断所述客户端写入日志的速度是否超过预设的速度阈值;The server determines whether the speed at which the client writes the log exceeds a preset speed threshold;
    若是,则判定所述客户端出现故障。If yes, it is determined that the client is faulty.
  27. 根据权利要求25所述的方法,其特征在于,所述服务端对所述共享内存中的日志写入状况进行监控,根据监控结果对所述客户端进行管控,包括:The method according to claim 25, wherein the server monitoring the log writing status in the shared memory, and managing and controlling the client according to the monitoring result, comprises:
    所述服务端判断所述客户端写入日志的数量是否超过预设的数量阈值;The server determines whether the number of logs written by the client exceeds a preset number threshold;
    若是,则判定所述客户端出现故障。If yes, it is determined that the client is faulty.
  28. 根据权利要求26或27所述的方法,其特征在于,所述判定所述客户端出现故障之后,还包括:The method according to claim 26 or 27, wherein after determining that the client has a fault, the method further comprises:
    所述服务端根据所述客户端的进程标识确定所述客户端对应的权限信息;Determining, by the server, the authority information corresponding to the client according to the process identifier of the client;
    所述服务端根据所述权限信息对所述客户端写入的日志信息进行管控。The server manages and controls the log information written by the client according to the authority information.
  29. 根据权利要求1所述的方法,其特征在于,所述方法包括:The method according to claim 1, wherein the method comprises:
    所述服务端从所述共享内存中获取所述日志信息,对所述日志信息进行发布处理。The server obtains the log information from the shared memory, and publishes the log information.
  30. 一种日志处理方法,应用于客户端,其特征在于,所述方法包括:A log processing method applied to a client terminal, characterized in that the method includes:
    通过预设的调用接口向服务端发送注册请求Send a registration request to the server through the preset calling interface
    当接收到所述服务端反馈的注册成功信息时,将所述客户端的日志信息写入所述客户端和所述服务端的共享内存中。When the registration success information fed back by the server is received, the log information of the client is written into the shared memory of the client and the server.
  31. 根据权利要求30所述的方法,其特征在于,所述共享内存为无锁队列实例。The method of claim 30, wherein the shared memory is a lock-free queue instance.
  32. 根据权利要求30所述的方法,其特征在于,所述共享内存为有锁队列实例。The method of claim 30, wherein the shared memory is a locked queue instance.
  33. 根据权利要求30所述的方法,其特征在于,所述注册请求由所述客户端的其中一个线程发送。The method according to claim 30, wherein the registration request is sent by one of the threads of the client.
  34. 根据权利要求33所述的方法,其特征在于,所述将所述客户端的日志信息写入所述共享内存中,包括:The method according to claim 33, wherein the writing the log information of the client into the shared memory comprises:
    将所述客户端中每一线程的日志按照预定的线程存储顺序写入所述共享内存中。The log of each thread in the client is written into the shared memory according to a predetermined thread storage sequence.
  35. 根据权利要求30-34任一项所述的方法,其特征在于,所述将所述客户端的日志信息写入所述共享内存中,包括:The method according to any one of claims 30-34, wherein the writing the log information of the client into the shared memory comprises:
    将优先级高于预设的第一打印级别的日志信息存入所述共享内存中。Store log information with a priority higher than the preset first printing level in the shared memory.
  36. 根据权利要求30-34任一项所述的方法,其特征在于,所述日志信息的打印级别包括优先级由高到低依次排列的OFF级别、FATAL级别、ERROR级别、WARN级别、INFO级别、DEBUG级别、TRACE级别和ALL级别。The method according to any one of claims 30-34, wherein the printing level of the log information includes OFF level, FATAL level, ERROR level, WARN level, INFO level, DEBUG level, TRACE level and ALL level.
  37. 根据权利要求30-34任一项所述的方法,其特征在于,所述将所述客户端的日志信息写入所述共享内存中包括:The method according to any one of claims 30-34, wherein the writing the log information of the client into the shared memory comprises:
    以异步存储的方式将所述客户端的日志信息写入所述共享内存中。The log information of the client is written into the shared memory in an asynchronous storage manner.
  38. 根据权利要求30所述的方法,其特征在于,所述注册信息中还包括发送所述注册请求的进程的进程标识。The method according to claim 30, wherein the registration information further includes the process identifier of the process that sent the registration request.
  39. 根据权利要求30所述的方法,其特征在于,所述通过所述客户端预设的调用接口向服务端发送注册请求之前,还包括:The method according to claim 30, wherein before sending a registration request to the server through the calling interface preset by the client, the method further comprises:
    根据预设的日志写入配置生成所述注册请求。The registration request is generated according to the preset log writing configuration.
  40. 根据权利要求39所述的方法,其特征在于,所述日志写入配置包括待占用内存大小、存储模式、存储位置、存储的子文件夹划分和存储的子文件夹大小中的至少一种。The method according to claim 39, wherein the log writing configuration includes at least one of a size of a memory to be occupied, a storage mode, a storage location, a storage subfolder division, and a storage subfolder size.
  41. 根据权利要求30-34、38-39任一项所述的方法,其特征在于,所述当接收到所述服务端反馈的注册成功信息时,将所述客户端的日志信息写入所述共享内存中之后,还包括:The method according to any one of claims 30-34 and 38-39, wherein when the registration success information fed back by the server is received, the log information of the client is written into the shared After in memory, it also includes:
    获取所述共享内存的连接数;Acquiring the number of connections of the shared memory;
    根据所述连接数确定所述服务端与所述共享内存是否断开连接。Determine whether the server is disconnected from the shared memory according to the number of connections.
  42. 根据权利要求41所述的方法,其特征在于,所述根据所述连接数确定所述服务端与所述共享内存是否断开连接,包括:The method of claim 41, wherein the determining whether the server is disconnected from the shared memory according to the number of connections comprises:
    若所述客户端与所述共享内存保持连接,且所述连接数小于预设的连接总量时,则判定所述服务端与所述共享内存断开连接;其中,所述连接总量为正常日志存储状态下所述共享内存的连接数;If the client remains connected to the shared memory, and the number of connections is less than the preset total number of connections, it is determined that the server is disconnected from the shared memory; wherein, the total number of connections is The number of connections to the shared memory in the normal log storage state;
    若所述客户端与所述共享内存保持连接,且所述连接数不小于预设的连接总量,则判定所述服务端与所述共享内存未断开连接。If the client remains connected to the shared memory and the number of connections is not less than the preset total number of connections, it is determined that the server is not disconnected from the shared memory.
  43. 根据权利要求42所述的方法,其特征在于,所述方法还包括:The method according to claim 42, wherein the method further comprises:
    当判定所述服务端断开连接时,按照预设的频率向所述服务端发送重新连接请求。When it is determined that the server is disconnected, a reconnection request is sent to the server at a preset frequency.
  44. 根据权利要求43所述的方法,其特征在于,所述注册成功信息包括所述服务端给所述客户端分配的识别码;所述重新连接请求包括所述识别码;所述识别码用于使得所述服务端能够根据所述重新连接请求中的识别码连接至所述共享内存。The method according to claim 43, wherein the registration success information includes an identification code assigned by the server to the client; the reconnection request includes the identification code; and the identification code is used for The server can be connected to the shared memory according to the identification code in the reconnection request.
  45. 一种日志处理方法,应用于服务端,其特征在于,所述方法包括:A log processing method applied to a server, wherein the method includes:
    接收客户端发送的注册请求;Receive the registration request sent by the client;
    根据所述注册请求为所述客户端申请共享内存;Apply for shared memory for the client according to the registration request;
    当所述共享内存申请成功后,向所述客户端发送注册成功信息;After the shared memory application is successful, send registration success information to the client;
    从所述客户端和服务端的共享内存中获取所述客户端的日志信息,并存储至预设的存储路径。Obtain the log information of the client from the shared memory of the client and the server, and store it in a preset storage path.
  46. 根据权利要求45所述的方法,其特征在于,所述从所述共享内存中获取所述日志信息,并存储至预设的存储路径,包括:The method of claim 45, wherein the obtaining the log information from the shared memory and storing it in a preset storage path comprises:
    从所述共享内存中获取优先级高于预设的第二打印级别的日志信息,并存储至预设的存储路径。Obtain log information with a priority higher than the preset second printing level from the shared memory, and store it in a preset storage path.
  47. 根据权利要求46所述的方法,其特征在于,所述日志信息的打印级别包括优先级由高到低依次排列的OFF级别、FATAL级别、ERROR级别、WARN级别、INFO级别、DEBUG级别、TRACE级别和ALL级别。The method according to claim 46, wherein the printing level of the log information includes OFF level, FATAL level, ERROR level, WARN level, INFO level, DEBUG level, and TRACE level in descending order of priority. And ALL level.
  48. 根据权利要求45-47任一项所述的方法,其特征在于,所述服务端从所述共享内存中获取所述日志信息并存储至预设的存储路径中,包括:The method according to any one of claims 45-47, wherein the server acquiring the log information from the shared memory and storing it in a preset storage path comprises:
    所述服务端以单线程的方式从所述共享内存中获取所述日志信息并存储至预设的存储路径中。The server obtains the log information from the shared memory in a single-threaded manner and stores it in a preset storage path.
  49. 根据权利要求45-47任一项所述的方法,其特征在于,所述注册请求中包括待占用内存量,所述根据所述注册请求为所述客户端申请共享内存,包括:The method according to any one of claims 45-47, wherein the registration request includes an amount of memory to be occupied, and the application for shared memory for the client according to the registration request comprises:
    确定所述服务端当前内存剩余量;Determine the current remaining amount of memory on the server;
    根据所述内存剩余量以及所述待占用内存量为所述客户端申请共享内存。Apply for shared memory for the client according to the remaining amount of memory and the amount of memory to be occupied.
  50. 根据权利要求49所述的方法,其特征在于,所述根据所述内存剩余量以及所述待占用内存量为所述客户端申请共享内存,包括:The method according to claim 49, wherein the applying for shared memory for the client according to the remaining amount of memory and the amount of memory to be occupied comprises:
    若所述待占用内存量小于所述内存剩余量,则为所述客户端申请与所述待占用内存量对应的共享内存;If the amount of memory to be occupied is less than the remaining amount of memory, apply for a shared memory corresponding to the amount of memory to be occupied for the client;
    若所述待占用内存量不小于所述内存剩余量,则拒绝为所述客户端申请共享内存。If the amount of memory to be occupied is not less than the remaining amount of memory, refuse to apply for shared memory for the client.
  51. 根据权利要求45-47、50任一项所述的方法,其特征在于,所述注册请求还包括所述客户端的进程标识;The method according to any one of claims 45-47 and 50, wherein the registration request further includes the process identifier of the client;
    相应地,所述根据所述注册请求为所述客户端申请共享内存,包括:Correspondingly, the applying for shared memory for the client according to the registration request includes:
    判断预设的进程黑名单中是否包括所述进程标识;Determine whether the process identifier is included in the preset process blacklist;
    若不存在,则为所述客户端申请共享内存;If it does not exist, apply for shared memory for the client;
    若存在,则拒绝为所述客户端申请共享内存。If it exists, refuse to apply for shared memory for the client.
  52. 根据权利要求45-47任一项所述的方法,其特征在于,所述注册请求是根据预设的日志写入配置生成的;The method according to any one of claims 45-47, wherein the registration request is generated according to a preset log writing configuration;
    所述根据所述注册请求为所述客户端申请共享内存,包括:The applying for shared memory for the client according to the registration request includes:
    根据所述日志写入配置为所述客户端申请共享内存。Apply for shared memory for the client according to the log writing configuration.
  53. 根据权利要求52所述的方法,其特征在于,所述日志写入配置包括待占用内存大小、存储模式、存储位置、存储的子文件夹划分和存储的子文件夹大小中的至少一种。The method according to claim 52, wherein the log writing configuration includes at least one of a size of a memory to be occupied, a storage mode, a storage location, a storage subfolder division, and a storage subfolder size.
  54. 根据权利要求45-47、50、53任一项所述的方法,其特征在于,所述根据所述注册请求为所述客户端申请共享内存之后,还包括:The method according to any one of claims 45-47, 50, 53, wherein after applying for shared memory for the client according to the registration request, the method further comprises:
    对所述共享内存进行初始化操作,获得无锁队列实例。Perform an initialization operation on the shared memory to obtain a lock-free queue instance.
  55. 根据权利要求45-47、50、53任一项所述的方法,其特征在于,所述根据所述注册请求为所述客户端申请共享内存之后,还包括:The method according to any one of claims 45-47, 50, 53, wherein after applying for shared memory for the client according to the registration request, the method further comprises:
    对所述共享内存进行初始化操作,获得有锁队列实例。Perform an initialization operation on the shared memory to obtain a locked queue instance.
  56. 根据权利要求45-47、50、53任一项所述的方法,其特征在于,所述方法还包括:The method according to any one of claims 45-47, 50, 53, wherein the method further comprises:
    当接收到所述客户端发送的重新连接请求,根据所述重新连接请求重新与所述共享内存连接。When receiving the reconnection request sent by the client, reconnect with the shared memory according to the reconnection request.
  57. 根据权利要求56所述的方法,其特征在于,所述注册成功信息包括所述服务端给所述客户端分配的识别码;所述重新连接请求中包括所述识别码;所述根据所述重新连接请求重新与所述共享内存连接,包括:The method according to claim 56, wherein the registration success information includes an identification code allocated by the server to the client; the reconnection request includes the identification code; The reconnection request to reconnect with the shared memory includes:
    根据所述重新连接请求中的识别码连接至所述共享内存。Connect to the shared memory according to the identification code in the reconnection request.
  58. 根据权利要求45-47、50、53、57任一项所述的方法,其特征在于,所述向所述客户端发送注册成功信息之后,还包括:The method according to any one of claims 45-47, 50, 53, 57, wherein after the sending the registration success information to the client, the method further comprises:
    对所述共享内存中的日志写入状况进行监控,根据监控结果对所述客户端进行管控。The log writing status in the shared memory is monitored, and the client is managed and controlled according to the monitoring result.
  59. 根据权利要求58所述的方法,其特征在于,所述对所述共享内存中的日志写入状况进行监控,根据监控结果对所述客户端进行管控,包括:The method according to claim 58, wherein the monitoring the log writing status in the shared memory and managing and controlling the client according to the monitoring result comprises:
    判断所述客户端写入日志的速度是否超过预设的速度阈值;Determining whether the speed at which the client writes the log exceeds a preset speed threshold;
    若是,则判定所述客户端出现故障。If yes, it is determined that the client is faulty.
  60. 根据权利要求58所述的方法,其特征在于,所述对所述共享内存中的日志写入状况进行监控,根据监控结果对所述客户端进行管控,包括:The method according to claim 58, wherein the monitoring the log writing status in the shared memory and managing and controlling the client according to the monitoring result comprises:
    判断所述客户端写入日志的数量是否超过预设的数量阈值;Judging whether the number of logs written by the client exceeds a preset number threshold;
    若是,则判定所述客户端出现故障。If yes, it is determined that the client is faulty.
  61. 根据权利要求59或60所述的方法,其特征在于,所述判定所述客户端出现故障之后,还包括:The method according to claim 59 or 60, wherein after determining that the client is faulty, the method further comprises:
    根据所述客户端的进程标识确定所述客户端对应的权限信息;Determining the authority information corresponding to the client according to the process identifier of the client;
    根据所述权限信息对所述客户端写入的日志信息进行管控。The log information written by the client is managed and controlled according to the authority information.
  62. 根据权利要求45所述的方法,其特征在于,所述方法还包括:The method of claim 45, wherein the method further comprises:
    从所述共享内存中获取所述日志信息,对所述日志信息进行发布处理。Acquire the log information from the shared memory, and perform publishing processing on the log information.
  63. 一种日志处理系统,其特征在于,包括A log processing system, characterized in that it comprises
    一个或多个处理器;One or more processors;
    一个或多个存储器;One or more memories;
    所述存储器用于存储程序代码;The memory is used to store program codes;
    所述处理器,用于调用所述程序代码,当程序代码被执行时,用于执行以下操作:The processor is used to call the program code, and when the program code is executed, it is used to perform the following operations:
    通过客户端预设的调用接口向服务端发送注册请求;Send a registration request to the server through the call interface preset by the client;
    通过所述服务端接收客户端发送的注册请求;Receiving the registration request sent by the client through the server;
    通过所述服务端根据所述注册请求为所述客户端申请共享内存;Apply for shared memory for the client through the server according to the registration request;
    当所述共享内存申请成功后,通过所述服务端向所述客户端发送注册成功信息;After the shared memory application is successful, send registration success information to the client through the server;
    当接收到所述服务端反馈的注册成功信息时,通过所述客户端将所述客户端的日志信息写入所述共享内存中;When receiving the registration success information fed back by the server, write the log information of the client into the shared memory through the client;
    通过所述服务端从所述共享内存中获取所述日志信息,并存储至预设的存储路径。The log information is obtained from the shared memory through the server and stored in a preset storage path.
  64. 根据权利要求63所述的日志处理系统,其特征在于,所述共享内存为无锁队列实例。The log processing system according to claim 63, wherein the shared memory is a lock-free queue instance.
  65. 根据权利要求63所述的日志处理系统,其特征在于,所述共享内存为有锁队列实例。The log processing system according to claim 63, wherein the shared memory is a locked queue instance.
  66. 根据权利要求63所述的日志处理系统,其特征在于,所述注册请求由所述客户端的其中一个线程发送。The log processing system according to claim 63, wherein the registration request is sent by one of the threads of the client.
  67. 根据权利要求66所述的日志处理系统,其特征在于,所述处理器在通过所述客户端将所述客户端的日志信息写入所述共享内存中时,用于:The log processing system according to claim 66, wherein the processor is configured to: when writing the log information of the client into the shared memory through the client:
    通过所述客户端将所述客户端中每一线程的日志按照预定的线程存储顺序写入所述共享内存中。The log of each thread in the client is written into the shared memory through the client according to a predetermined thread storage sequence.
  68. 根据权利要求63-67任一项所述的日志处理系统,其特征在于,所述处理器在通过所述客户端将所述客户端的日志信息写入所述共享内存中时,用于:The log processing system according to any one of claims 63-67, wherein when the processor writes the log information of the client into the shared memory through the client, the processor is configured to:
    通过所述客户端将优先级高于预设的第一打印级别的日志信息存入所述共享内存中。The log information whose priority is higher than the preset first printing level is stored in the shared memory through the client.
  69. 根据权利要求63-67任一项所述的日志处理系统,其特征在于,所述日志信息的打印级别包括优先级由高到低依次排列的OFF级别、FATAL级别、ERROR级别、WARN级别、INFO级别、DEBUG级别、TRACE级别和ALL级别。The log processing system according to any one of claims 63-67, wherein the printing level of the log information includes OFF level, FATAL level, ERROR level, WARN level, INFO, which are arranged in descending order of priority. Level, DEBUG level, TRACE level and ALL level.
  70. 根据权利要求63-67任一项所述的日志处理系统,其特征在于,所述处理器在通过所述客户端将所述客户端的日志信息写入所述共享内存中时,用于:The log processing system according to any one of claims 63-67, wherein when the processor writes the log information of the client into the shared memory through the client, the processor is configured to:
    通过所述客户端以异步存储的方式将所述客户端的日志信息写入所述共享内存中。The log information of the client is written into the shared memory through the client in an asynchronous storage manner.
  71. 根据权利要求63所述的日志处理系统,其特征在于,所述处理器在通过所述客户端预设的调用接口向服务端发送注册请求之前,还用于:The log processing system according to claim 63, wherein the processor is further configured to: before sending a registration request to the server through the calling interface preset by the client,
    通过所述客户端根据预设的日志写入配置生成所述注册请求。The registration request is generated by the client according to a preset log writing configuration.
  72. 根据权利要求71所述的日志处理系统,其特征在于,所述日志写入配置包括待占用内存大小、存储模式、存储位置、存储的子文件夹划分和存储的子文件夹大小中的至少一种。The log processing system according to claim 71, wherein the log writing configuration includes at least one of a memory size to be occupied, a storage mode, a storage location, a storage subfolder division, and a storage subfolder size. Kind.
  73. 根据权利要求63-67、71-72任一项所述的日志处理系统,其特 征在于,所述处理器在当接收到所述服务端反馈的注册成功信息时,通过所述客户端将所述客户端的日志信息写入所述共享内存中之后,还用于:The log processing system according to any one of claims 63-67 and 71-72, wherein, when the processor receives the registration success information fed back by the server, the processor transmits all information through the client After the log information of the client is written into the shared memory, it is also used to:
    通过所述客户端获取所述共享内存的连接数;Acquiring the number of connections of the shared memory through the client;
    通过所述客户端根据所述连接数确定所述服务端与所述共享内存是否断开连接。The client determines whether the server is disconnected from the shared memory according to the number of connections.
  74. 根据权利要求73所述的日志处理系统,其特征在于,所述处理器在通过所述客户端根据所述连接数确定所述服务端与所述共享内存是否断开连接时,用于:The log processing system according to claim 73, wherein the processor is configured to: when the client determines whether the server is disconnected from the shared memory according to the number of connections through the client:
    若所述客户端与所述共享内存保持连接,且所述连接数小于预设的连接总量时,则通过所述客户端判定所述服务端与所述共享内存断开连接;其中,所述连接总量为正常日志存储状态下所述共享内存的连接数;If the client remains connected to the shared memory, and the number of connections is less than the preset total number of connections, the client determines that the server is disconnected from the shared memory; wherein, The total number of connections is the number of connections of the shared memory in the normal log storage state;
    若所述客户端与所述共享内存保持连接,且所述连接数不小于预设的连接总量,则通过所述客户端判定所述服务端与所述共享内存未断开连接。If the client maintains a connection with the shared memory, and the number of connections is not less than a preset total number of connections, it is determined by the client that the server is not disconnected from the shared memory.
  75. 根据权利要求74所述的日志处理系统,其特征在于,所述处理器还用于:The log processing system according to claim 74, wherein the processor is further configured to:
    当判定所述服务端断开连接时,通过所述客户端按照预设的频率向所述服务端发送重新连接请求;When it is determined that the server is disconnected, sending a reconnection request to the server through the client according to a preset frequency;
    当所述服务端接收到所述客户端发送的重新连接请求,通过所述服务端根据所述重新连接请求重新与所述共享内存连接。When the server receives the reconnection request sent by the client, the server reconnects to the shared memory according to the reconnection request.
  76. 根据权利要求75所述的日志处理系统,其特征在于,所述注册成功信息包括所述服务端给所述客户端分配的识别码;所述重新连接请求包括所述识别码;所述处理器在通过所述服务端根据所述重新连接请求重新与所述共享内存连接时,用于:The log processing system according to claim 75, wherein the registration success information includes an identification code assigned by the server to the client; the reconnection request includes the identification code; and the processor When reconnecting to the shared memory through the server according to the reconnection request, it is used to:
    通过所述服务端根据所述重新连接请求中的识别码连接至所述共享内存。Connect to the shared memory through the server according to the identification code in the reconnection request.
  77. 根据权利要求63所述的日志处理系统,其特征在于,所述处理器在通过所述服务端从所述共享内存中获取所述日志信息,并存储至预设的存储路径时,用于:The log processing system according to claim 63, wherein when the processor obtains the log information from the shared memory through the server and stores it in a preset storage path, it is configured to:
    通过所述服务端从所述共享内存中获取优先级高于预设的第二打印级别的日志信息,并存储至预设的存储路径。Obtain log information with a priority higher than a preset second printing level from the shared memory through the server, and store it in a preset storage path.
  78. 根据权利要求77所述的日志处理系统,其特征在于,所述日志信息的打印级别包括优先级由高到低依次排列的OFF级别、FATAL级别、ERROR级别、WARN级别、INFO级别、DEBUG级别、TRACE级别和ALL级别。The log processing system according to claim 77, wherein the printing level of the log information includes OFF level, FATAL level, ERROR level, WARN level, INFO level, DEBUG level, TRACE level and ALL level.
  79. 根据权利要求77或78所述的日志处理系统,其特征在于,所述处理器在通过所述服务端从所述共享内存中获取所述日志信息,并存储至预设的存储路径时,用于:The log processing system according to claim 77 or 78, wherein when the processor obtains the log information from the shared memory through the server and stores it in a preset storage path, it uses in:
    通过所述服务端以单线程的方式从所述共享内存中获取所述日志信息并存储至预设的存储路径中。The log information is obtained from the shared memory in a single-threaded manner through the server and stored in a preset storage path.
  80. 根据权利要求77或78所述的日志处理系统,其特征在于,所述注册请求中包括待占用内存量,所述处理器在通过所述服务端根据所述注册请求为所述客户端申请共享内存时,用于:The log processing system according to claim 77 or 78, wherein the registration request includes an amount of memory to be occupied, and the processor applies for sharing for the client according to the registration request through the server. When the memory is used:
    确定所述服务端当前内存剩余量;Determine the current remaining amount of memory on the server;
    通过所述服务端根据所述内存剩余量以及所述待占用内存量为所述客户端申请共享内存。The server applies for shared memory for the client according to the remaining amount of memory and the amount of memory to be occupied.
  81. 根据权利要求80所述的日志处理系统,其特征在于,所述处理器在通过所述服务端根据所述内存剩余量以及所述待占用内存量为所述客户端申请共享内存时,用于:The log processing system according to claim 80, wherein the processor is configured to use the server to apply for shared memory for the client according to the remaining amount of memory and the amount of memory to be occupied by the server. :
    若所述待占用内存量小于所述内存剩余量,则为所述客户端申请与所述待占用内存量对应的共享内存;If the amount of memory to be occupied is less than the remaining amount of memory, apply for a shared memory corresponding to the amount of memory to be occupied for the client;
    若所述待占用内存量不小于所述内存剩余量,则拒绝为所述客户端申请共享内存。If the amount of memory to be occupied is not less than the remaining amount of memory, refuse to apply for shared memory for the client.
  82. 根据权利要求77-78、81任一项所述的日志处理系统,其特征在于,所述注册请求还包括所述客户端的进程标识;The log processing system according to any one of claims 77-78 and 81, wherein the registration request further includes a process identifier of the client;
    相应地,所述处理器在通过所述服务端根据所述注册请求为所述客户端申请共享内存时,用于:Correspondingly, when applying for shared memory for the client through the server according to the registration request, the processor is configured to:
    判断预设的进程黑名单中是否包括所述进程标识;Determine whether the process identifier is included in the preset process blacklist;
    若不存在,则为所述客户端申请共享内存;If it does not exist, apply for shared memory for the client;
    若存在,则拒绝为所述客户端申请共享内存。If it exists, refuse to apply for shared memory for the client.
  83. 根据权利要求77-78、81任一项所述的日志处理系统,其特征在于,所述注册请求是根据预设的日志写入配置生成的;The log processing system according to any one of claims 77-78 and 81, wherein the registration request is generated according to a preset log writing configuration;
    所述处理器在通过所述服务端根据所述注册请求为所述客户端申请共享内存时,用于:When the processor applies for shared memory for the client according to the registration request through the server, it is configured to:
    所述服务端根据所述日志写入配置为所述客户端申请共享内存。The server applies for shared memory for the client according to the log writing configuration.
  84. 根据权利要求83所述的日志处理系统,其特征在于,所述日志写入配置包括待占用内存大小、存储模式、存储位置、存储的子文件夹划分和存储的子文件夹大小中的至少一种。The log processing system according to claim 83, wherein the log writing configuration includes at least one of a memory size to be occupied, a storage mode, a storage location, a storage subfolder division, and a storage subfolder size. Kind.
  85. 根据权利要求77-78、81、84任一项所述的日志处理系统,其特征在于,所述处理器在通过所述服务端接收客户端发送的注册请求之后,还包括:The log processing system according to any one of claims 77-78, 81, 84, wherein after the processor receives a registration request sent by the client through the server, the processor further comprises:
    通过所述服务端对所述共享内存进行初始化操作,获得有锁队列实例。The server initializes the shared memory to obtain a locked queue instance.
  86. 根据权利要求77-78、81、84任一项所述的日志处理系统,其特征在于,所述处理器在通过所述服务端接收客户端发送的注册请求之后,还包括:The log processing system according to any one of claims 77-78, 81, 84, wherein after the processor receives a registration request sent by the client through the server, the processor further comprises:
    通过所述服务端对所述共享内存进行初始化操作,获得有锁队列实例。The server initializes the shared memory to obtain a locked queue instance.
  87. 根据权利要求77-78、81、84任一项所述的日志处理系统,其特征在于,所述处理器在通过所述服务端向所述客户端发送注册成功信息之后,还包括:The log processing system according to any one of claims 77-78, 81, 84, wherein after the processor sends registration success information to the client through the server, further comprising:
    通过所述服务端对所述共享内存中的日志写入状况进行监控,根据监控结果对所述客户端进行管控。The log writing status in the shared memory is monitored by the server, and the client is managed and controlled according to the monitoring result.
  88. 根据权利要求87所述的日志处理系统,其特征在于,所述处理器在通过所述服务端对所述共享内存中的日志写入状况进行监控,根据监控结果对所述客户端进行管控时,用于:The log processing system according to claim 87, wherein when the processor monitors the log writing status in the shared memory through the server, and controls the client according to the monitoring result For:
    所述服务端判断所述客户端写入日志的速度是否超过预设的速度阈值;The server determines whether the speed at which the client writes the log exceeds a preset speed threshold;
    若是,则判定所述客户端出现故障。If yes, it is determined that the client is faulty.
  89. 根据权利要求87所述的日志处理系统,其特征在于,所述处理器在通过所述服务端对所述共享内存中的日志写入状况进行监控,根据监控结果对所述客户端进行管控时,用于:The log processing system according to claim 87, wherein when the processor monitors the log writing status in the shared memory through the server, and controls the client according to the monitoring result For:
    所述服务端判断所述客户端写入日志的数量是否超过预设的数量阈值;The server determines whether the number of logs written by the client exceeds a preset number threshold;
    若是,则判定所述客户端出现故障。If yes, it is determined that the client is faulty.
  90. 根据权利要求88或89所述的日志处理系统,其特征在于,所述处理器在判定所述客户端出现故障之后,还用于:The log processing system according to claim 88 or 89, wherein after determining that the client has a fault, the processor is further configured to:
    所述服务端根据所述客户端的进程标识确定所述客户端对应的权限信息;Determining, by the server, the authority information corresponding to the client according to the process identifier of the client;
    所述服务端根据所述权限信息对所述客户端写入的日志信息进行管控。The server manages and controls the log information written by the client according to the authority information.
  91. 根据权利要求63所述的日志处理系统,其特征在于,所述处理器用于:The log processing system according to claim 63, wherein the processor is configured to:
    所述服务端从所述共享内存中获取所述日志信息,对所述日志信息进行发布处理。The server obtains the log information from the shared memory, and publishes the log information.
  92. 一种客户终端设备,其特征在于,所述终端设备包括:A client terminal device, characterized in that, the terminal device includes:
    存储器和处理器;Memory and processor;
    所述存储器用于存储程序代码;The memory is used to store program codes;
    所述处理器,调用所述程序代码,当程序代码被执行时,用于执行以下操作:The processor calls the program code, and when the program code is executed, is used to perform the following operations:
    通过预设的调用接口向服务端发送注册请求Send a registration request to the server through the preset calling interface
    当接收到所述服务端反馈的注册成功信息时,将日志信息写入所述客户端和所述服务端的共享内存中。When the registration success information fed back by the server is received, the log information is written into the shared memory of the client and the server.
  93. 根据权利要求92所述的终端设备,其特征在于,所述共享内存为无锁队列实例。The terminal device according to claim 92, wherein the shared memory is a lock-free queue instance.
  94. 根据权利要求92所述的终端设备,其特征在于,所述共享内存为有锁队列实例。The terminal device of claim 92, wherein the shared memory is a locked queue instance.
  95. 根据权利要求92所述的终端设备,其特征在于,所述注册请求由所述客户端的其中一个线程发送。The terminal device according to claim 92, wherein the registration request is sent by one of the threads of the client.
  96. 根据权利要求95所述的终端设备,其特征在于,所述处理器在将所述客户端的日志信息写入所述共享内存中时,用于:The terminal device of claim 95, wherein the processor is configured to: when writing log information of the client into the shared memory:
    将所述客户端中每一线程的日志按照预定的线程存储顺序写入所述共享内存中。The log of each thread in the client is written into the shared memory according to a predetermined thread storage sequence.
  97. 根据权利要求92-96任一项所述的终端设备,其特征在于,所述 处理器在将所述客户端的日志信息写入所述共享内存中时,用于:The terminal device according to any one of claims 92-96, wherein the processor is configured to: when writing log information of the client into the shared memory:
    将优先级高于预设的第一打印级别的日志信息存入所述共享内存中。Store log information with a priority higher than the preset first printing level in the shared memory.
  98. 根据权利要求92-96任一项所述的终端设备,其特征在于,所述日志信息的打印级别包括优先级由高到低依次排列的OFF级别、FATAL级别、ERROR级别、WARN级别、INFO级别、DEBUG级别、TRACE级别和ALL级别。The terminal device according to any one of claims 92-96, wherein the printing level of the log information includes OFF level, FATAL level, ERROR level, WARN level, and INFO level in descending order of priority. , DEBUG level, TRACE level and ALL level.
  99. 根据权利要求92-96任一项所述的终端设备,其特征在于,所述处理器在将所述客户端的日志信息写入所述共享内存中时,用于:The terminal device according to any one of claims 92-96, wherein the processor is configured to: when writing log information of the client into the shared memory:
    以异步存储的方式将所述客户端的日志信息写入所述共享内存中。The log information of the client is written into the shared memory in an asynchronous storage manner.
  100. 根据权利要求92所述的终端设备,其特征在于,所述注册信息中还包括发送所述注册请求的进程的进程标识。The terminal device according to claim 92, wherein the registration information further includes a process identifier of the process that sent the registration request.
  101. 根据权利要求92所述的终端设备,其特征在于,所述处理器在通过所述客户端预设的调用接口向服务端发送注册请求之前,还用于:The terminal device according to claim 92, wherein the processor is further configured to: before sending a registration request to the server through the calling interface preset by the client terminal:
    根据预设的日志写入配置生成所述注册请求。The registration request is generated according to the preset log writing configuration.
  102. 根据权利要求101所述的终端设备,其特征在于,所述日志写入配置包括待占用内存大小、存储模式、存储位置、存储的子文件夹划分和存储的子文件夹大小中的至少一种。The terminal device according to claim 101, wherein the log writing configuration includes at least one of a memory size to be occupied, a storage mode, a storage location, a storage subfolder division, and a storage subfolder size .
  103. 根据权利要求92-96、100-101任一项所述的终端设备,其特征在于,所述处理器在当接收到所述服务端反馈的注册成功信息时,将所述客户端的日志信息写入所述共享内存中之后,还用于:The terminal device according to any one of claims 92-96 and 100-101, wherein the processor writes the log information of the client when receiving the registration success information fed back by the server After being stored in the shared memory, it is also used for:
    获取所述共享内存的连接数;Acquiring the number of connections of the shared memory;
    根据所述连接数确定所述服务端与所述共享内存是否断开连接。Determine whether the server is disconnected from the shared memory according to the number of connections.
  104. 根据权利要求103所述的终端设备,其特征在于,所述处理器在根据所述连接数确定所述服务端与所述共享内存是否断开连接时,用于:The terminal device according to claim 103, wherein the processor is configured to: when determining whether the server is disconnected from the shared memory according to the number of connections:
    若所述客户端与所述共享内存保持连接,且所述连接数小于预设的连接总量时,则判定所述服务端与所述共享内存断开连接;其中,所述连接总量为正常日志存储状态下所述共享内存的连接数;If the client remains connected to the shared memory, and the number of connections is less than the preset total number of connections, it is determined that the server is disconnected from the shared memory; wherein, the total number of connections is The number of connections to the shared memory in the normal log storage state;
    若所述客户端与所述共享内存保持连接,且所述连接数不小于预设的连接总量,则判定所述服务端与所述共享内存未断开连接。If the client remains connected to the shared memory and the number of connections is not less than the preset total number of connections, it is determined that the server is not disconnected from the shared memory.
  105. 根据权利要求104所述的终端设备,其特征在于,所述处理器 还用于:The terminal device according to claim 104, wherein the processor is further configured to:
    当判定所述服务端断开连接时,按照预设的频率向所述服务端发送重新连接请求。When it is determined that the server is disconnected, a reconnection request is sent to the server at a preset frequency.
  106. 根据权利要求105所述的终端设备,其特征在于,所述注册成功信息包括所述服务端给所述客户端分配的识别码;所述重新连接请求包括所述识别码;所述识别码用于使得所述服务端能够根据所述重新连接请求中的识别码连接至所述共享内存。The terminal device according to claim 105, wherein the registration success information includes an identification code allocated by the server to the client; the reconnection request includes the identification code; Therefore, the server can connect to the shared memory according to the identification code in the reconnection request.
  107. 一种服务终端设备,其特征在于,所述服务终端设备包括:存储器和处理器;A service terminal device, characterized in that, the service terminal device includes: a memory and a processor;
    所述存储器用于存储程序代码;The memory is used to store program codes;
    所述处理器,调用所述程序代码,当程序代码被执行时,用于执行以下操作:The processor calls the program code, and when the program code is executed, is used to perform the following operations:
    接收客户端发送的注册请求;Receive the registration request sent by the client;
    根据所述注册请求为所述客户端申请共享内存;Apply for shared memory for the client according to the registration request;
    当所述共享内存申请成功后,向所述客户端发送注册成功信息;After the shared memory application is successful, send registration success information to the client;
    从所述共享内存中获取所述客户端的日志信息,并存储至预设的存储路径。Obtain the log information of the client from the shared memory and store it in a preset storage path.
  108. 根据权利要求107所述的服务终端设备,其特征在于,所述处理器在从所述共享内存中获取所述日志信息,并存储至预设的存储路径时,用于:The service terminal device according to claim 107, wherein when the processor obtains the log information from the shared memory and stores it in a preset storage path, it is configured to:
    从所述共享内存中获取优先级高于预设的第二打印级别的日志信息,并存储至预设的存储路径。Obtain log information with a priority higher than the preset second printing level from the shared memory, and store it in a preset storage path.
  109. 根据权利要求108所述的服务终端设备,其特征在于,所述日志信息的打印级别包括优先级由高到低依次排列的OFF级别、FATAL级别、ERROR级别、WARN级别、INFO级别、DEBUG级别、TRACE级别和ALL级别。The service terminal device according to claim 108, wherein the printing level of the log information includes OFF level, FATAL level, ERROR level, WARN level, INFO level, DEBUG level, TRACE level and ALL level.
  110. 根据权利要求107-109任一项所述的服务终端设备,其特征在于,所述处理器在从所述共享内存中获取所述日志信息并存储至预设的存储路径中时,用于:The service terminal device according to any one of claims 107-109, wherein when the processor obtains the log information from the shared memory and stores it in a preset storage path, it is configured to:
    所述服务端以单线程的方式从所述共享内存中获取所述日志信息并存储至预设的存储路径中。The server obtains the log information from the shared memory in a single-threaded manner and stores it in a preset storage path.
  111. 根据权利要求107-109任一项所述的服务终端设备,其特征在于,所述注册请求中包括待占用内存量,所述处理器在根据所述注册请求为所述客户端申请共享内存时,用于:The service terminal device according to any one of claims 107-109, wherein the registration request includes an amount of memory to be occupied, and when the processor applies for shared memory for the client according to the registration request For:
    确定所述服务端当前内存剩余量;Determine the current remaining amount of memory on the server;
    根据所述内存剩余量以及所述待占用内存量为所述客户端申请共享内存。Apply for shared memory for the client according to the remaining amount of memory and the amount of memory to be occupied.
  112. 根据权利要求111所述的服务终端设备,其特征在于,所述处理器在根据所述内存剩余量以及所述待占用内存量为所述客户端申请共享内存时,用于:The service terminal device of claim 111, wherein the processor is configured to: when applying for shared memory for the client according to the remaining amount of memory and the amount of memory to be occupied, the processor is configured to:
    若所述待占用内存量小于所述内存剩余量,则为所述客户端申请与所述待占用内存量对应的共享内存;If the amount of memory to be occupied is less than the remaining amount of memory, apply for a shared memory corresponding to the amount of memory to be occupied for the client;
    若所述待占用内存量不小于所述内存剩余量,则拒绝为所述客户端申请共享内存。If the amount of memory to be occupied is not less than the remaining amount of memory, refuse to apply for shared memory for the client.
  113. 根据权利要求107-109、112任一项所述的服务终端设备,其特征在于,所述注册请求还包括所述客户端的进程标识;The service terminal device according to any one of claims 107-109 and 112, wherein the registration request further includes a process identifier of the client;
    相应地,所述处理器在根据所述注册请求为所述客户端申请共享内存时,用于:Correspondingly, when applying for shared memory for the client according to the registration request, the processor is configured to:
    判断预设的进程黑名单中是否包括所述进程标识;Determine whether the process identifier is included in the preset process blacklist;
    若不存在,则为所述客户端申请共享内存;If it does not exist, apply for shared memory for the client;
    若存在,则拒绝为所述客户端申请共享内存。If it exists, refuse to apply for shared memory for the client.
  114. 根据权利要求107-109任一项所述的服务终端设备,其特征在于,所述注册请求是根据预设的日志写入配置生成的;The service terminal device according to any one of claims 107-109, wherein the registration request is generated according to a preset log writing configuration;
    所述处理器在根据所述注册请求为所述客户端申请共享内存时,用于:When applying for shared memory for the client according to the registration request, the processor is configured to:
    根据所述日志写入配置为所述客户端申请共享内存。Apply for shared memory for the client according to the log writing configuration.
  115. 根据权利要求114所述的服务终端设备,其特征在于,所述日志写入配置包括待占用内存大小、存储模式、存储位置、存储的子文件夹划分和存储的子文件夹大小中的至少一种。The service terminal device according to claim 114, wherein the log writing configuration includes at least one of a memory size to be occupied, a storage mode, a storage location, a storage subfolder division, and a storage subfolder size Kind.
  116. 根据权利要求107-109、112、115任一项所述的服务终端设备,其特征在于,所述处理器在根据所述注册请求为所述客户端申请共享内存之后,还用于:The service terminal device according to any one of claims 107-109, 112, 115, wherein the processor is further configured to: after applying for shared memory for the client according to the registration request,
    对所述共享内存进行初始化操作,获得无锁队列实例。Perform an initialization operation on the shared memory to obtain a lock-free queue instance.
  117. 根据权利要求107-109、112、115任一项所述的服务终端设备,其特征在于,所述处理器在根据所述注册请求为所述客户端申请共享内存之后,还用于:The service terminal device according to any one of claims 107-109, 112, 115, wherein the processor is further configured to: after applying for shared memory for the client according to the registration request,
    对所述共享内存进行初始化操作,获得有锁队列实例。Perform an initialization operation on the shared memory to obtain a locked queue instance.
  118. 根据权利要求107-109、112、115任一项所述的服务终端设备,其特征在于,所述处理器还用于:The service terminal device according to any one of claims 107-109, 112, 115, wherein the processor is further configured to:
    当接收到所述客户端发送的重新连接请求,根据所述重新连接请求重新与所述共享内存连接。When receiving the reconnection request sent by the client, reconnect with the shared memory according to the reconnection request.
  119. 根据权利要求118所述的服务终端设备,其特征在于,所述注册成功信息包括所述服务端给所述客户端分配的识别码;所述重新连接请求中包括所述识别码;所述处理器在根据所述重新连接请求重新与所述共享内存连接时,用于:The service terminal device of claim 118, wherein the registration success information includes an identification code assigned by the server to the client; the reconnection request includes the identification code; and the processing When reconnecting to the shared memory according to the reconnection request, the device is used to:
    根据所述重新连接请求中的识别码连接至所述共享内存。Connect to the shared memory according to the identification code in the reconnection request.
  120. 根据权利要求107-109、112、115、119任一项所述的服务终端设备,其特征在于,所述处理器在向所述客户端发送注册成功信息之后,还用于:The service terminal device according to any one of claims 107-109, 112, 115, and 119, wherein the processor is further configured to: after sending registration success information to the client terminal:
    对所述共享内存中的日志写入状况进行监控,根据监控结果对所述客户端进行管控。The log writing status in the shared memory is monitored, and the client is managed and controlled according to the monitoring result.
  121. 根据权利要求120所述的服务终端设备,其特征在于,所述处理器在对所述共享内存中的日志写入状况进行监控,根据监控结果对所述客户端进行管控时,用于:The service terminal device of claim 120, wherein the processor is configured to: when monitoring the log writing status in the shared memory, and controlling the client according to the monitoring result:
    判断所述客户端写入日志的速度是否超过预设的速度阈值;Determining whether the speed at which the client writes the log exceeds a preset speed threshold;
    若是,则判定所述客户端出现故障。If yes, it is determined that the client is faulty.
  122. 根据权利要求120所述的服务终端设备,其特征在于,所述处理器在对所述共享内存中的日志写入状况进行监控,根据监控结果对所述客户端进行管控时,用于:The service terminal device of claim 120, wherein the processor is configured to: when monitoring the log writing status in the shared memory, and controlling the client according to the monitoring result:
    判断所述客户端写入日志的数量是否超过预设的数量阈值;Judging whether the number of logs written by the client exceeds a preset number threshold;
    若是,则判定所述客户端出现故障。If yes, it is determined that the client is faulty.
  123. 根据权利要求121或122所述的服务终端设备,其特征在于, 所述处理器在判定所述客户端出现故障之后,还用于:The service terminal device according to claim 121 or 122, wherein, after determining that the client has a fault, the processor is further configured to:
    根据所述客户端的进程标识确定所述客户端对应的权限信息;Determining the authority information corresponding to the client according to the process identifier of the client;
    根据所述权限信息对所述客户端写入的日志信息进行管控。The log information written by the client is managed and controlled according to the authority information.
  124. 根据权利要求107所述的服务终端设备,其特征在于,所述处理器还用于:The service terminal device of claim 107, wherein the processor is further configured to:
    从所述共享内存中获取所述日志信息,对所述日志信息进行发布处理。Acquire the log information from the shared memory, and perform publishing processing on the log information.
  125. 一种计算机可读存储介质,其特征在于,其上存储有计算机程序,所述计算机程序被处理器执行以实现如权利要求1-29或30-44或45-62任一项所述的方法。A computer-readable storage medium, characterized in that a computer program is stored thereon, and the computer program is executed by a processor to implement the method according to any one of claims 1-29 or 30-44 or 45-62 .
PCT/CN2019/091998 2019-06-20 2019-06-20 Log processing method and device, and computer-readable storage medium WO2020252724A1 (en)

Priority Applications (2)

Application Number Priority Date Filing Date Title
PCT/CN2019/091998 WO2020252724A1 (en) 2019-06-20 2019-06-20 Log processing method and device, and computer-readable storage medium
CN201980012096.4A CN111699479A (en) 2019-06-20 2019-06-20 Log processing method, log processing device and computer-readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
PCT/CN2019/091998 WO2020252724A1 (en) 2019-06-20 2019-06-20 Log processing method and device, and computer-readable storage medium

Publications (1)

Publication Number Publication Date
WO2020252724A1 true WO2020252724A1 (en) 2020-12-24

Family

ID=72476455

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2019/091998 WO2020252724A1 (en) 2019-06-20 2019-06-20 Log processing method and device, and computer-readable storage medium

Country Status (2)

Country Link
CN (1) CN111699479A (en)
WO (1) WO2020252724A1 (en)

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112527614A (en) * 2020-12-08 2021-03-19 广东小天才科技有限公司 Intelligent device log quantity early warning system and method
CN113051243A (en) * 2021-03-31 2021-06-29 上海阵量智能科技有限公司 Log processing method, device, system, chip, equipment and storage medium
CN114172946A (en) * 2021-12-06 2022-03-11 京东科技信息技术有限公司 Request result sending method and device, electronic equipment and computer readable medium

Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6219672B1 (en) * 1997-12-11 2001-04-17 Kabushiki Kaisha Toshiba Distributed shared memory system and method of controlling distributed shared memory
US20030172093A1 (en) * 2001-03-26 2003-09-11 Mitsugu Nagoya Server duplexing method and duplexed server system
CN102420814A (en) * 2011-11-21 2012-04-18 航天科工深圳(集团)有限公司 Data access method and device, and server
CN107066405A (en) * 2017-03-31 2017-08-18 联想(北京)有限公司 A kind of sharing method of memory device, interconnection subsystem and internal memory
CN107241335A (en) * 2017-06-16 2017-10-10 上海闻泰信息技术有限公司 The method and device of information sharing
CN107579864A (en) * 2017-10-16 2018-01-12 深圳大宇无限科技有限公司 Ask monitoring method, device and server
CN108566552A (en) * 2018-04-20 2018-09-21 四川长虹网络科技有限责任公司 Multi-medium play method and system suitable for top box of digital machine
CN109471743A (en) * 2018-11-12 2019-03-15 深圳前海微众银行股份有限公司 Log collecting method, device and computer readable storage medium
CN109508246A (en) * 2018-06-25 2019-03-22 广州多益网络股份有限公司 Log recording method, system and computer readable storage medium

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103514053B (en) * 2013-09-22 2017-01-25 中国科学院信息工程研究所 Shared-memory-based method for conducting communication among multiple processes
CN106648931A (en) * 2016-12-12 2017-05-10 贵阳朗玛信息技术股份有限公司 Log information recording method and device
CN107491355A (en) * 2017-08-17 2017-12-19 山东浪潮商用系统有限公司 Funcall method and device between a kind of process based on shared drive

Patent Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6219672B1 (en) * 1997-12-11 2001-04-17 Kabushiki Kaisha Toshiba Distributed shared memory system and method of controlling distributed shared memory
US20030172093A1 (en) * 2001-03-26 2003-09-11 Mitsugu Nagoya Server duplexing method and duplexed server system
CN102420814A (en) * 2011-11-21 2012-04-18 航天科工深圳(集团)有限公司 Data access method and device, and server
CN107066405A (en) * 2017-03-31 2017-08-18 联想(北京)有限公司 A kind of sharing method of memory device, interconnection subsystem and internal memory
CN107241335A (en) * 2017-06-16 2017-10-10 上海闻泰信息技术有限公司 The method and device of information sharing
CN107579864A (en) * 2017-10-16 2018-01-12 深圳大宇无限科技有限公司 Ask monitoring method, device and server
CN108566552A (en) * 2018-04-20 2018-09-21 四川长虹网络科技有限责任公司 Multi-medium play method and system suitable for top box of digital machine
CN109508246A (en) * 2018-06-25 2019-03-22 广州多益网络股份有限公司 Log recording method, system and computer readable storage medium
CN109471743A (en) * 2018-11-12 2019-03-15 深圳前海微众银行股份有限公司 Log collecting method, device and computer readable storage medium

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
RUAN, XIACHENG: "The design and implementation of general logging system under distributed computing environment", CHINA MASTER'S THESES FULL-TEXT DATABASE, INFORMATION SCIENCE AND TECHNOLOGY, no. 03, 15 March 2016 (2016-03-15), XP055766303 *

Also Published As

Publication number Publication date
CN111699479A (en) 2020-09-22

Similar Documents

Publication Publication Date Title
JP6600373B2 (en) System and method for active-passive routing and control of traffic in a traffic director environment
US9141491B2 (en) Highly available server system based on cloud computing
US11240745B2 (en) Network slice instance processing method and apparatus, and system
US9753786B2 (en) Client server communication system
CN107515783B (en) Application container cluster tool-based application container management and control method and device
WO2020252724A1 (en) Log processing method and device, and computer-readable storage medium
WO2018121334A1 (en) Web application service providing method, apparatus, electronic device and system
US20110173319A1 (en) Apparatus and method for operating server using virtualization technique
US10884880B2 (en) Method for transmitting request message and apparatus
JP2008305070A (en) Information processor and information processor system
WO2024016624A1 (en) Multi-cluster access method and system
US8458702B1 (en) Method for implementing user space up-calls on java virtual machine before/after garbage collection
CN112559461A (en) File transmission method and device, storage medium and electronic equipment
CA3138764A1 (en) Data processing method, device, computer equipment and storage medium
CN111147274B (en) System and method for creating a highly available arbitration set for a cluster solution
CN113467873A (en) Virtual machine scheduling method and device, electronic equipment and storage medium
JP2013218449A (en) Cloud computing system
US8407343B2 (en) System, method, and computer-readable medium for managing communications among service modules
CN114553900B (en) Distributed block storage management system, method and electronic equipment
CN115361271A (en) SSH server switching and connecting method, cloud server and storage medium
CN116301567A (en) Data processing system, method and equipment
CN115378557A (en) Hot standby implementation method, device, system, electronic equipment and storage medium
CN116301568A (en) Data access method, device and equipment
US20140215037A1 (en) Provision of management information and requests among management servers within a computing network
JP2011203848A (en) Resource management device, program, and method for sharing database in distributed manner

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 19933744

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 19933744

Country of ref document: EP

Kind code of ref document: A1