Method and device for generating log number
By defining and configuring the log number format in the background database table, a globally unique target log number is generated, which solves the problems of log number uniqueness and low generation efficiency in the existing technology, and efficient and unique log number generation is achieved.
Patent Information
- Application Number
- CN202411642903.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-18
- Publication Date
- 2025-03-11
AI Technical Summary
In the prior art, the uniqueness of the log number in the cluster cannot be guaranteed, and each time a log number is generated, the database read and write operations are required, resulting in low generation efficiency.
By reading the background database table, defining the initial log number format of each node, configuring and initializing the log number, generating a globally unique target log number, avoiding frequent read and write operations of the database.
Ensure the global uniqueness of log numbers, improve the efficiency of log number generation, and solve the problem of low log number generation efficiency.
Smart Images

Figure CN119597572A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a method and device for generating a log number. Background Art
[0002] The system log number is a unique identifier assigned by the information system to each log record. During the operation of the system, the frequent use of the log number plays many important roles. For example, it helps with system management and troubleshooting. Second, it meets the needs of data traceability and auditing. Third, it can effectively cope with the complexity of distributed systems. Finally, it can support the implementation of automated operation and maintenance. Therefore, ensuring that the log number has global uniqueness, efficiency, and clear meaning is the key to improving system performance.
[0003] In existing technologies, applications usually generate a series of unique log IDs for each node in advance based on the configuration information of each node in the cluster, and store these IDs in the database in advance so that these IDs can be directly inserted into the database's log table during subsequent logging processes, thereby being used to identify and track the source of each log record.
[0004] However, when different application service nodes in the cluster read and increment the log number at the same time, the uniqueness of the log number in the cluster cannot be guaranteed, and each time a log number is generated, a database read and write operation is required, resulting in low efficiency in log number generation. Summary of the invention
[0005] Based on the above-mentioned deficiencies of the prior art, the present application provides a method and device for generating a log number to solve the problem of low efficiency in generating log numbers brought about by the prior art.
[0006] In order to achieve the above objectives, this application provides the following technical solutions:
[0007] The first aspect of the present application provides a method for generating a log number, comprising:
[0008] Reading a backend database table; wherein the backend database table at least includes an initial log number corresponding to each node of the server;
[0009] For each of the nodes, define the format of the initial log number corresponding to the node to obtain a standard log number;
[0010] The standard log number is configured to obtain a configuration log number;
[0011] The configuration log number is initialized to obtain a target log number.
[0012] Optionally, in the above-mentioned log number generation method, the step of defining the format of the initial log number corresponding to the node to obtain the standard log number includes:
[0013] Define the number of digits of the initial log number corresponding to the node;
[0014] After defining the number of digits of the initial log number, defining the value of the first preset number of digits in the number of digits of the initial log number as a date;
[0015] The value of the target preset number of digits in the initial log number is defined as the cluster number of the node; wherein the target preset number of digits is a rear preset position adjacent to the front preset number of digits;
[0016] The values of the remaining digits in the digits of the initial log number are defined as an increasing sequence number to obtain a standard log number.
[0017] Optionally, in the above-mentioned method for generating a log number, configuring the standard log number to obtain a configured log number includes:
[0018] Configure the type of the standard log number as a global class;
[0019] Define the configured standard log number variable as a shared variable;
[0020] Configure the access object corresponding to the standard log number in the data table to obtain the configured log number.
[0021] Optionally, in the above-mentioned method for generating a log number, after configuring the standard log number to obtain the configured log number, the method further includes:
[0022] The configuration log number is taken as a java object and stored in the spring container.
[0023] Optionally, in the above-mentioned log number generation method, the initializing the configuration log number to obtain the target log number includes:
[0024] Obtain the current date and parse the cluster number corresponding to the node from the server;
[0025] Based on the current date and the cluster number, assemble the configuration log numbers to obtain a global log number, and set an upper limit and a lower limit of the global log number;
[0026] After the setting is completed, determine whether the global log number exists in the database;
[0027] If the global log number exists in the database, the sequence number of the global log number is incremented to obtain a first target sequence number, and the shared variable of the global log number is set to the first target sequence number to obtain a target log number;
[0028] If the global log number does not exist in the database, the sequence number of the global log number is set to a preset threshold to obtain a second target sequence number;
[0029] Based on the second target sequence number, the global log number is assembled, and the shared variable of the assembled global log number is set to the second target sequence number to obtain a target log number.
[0030] Optionally, in the above log number generation method, the method further includes:
[0031] receiving a processing request for the target log number;
[0032] According to the processing request, the sequence number of the target log number is incremented, and the incremented target log number is stored in the data table.
[0033] The second aspect of the present application provides a device for generating a log number, including:
[0034] A reading unit, the unit reads a background database table; wherein the background database table at least includes an initial log number corresponding to each node of the server;
[0035] A definition unit, used for defining the format of the initial log number corresponding to each node respectively, to obtain a standard log number;
[0036] A configuration unit, configured to configure the standard log number to obtain a configuration log number;
[0037] The initialization unit is used to initialize the configuration log number to obtain a target log number.
[0038] Optionally, in the above-mentioned log number generating device, the definition unit includes:
[0039] A digit definition unit, used to define the digit of the initial log number corresponding to the node;
[0040] A date definition unit, used for defining the value of the first preset number of digits in the number of digits of the initial log number as a date after defining the number of digits of the initial log number;
[0041] A number definition unit, used to define a value of a target preset number of digits in the number of digits of the initial log number as the cluster number of the node; wherein the target preset number of digits is a rear preset position adjacent to the front preset number of digits;
[0042] The definition subunit is used to define the value of the remaining digits in the digits of the initial log number as an increasing sequence number to obtain a standard log number.
[0043] Optionally, in the above-mentioned log number generating device, the configuration unit includes:
[0044] A type configuration unit, used to configure the type of the standard log number as a global class;
[0045] The variable definition unit is used to define the configured standard log number variable as a shared variable;
[0046] The object configuration unit is used to configure the access object corresponding to the standard log number in the data table to obtain the configured log number.
[0047] Optionally, in the above-mentioned log number generating device, it also includes:
[0048] The storage unit is used to store the configuration log number as a Java object in a spring container.
[0049] Optionally, in the above-mentioned log number generating device, the initialization unit includes:
[0050] A parsing unit, used to obtain the current date and parse the cluster number corresponding to the node from the server;
[0051] An assembling unit, configured to assemble the configuration log numbers based on the current date and the cluster number to obtain a global log number, and to set an upper limit and a lower limit of the global log number;
[0052] A judging unit, used for judging whether the global log number exists in the database after the setting is completed;
[0053] A first setting unit is configured to, if the global log number exists in the database, increment the sequence number of the global log number to obtain a first target sequence number, and set the shared variable of the global log number to the first target sequence number to obtain a target log number;
[0054] A second setting unit is used to set the sequence number of the global log number to a preset threshold value if the global log number does not exist in the database, so as to obtain a second target sequence number;
[0055] An assembling unit is used to assemble the global log number based on the second target sequence number, and set the shared variable of the assembled global log number to the second target sequence number to obtain a target log number.
[0056] Optionally, in the above-mentioned log number generating device, it also includes:
[0057] A receiving unit, configured to receive a processing request for the target log number;
[0058] The incrementing unit is used to increment the sequence number of the target log number according to the processing request, and store the incremented target log number in the data table.
[0059] The present application provides a method for generating a log number, which reads a background database table, wherein the background database table includes at least the initial log number corresponding to each node of the server, and then defines the format of the initial log number corresponding to each node for each node, obtains a standard log number, and then configures the standard log number to obtain a configuration log number, and finally initializes the configuration log number to obtain a target log number. Thus, when different application service nodes in the cluster read and increment the log number at the same time, the incremented log number will be saved in the database table, and no database read and write operations are required, and the global uniqueness of the log number can be ensured, thereby solving the problem of low log number generation efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0060] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying any creative work.
[0061] Figure 1 A flowchart of a method for generating a log number provided in an embodiment of the present application;
[0062] Figure 2 A flowchart of a method for defining a log number provided in an embodiment of the present application;
[0063] Figure 3 A flowchart of a method for configuring a log number provided in an embodiment of the present application;
[0064] Figure 4 A flowchart of a method for initializing a log number provided in an embodiment of the present application;
[0065] Figure 5 A flowchart of a method for increasing a log number provided in another embodiment of the present application;
[0066] Figure 6 A schematic diagram of the structure of a log number generation device provided in another embodiment of the present application. DETAILED DESCRIPTION
[0067] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0068] In this application, relational terms such as first and second, etc. are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "comprise", "include" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the statement "comprises a ..." does not exclude the presence of other identical elements in the process, method, article or device including the element.
[0069] The present application embodiment provides a method for generating a log number, such as Figure 1 As shown, the specific steps include:
[0070] S101, read the background database table.
[0071] The background database table may include an initial log number corresponding to each node of the server.
[0072] It should be noted that when the system is initialized, the background database table of the server background will be read, and the initial log number corresponding to each node of the server can be obtained through the query statement. At this time, the initial log number is just a null value and has no meaning and uniqueness. It cannot be used as the unique identifier of the server node. Therefore, in order for the log number to have a certain meaning and ensure the global uniqueness of the log number, the initial log number needs to be further generated and processed.
[0073] Optionally, the query statement can be queried using SQL statements, such as:
[0074]
[0075] S102 . For each node, define the format of the initial log number corresponding to the node to obtain a standard log number.
[0076] It is understandable that in order to ensure that each log number is unique at the cluster and node level, and to clearly identify the time and source of log number generation, and to effectively avoid log number conflicts, the initial log number of each node can be pre-defined to have a unified and standardized format to avoid log conflicts, losses or misunderstandings caused by manual operations or misconfigurations, thereby improving system stability and reliability. This also facilitates the management and query of log numbers.
[0077] Optionally, in another embodiment of the present application, a specific implementation of step S102 is as follows: Figure 2 As shown, the following steps are included:
[0078] S201. Define the number of digits of the initial log number corresponding to the node.
[0079] Optionally, you can use the log number definition interface provided by the system to first define the initial log number as 18, which is a long integer. Of course, other digits are also possible, and the specific setting can be based on demand.
[0080] S202: After defining the number of digits of the initial log number, define the value of the first preset number of digits in the number of digits of the initial log number as the date.
[0081] It can be understood that after defining the number of digits of the initial log number, it is necessary to define the numerical value corresponding to each digit to ensure the uniqueness of the log number. Therefore, in an embodiment of the present application, the data corresponding to the first eight digits of the initial log number are defined as the date, where the format of the date is yyyyMMdd, yyyy is the year, MM is the month, and dd is the date, so as to identify the time when the log was generated.
[0082] Optionally, the number of pre-set digits is not necessarily the first eight digits, and can be specifically set according to requirements.
[0083] S203: Define the value of the target preset number of digits in the initial log number as the cluster number of the node.
[0084] The target preset number of digits is a rear preset position adjacent to a front preset number of digits.
[0085] Specifically, after setting the first eight digits to the date format, the middle two digits need to be used to represent the number of the node in the cluster application server, so as to easily know which node the log number belongs to.
[0086] S204: Define the value of the remaining digits in the initial log number as an increasing sequence number to obtain a standard log number.
[0087] Specifically, the value corresponding to the remaining digits is defined as an incrementable sequence number, that is, each time the log number is requested, the sequence number of the log number is incremented each time, and each time it is unique. The sequence number is in days, and the daily sequence number starts to increment from 00000001.
[0088] S103: Configure the standard log number to obtain a configured log number.
[0089] It should be noted that the purpose of configuring the standard log number is to ensure the uniqueness, consistency, traceability, and manageability of log records. It can effectively manage logs in a distributed system or multi-node environment and provide efficient log retrieval and analysis functions. The specific configuration can be done through code.
[0090] Optionally, in another embodiment of the present application, a specific implementation of step S103 is as follows: Figure 3 As shown, the following steps are included:
[0091] S301. Configure the type of the standard log number as a global class.
[0092] It is understandable that in order to ensure the consistency, uniqueness and manageability of log numbers in the system, the type of standard log numbers can be configured as a global class, which not only provides a standard interface for generating log numbers, but also centrally controls and optimizes the log number generation logic, thereby improving the performance, scalability and maintainability of the system.
[0093] For example, a globally shared LogNumberGenerator class can be designed to implement this function. The LogNumberGenerator class encapsulates the entire logic of log number generation to ensure that all log numbers generated in the system follow unified rules.
[0094] S302: Define the configured standard log number variable as a shared variable.
[0095] Specifically, in order to achieve that the threads in the system share the same set of log number generation rules, thereby ensuring consistency, coordination and efficiency, it is optional to define shared variables related to the log number in the LogConfig class, such as date format, cluster identifier, node identifier and serial number counter. All log number generation processes will be based on these shared variables, thereby avoiding the use of log numbers in different formats by different modules or services, reducing the analysis difficulties and misunderstandings caused by format differences, improving the maintainability of the system log, and by defining shared variables, multiple calculations or repeated operations can be avoided. For example, in a multi-threaded environment, if each thread maintains a set of log number generation rules separately, it may lead to repeated calculations and waste of resources. By sharing variables, it can be ensured that resources (such as counters, date formats, etc.) only need to be maintained in one place, improving performance, and also improving the efficiency of log number generation.
[0096] S303: Configure the access object corresponding to the standard log number in the data table to obtain the configured log number.
[0097] It should be noted that in order to associate the standard log number configuration with the access object (DAO) in the database table, and also obtain the configured log number through the access object, a set of database models and DAO layer designs can be constructed, wherein the log_config class in the database model is used to store the configuration information of the log number, including the date format, cluster identifier, node identifier, and current serial number. The LogConfigDAO in the DAO layer is used to provide an interface for obtaining configuration from the database and updating the serial number, thereby realizing the association of the standard log number and the subsequently incremented standard log number with the corresponding access object in the data table.
[0098] Optionally, after obtaining the configuration log number, it is also necessary to store the configuration log number in the spring container, so as to achieve centralized management and efficient access of the configuration. Therefore, after executing step S103, it further includes:
[0099] The configuration log number is taken as a Java object and stored in the spring container.
[0100] Specifically, storing the log number configuration in the Spring container (i.e. as a Spring-managed Bean) can achieve centralized management and efficient access to the configuration. Spring's dependency injection (DI) mechanism allows us to obtain and use the log number configuration in different places in the application, avoiding database queries every time, improving performance and maintainability.
[0101] For example, it can be implemented through the following code logic:
[0102] @Component / / Spring Bean
[0103] public class LogNumberGenerator{
[0104] private final LogConfig logConfig;
[0105] / / Constructor injects LogConfig
[0106] @Autowired
[0107] public LogNumberGenerator(LogConfig logConfig){
[0108] this.logConfig = logConfig;
[0109] }, thereby registering both LogConfig and LogNumberGenerator as beans of the Spring container by using the @Component annotation. This enables them to be used in the application through dependency injection, which means that the configured log number is stored in the Spring container.
[0110] S104: Initialize the configuration log number to obtain the target log number.
[0111] It should be emphasized that in cluster applications, generating unique and traceable log numbers is crucial for subsequent log tracking and problem location. Therefore, by initializing the log number and using appropriate configuration, it can be ensured that the generated log number is globally unique, and each log number can be associated with a specific date, cluster, node, and generation order (serial number), so that a unique target log number can be obtained for each node.
[0112] Optionally, in another embodiment of the present application, a specific implementation of step S104 is as follows: Figure 4 As shown, the following steps are included:
[0113] S401. Obtain the current date and parse the cluster number corresponding to the node from the server.
[0114] It is understandable that in cluster applications, it is usually necessary to monitor and analyze logs generated by different systems and services. With a unified log number format, you can more easily classify logs, especially across multiple services and machines. Therefore, before generating a log number, the value corresponding to each digit in each log number has been defined. Therefore, the first eight digits of the log number are the date, and the next two digits are the node number. Therefore, if you want to generate a log number that has a certain meaning and ensures the global uniqueness of the log number, you need to first obtain the current date and parse the cluster number corresponding to the node from the server, so as to ensure that all logs have a consistent format, which is convenient for subsequent analysis and retrieval, and use the node ID as part of the log number, so that log managers can quickly determine the source of the log and quickly locate the problem.
[0115] S402: Based on the current date and the cluster number, assemble the configuration log numbers to obtain a global log number, and set the upper and lower limits of the global log number.
[0116] Specifically, after obtaining the current date and cluster number, they can be assembled in a defined order to obtain part of the log number. For example, if the current date is 20240831 and the cluster number is 01, the assembled global log number is 2024083101.
[0117] In addition, you also need to set the upper and lower limits of the global log number to effectively avoid log number overflow. For example, set a maximum value. When the sequence number reaches this maximum value, the system will reset the sequence number or regenerate the log number to avoid exceeding the preset range and ensure long-term stable operation of the system. Some systems will automatically wrap around when the sequence number approaches the upper limit, thereby avoiding the use of too large numbers while maintaining the incremental characteristics of the sequence number. If there is no upper limit, the log number may reach the digital limit designed by the system after a long period of operation, resulting in the system being unable to generate a new log number. By setting upper and lower limits, you can prevent log number conflicts and overflows and ensure the stable growth and manageability of log numbers.
[0118] S403: After the setting is completed, determine whether there is a global log number in the database.
[0119] It should be noted that after setting the upper and lower limits of the global log number, considering that each time a request is made to obtain the log number of a node, the log number will be incremented and the log will be stored in the database, it can be said that the log number of the node has been generated. Therefore, in order to avoid repeated generation of log numbers and affect the uniqueness of the log, before finally generating the log number of the node, it is also determined whether there is a global log number in the database. If there is a global log number in the database, it means that the log number of the node has been generated, so step S404 is executed at this time. If there is no global log number in the database, it means that the log number of the node has not been generated, so step S405 is executed.
[0120] S404 , increment the sequence number of the global log number to obtain a first target sequence number, and set the shared variable of the global log number to the first target sequence number to obtain a target log number.
[0121] It is understandable that when a global log number exists in the database, it means that the node already has a unique log number. At this time, it is necessary to generate a new target log number for the node by increasing its sequence number and updating the shared variable.
[0122] Therefore, when it is found that the global log number already exists, the sequence number of the global log number will be increased by 1, thereby ensuring the logical order of the current log number and the existing log number, so that the new log number will not be repeated, and the increasing order of the log number is guaranteed. For example, if the original sequence number is N, then after adding 1, the newly generated target sequence number is N+1.
[0123] Then, by setting the new sequence number as the first target sequence number, the relevant records of the global log number in the database are actually updated. At this time, the shared variable (i.e., the log number status in the database or memory) is updated to the new target sequence number, so that the latest sequence number is reflected in the shared resource, ensuring that other system modules can obtain the correct, increasing sequence number the next time they obtain the log number. Finally, after updating the sequence number of the global log number, the new target log number of the node is composed of the global log number + the new sequence number. For example, if the global log number is 2024083101 and the sequence number is 00000001, then the target log number becomes 202408310100000002, and then this target log number can be used for new log record operations to ensure that the new log record is unique and ordered globally.
[0124] S405: Set the sequence number of the global log number to a preset threshold to obtain a second target sequence number.
[0125] It should be noted that when the global log number does not exist in the database, it means that an initial sequence number needs to be assigned to the log number, that is, 00000001, and 00000001 is set as the second target sequence number.
[0126] S406 , assembling the global log number based on the second target sequence number, and setting the shared variable of the assembled global log number to the second target sequence number to obtain the target log number.
[0127] It can be understood that when the global log number does not exist in the database and after the sequence number of the global log number is set, the sequence number can be assembled into the global log number. For example, if the global log number is 2024083002 and the sequence number is 00000001, the assembled global log number is 202408300200000001.
[0128] In addition, after the log number is assembled, the shared variables need to be updated so that the location of the global log number and sequence number information stored in the database or memory can be known. Therefore, by setting the shared variables to the second target sequence number, the latest status of the global log number is updated in the system, so that subsequent requests can generate log numbers based on the new target sequence number.
[0129] Optionally, after obtaining the target log number corresponding to each node of the server, in order to avoid reading the database table when the server requests to obtain the log number, the database needs to be further read and written, thereby affecting the increment of the target log number corresponding to the node. Therefore, in another embodiment of the present application, a method for incrementing the log number is also provided, such as Figure 5 As shown, the following steps are included:
[0130] S501: Receive a processing request for a target log number.
[0131] Specifically, the system receives processing requests for target log numbers. Usually, these requests require processing of a specific log number. This request may come from a logging module, a log query module, or other business logic that needs to generate a unique log number.
[0132] For example, the received request might be:
[0133] {
[0134] "action":"generate_log",
[0135] "log_category":"transaction",
[0136] "timestamp":"202408300200000001"
[0137] }
[0138] At this point, the system will parse the request content and extract the basic information of the target log number, such as timestamp, sequence number, etc., as the basis for subsequent processing.
[0139] S502: According to the processing request, the sequence number of the target log number is incremented, and the incremented target log number is stored in the data table.
[0140] It is understandable that once a processing request is received, the system will increment the sequence number based on the target log number and store the incremented new log number in the data table.
[0141] Specifically, the system first queries the target log number and sequence number stored in the database to obtain the status of the current log number, and then the system increments the sequence number of the target log number. For example, if the current sequence number is 00000001, the incremented sequence number is 00000002, and a new target log number 202408300200000002 is generated, and the current shared variable of the target log number is updated to the incremented sequence number 00000002. Finally, the system stores the incremented target log number (for example, 02408300200000002) in the data table of the database. In addition, after the processing is completed, the system usually returns the new log number to the requester for subsequent use.
[0142] The present application provides a method for generating a log number, which reads a background database table, wherein the background database table includes at least the initial log number corresponding to each node of the server, and then defines the format of the initial log number corresponding to each node for each node, obtains a standard log number, and then configures the standard log number to obtain a configuration log number, and finally initializes the configuration log number to obtain a target log number. Thus, when different application service nodes in the cluster read and increment the log number at the same time, the incremented log number will be saved in the database table, and no database read and write operations are required, and the global uniqueness of the log number can be ensured, thereby solving the problem of low log number generation efficiency.
[0143] Another embodiment of the present application provides a device for generating a log number, such as Figure 6 As shown, it includes the following units:
[0144] The reading unit 601 reads a background database table, wherein the background database table at least includes an initial log number corresponding to each node of the server.
[0145] The definition unit 602 is used to define the format of the initial log number corresponding to each node respectively, and obtain a standard log number.
[0146] The configuration unit 603 is used to configure the standard log number to obtain the configuration log number.
[0147] The initialization unit 604 is used to initialize the configuration log number to obtain a target log number.
[0148] It should be noted that the specific working process of the above-mentioned units in the embodiment of the present application can refer to steps S101 to S104 in the above-mentioned method embodiment, and will not be repeated here.
[0149] Optionally, in a device for generating a log number provided in another embodiment of the present application, the definition unit 602 includes:
[0150] The digit definition unit is used to define the digits of the initial log number corresponding to the node.
[0151] The date definition unit is used to define the value of the first preset number of digits in the initial log number as the date after the number of digits in the initial log number is defined.
[0152] The number definition unit is used to define the value of the target preset number of digits in the initial log number as the cluster number of the node, wherein the target preset number of digits is a rear preset position adjacent to the front preset number of digits.
[0153] A definition subunit is used to define the values of the remaining digits of the initial log number as an increasing sequence number to obtain a standard log number.
[0154] Optionally, in a device for generating a log number provided in another embodiment of the present application, the configuration unit 603 includes:
[0155] Type configuration unit, used to configure the type of the standard log number as a global class.
[0156] The variable definition unit is used to define the configured standard log number variable as a shared variable.
[0157] The object configuration unit is used to configure the access object corresponding to the standard log number in the data table to obtain the configured log number.
[0158] Optionally, in another embodiment of the present application, a device for generating a log number further includes:
[0159] The storage unit is used to store the configuration log number as a Java object in the spring container.
[0160] Optionally, in a device for generating a log number provided in another embodiment of the present application, the initialization unit 604 includes:
[0161] The parsing unit is used to obtain the current date and parse the cluster number corresponding to the node from the server.
[0162] The assembly unit is used to assemble the configuration log numbers based on the current date and the cluster number to obtain the global log number, and to set the upper and lower limits of the global log number.
[0163] The judging unit is used to judge whether the global log number exists in the database after the setting is completed.
[0164] The first setting unit is used to increment the sequence number of the global log number if the global log number exists in the database to obtain a first target sequence number, and set the shared variable of the global log number to the first target sequence number to obtain a target log number.
[0165] The second setting unit is used to set the sequence number of the global log number to a preset threshold if the global log number does not exist in the database, so as to obtain a second target sequence number.
[0166] The assembling unit is used to assemble the global log number based on the second target sequence number, and set the shared variable of the assembled global log number to the second target sequence number to obtain the target log number.
[0167] Optionally, in another embodiment of the present application, a device for generating a log number further includes:
[0168] The receiving unit is used to receive a processing request of a target log number.
[0169] The incrementing unit is used to increment the sequence number of the target log number according to the processing request, and store the incremented target log number in the data table.
[0170] It should be noted that the specific working process of each unit provided in the above embodiments of the present application can refer to the corresponding steps in the above method embodiments, and will not be repeated here.
[0171] It should also be noted that a log number generation device provided in an embodiment of the present application has the technical effects of any of the above embodiments, and the embodiments of the present application are not described in detail here.
[0172] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0173] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A method for generating a log number, characterized in that: include: Reading a backend database table; wherein the backend database table at least includes an initial log number corresponding to each node of the server; For each of the nodes, define the format of the initial log number corresponding to the node to obtain a standard log number; The standard log number is configured to obtain a configuration log number; The configuration log number is initialized to obtain a target log number.
2. The method according to claim 1, characterized in that The format of the initial log number corresponding to the node is defined to obtain the standard log number, including: Define the number of digits of the initial log number corresponding to the node; After defining the number of digits of the initial log number, defining the value of the first preset number of digits in the number of digits of the initial log number as a date; The value of the target preset number of digits in the initial log number is defined as the cluster number of the node; wherein the target preset number of digits is a rear preset position adjacent to the front preset number of digits; The values of the remaining digits in the digits of the initial log number are defined as an increasing sequence number to obtain a standard log number.
3. The method according to claim 1, characterized in that The step of configuring the standard log number to obtain the configured log number includes: Configure the type of the standard log number as a global class; Define the configured standard log number variable as a shared variable; Configure the access object corresponding to the standard log number in the data table to obtain the configured log number.
4. The method according to claim 1, characterized in that: After configuring the standard log number to obtain the configured log number, the method further includes: The configuration log number is taken as a java object and stored in the spring container.
5. The method according to claim 1, characterized in that The step of initializing the configuration log number to obtain a target log number includes: Obtain the current date and parse the cluster number corresponding to the node from the server; Based on the current date and the cluster number, assemble the configuration log numbers to obtain a global log number, and set an upper limit and a lower limit of the global log number; After the setting is completed, determine whether the global log number exists in the database; If the global log number exists in the database, the sequence number of the global log number is incremented to obtain a first target sequence number, and the shared variable of the global log number is set to the first target sequence number to obtain a target log number; If the global log number does not exist in the database, the sequence number of the global log number is set to a preset threshold to obtain a second target sequence number; Based on the second target sequence number, the global log number is assembled, and the shared variable of the assembled global log number is set to the second target sequence number to obtain a target log number.
6. The method according to claim 1, characterized in that Also includes: receiving a processing request for the target log number; According to the processing request, the sequence number of the target log number is incremented, and the incremented target log number is stored in the data table.
7. A device for generating a log number, characterized in that: include: A reading unit, the unit reads a background database table; wherein the background database table at least includes an initial log number corresponding to each node of the server; A definition unit, used for defining the format of the initial log number corresponding to each node respectively, to obtain a standard log number; A configuration unit, configured to configure the standard log number to obtain a configuration log number; The initialization unit is used to initialize the configuration log number to obtain a target log number.
8. The device according to claim 7, characterized in that The definition unit comprises: A digit definition unit, used to define the digit of the initial log number corresponding to the node; A date definition unit, used for defining the value of the first preset number of digits in the number of digits of the initial log number as a date after defining the number of digits of the initial log number; A number definition unit, used to define a value of a target preset number of digits in the number of digits of the initial log number as a cluster number of the node; wherein the target preset number of digits is a rear preset position adjacent to the front preset number of digits; The definition subunit is used to define the value of the remaining digits in the digits of the initial log number as an increasing sequence number to obtain a standard log number.
9. The device according to claim 7, characterized in that The configuration unit comprises: A type configuration unit, used to configure the type of the standard log number as a global class; The variable definition unit is used to define the configured standard log number variable as a shared variable; The object configuration unit is used to configure the access object corresponding to the standard log number in the data table to obtain the configured log number.
10. The device according to claim 7, characterized in that Also includes: The storage unit is used to store the configuration log number as a java object in a spring container.