Database log reading method and device, storage medium and program product
By building a log mapping table in a centralized control system for database instances and only reading the necessary log file contents, the problem of large resource consumption and time-consuming caused by full reading of log files in the existing technology is solved, and efficient log reading and improved user experience is achieved.
Patent Information
- Application Number
- CN202510265798.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-06
- Publication Date
- 2025-06-06
AI Technical Summary
In the database instance centralized control system, directly reading all database log contents leads to large and long time-consuming system resources, long waiting time for users, low reading efficiency and poor user experience.
By building a log mapping table, the starting line number and terminating line number of the target log file are determined based on the specified page number and the number of rows per page, and only the necessary log file contents are read to avoid reading all log files in full.
Improves the efficiency of database log reading, reduces user waiting time, and improves user experience.
Smart Images

Figure CN120104587A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of database technology, and in particular to a database log reading method, device, storage medium and program product. Background Art
[0002] In a centralized database instance management system, the contents of the database log need to be presented to users or other subsystems to monitor the database status or troubleshoot errors. However, database log files will become larger and larger over time, and directly reading all log contents will cause system lag.
[0003] In the prior art, the page number and the number of lines are generally specified, and then the log content is displayed to the user in pages. However, since the database logs are distributed in different log files, the contents of all log files need to be aggregated into a temporary file, and then the contents of the temporary file are displayed in pages.
[0004] However, the existing method requires reading all log files, resulting in large consumption of system resources, and the aggregation and paging processing takes a long time, resulting in long user waiting time, low reading efficiency, and poor user experience. Summary of the invention
[0005] The embodiments of the present application provide a database log reading method, device, storage medium and program product, which only need to read the necessary log file content and avoid reading all log files in full, thereby improving reading efficiency and reducing user waiting time.
[0006] In a first aspect, an embodiment of the present application provides a database log reading method, comprising:
[0007] In response to a log reading instruction, determining a start line number and an end line number of a target log file according to a specified page number and the number of lines per page, wherein the log reading instruction carries the specified page number and the number of lines per page;
[0008] Locate the target log file according to the starting line number, the ending line number and a log mapping table, wherein the log mapping table includes a correspondence between the file name and the total number of lines of each log file;
[0009] The target log file is read, and the contents of the target log file are combined and displayed to the user end.
[0010] In a possible implementation manner, before responding to the log reading instruction, the method further includes:
[0011] Determine whether the log reading instruction is received for the first time;
[0012] If so, initialize the log mapping table.
[0013] In a possible implementation, the initializing the log mapping table includes:
[0014] Generate an initial capacity of the log mapping table;
[0015] Enable monitoring of each log file in the log file directory;
[0016] Generate the log mapping table.
[0017] In a possible implementation, the generating the log mapping table includes:
[0018] Obtain each of the log files, and obtain the total number of lines in each of the log files;
[0019] Generate a correspondence between the file name of each log file and the total number of lines thereof.
[0020] In a possible implementation, obtaining each log file includes:
[0021] Obtain the total number of log files required by the log mapping table;
[0022] Get the first log file in the log mapping table;
[0023] In the log file directory, each log file is obtained in sequence according to the first log file and the total number of log files.
[0024] In a possible implementation manner, after starting monitoring of each log file in the log file directory, the method further includes:
[0025] If it is detected that a new log file is generated, the file name of the new log file and the total number of lines of the new log file are added to the log mapping table according to the creation time of the new log file;
[0026] If it is detected that the log file is updated, the log mapping table is updated according to the content of the updated log file;
[0027] If it is detected that the log file is deleted, the file name and the total number of lines of the corresponding log file in the log mapping table are deleted according to the file name of the deleted log file.
[0028] In a possible implementation manner, after determining the start line number and the end line number of the target log file according to the specified page number and the number of lines per page, the method further includes:
[0029] According to the termination line number, determining whether the target log file is in the log mapping table;
[0030] If not, expand the log mapping table.
[0031] In a possible implementation, the expanding the log mapping table includes:
[0032] Get the file name of the last log file in the log mapping table;
[0033] In the log file directory, obtain other log files whose creation time is later than the last log file;
[0034] Determining the expansion capacity of the log mapping table according to the termination line of the other log files and the current capacity of the log mapping table;
[0035] The current capacity of the log mapping table is expanded according to the expanded capacity.
[0036] In a possible implementation manner, before the current capacity of the log mapping table is expanded according to the capacity expansion, the method further includes:
[0037] Determining whether the capacity of the log mapping table after expansion exceeds the maximum capacity;
[0038] If so, obtain the last log file that is not in the log mapping table;
[0039] Obtain the log file to be deleted from the log mapping table according to the last log file;
[0040] The file name and the total number of lines of the log file to be deleted are deleted so that the current capacity of the log mapping table is less than or equal to the maximum capacity.
[0041] In a second aspect, an embodiment of the present application provides a database log reading device, including:
[0042] A first processing module, configured to respond to a log reading instruction and determine a start line number and an end line number of a target log file according to a specified page number and the number of lines per page, wherein the log reading instruction carries the specified page number and the number of lines per page;
[0043] A second processing module, configured to locate a target log file according to the starting line number, the ending line number and a log mapping table, wherein the log mapping table includes a correspondence between a file name and a total number of lines of each log file;
[0044] The reading and display module is used to read the target log file, and merge the read contents of the target log file and display them to the user end.
[0045] In a possible implementation manner, the first processing module is further configured to:
[0046] Determine whether the log reading instruction is received for the first time;
[0047] If so, initialize the log mapping table.
[0048] In a possible implementation manner, the first processing module is further configured to:
[0049] Generate an initial capacity of the log mapping table;
[0050] Enable monitoring of each log file in the log file directory;
[0051] Generate the log mapping table.
[0052] In a possible implementation manner, the first processing module is further configured to:
[0053] Obtain each of the log files, and obtain the total number of lines in each of the log files;
[0054] Generate a correspondence between the file name of each log file and the total number of lines thereof.
[0055] In a possible implementation manner, the first processing module is further configured to:
[0056] Obtain the total number of log files required by the log mapping table;
[0057] Get the first log file in the log mapping table;
[0058] In the log file directory, each log file is obtained in sequence according to the first log file and the total number of log files.
[0059] In a possible implementation manner, the first processing module is further configured to:
[0060] If it is detected that a new log file is generated, the file name of the new log file and the total number of lines of the new log file are added to the log mapping table according to the creation time of the new log file;
[0061] If it is detected that the log file is updated, the log mapping table is updated according to the content of the updated log file;
[0062] If it is detected that the log file is deleted, the file name and the total number of lines of the corresponding log file in the log mapping table are deleted according to the file name of the deleted log file.
[0063] In a possible implementation manner, the second processing module is further used to:
[0064] According to the termination line number, determining whether the target log file is in the log mapping table;
[0065] If not, expand the log mapping table.
[0066] In a possible implementation manner, the second processing module is further used to:
[0067] Get the file name of the last log file in the log mapping table;
[0068] In the log file directory, obtain other log files whose creation time is later than the last log file;
[0069] Determining the expansion capacity of the log mapping table according to the termination line of the other log files and the current capacity of the log mapping table;
[0070] The current capacity of the log mapping table is expanded according to the expanded capacity.
[0071] In a possible implementation manner, the second processing module is further used to:
[0072] Determining whether the capacity of the log mapping table after expansion exceeds the maximum capacity;
[0073] If so, obtain the last log file that is not in the log mapping table;
[0074] Obtain the log file to be deleted from the log mapping table according to the last log file;
[0075] The file name and the total number of lines of the log file to be deleted are deleted so that the current capacity of the log mapping table is less than or equal to the maximum capacity.
[0076] In a third aspect, an embodiment of the present application provides an electronic device, including: a memory, a processor;
[0077] The memory stores computer-executable instructions;
[0078] The processor executes the computer-executable instructions stored in the memory, so that the processor executes the above first aspect and / or various possible implementations of the first aspect.
[0079] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, in which computer-executable instructions are stored. When the computer-executable instructions are executed by a processor, they are used to implement the first aspect above and / or various possible implementations of the first aspect.
[0080] In a fifth aspect, an embodiment of the present application provides a computer program product, including a computer program, which, when executed by a processor, implements the above first aspect and / or various possible implementation methods of the first aspect.
[0081] The database log reading method, device, storage medium and program product provided by the present application first respond to the log reading instruction, determine the starting line number and the ending line number of the target log file according to the specified page number and the number of lines per page, wherein the log reading instruction carries the specified page number and the number of lines per page; then locate the target log file according to the starting line number, the ending line number and the log mapping table, the log mapping table includes the correspondence between the file name of each log file and the total number of lines; then read the target log file, and merge the contents of the read target log file to display to the user end. Based on the log mapping table, only the necessary log files need to be read, avoiding the full reading of all log files, reducing the time spent on reading log files, thereby improving reading efficiency, reducing user waiting time, and improving user experience. BRIEF DESCRIPTION OF THE DRAWINGS
[0082] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0083] Figure 1 A schematic diagram of an application scenario of the database log reading method provided in this application;
[0084] Figure 2 Schematic diagram of the process of reading database logs provided in this application Figure 1 ;
[0085] Figure 3 Schematic diagram of the process of reading database logs provided in this application Figure 2 ;
[0086] Figure 4 Schematic diagram of the process of reading database logs provided in this application Figure 3 ;
[0087] Figure 5 A schematic diagram of the structure of the database log reading device provided by this application;
[0088] Figure 6 A schematic diagram of the structure of the electronic device provided in this application.
[0089] The above drawings have shown clear embodiments of the present application, which will be described in more detail later. These drawings and text descriptions are not intended to limit the scope of the present application in any way, but to illustrate the concept of the present application to those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION
[0090] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.
[0091] Figure 1 A schematic diagram of an application scenario of the database log reading method provided in this application, such as Figure 1 As shown, in a database instance centralized control system, the content of the database log needs to be presented to the user or other subsystems to facilitate the user or subsystem to monitor the database status or troubleshoot errors. For example, electronic device 100 can be deployed in a database instance centralized control system, and electronic device 200 can be deployed on the user side or other subsystems. Among them, electronic device 100 and electronic device 200 can be computers, servers, smart phones, tablet computers and other devices. This application does not limit the device types of electronic devices 100 and 200. Figure 1 The electronic device 100 and the electronic device 200 in the figure are both shown as computers as examples.
[0092] Combined with the above scenario, it can be seen that in the prior art, the page number and the number of lines are usually specified, and then the log content is displayed to the user in pages. However, since the database logs are distributed in different log files, it is necessary to aggregate the contents of all log files into a temporary file, and then display the contents of the temporary file in pages. However, the existing method requires reading all log files, resulting in large consumption of system resources, and the aggregation and paging processing takes a long time, resulting in long user waiting time, low reading efficiency, and poor user experience.
[0093] The database log reading method provided in this application can read only necessary log files through the constructed log mapping table, avoid reading all log files in full, reduce the time spent on reading log files, thereby improving reading efficiency, reducing user waiting time, and improving user experience.
[0094] The technical solution of the present application and how the technical solution of the present application solves the above-mentioned technical problems are described in detail below with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present application will be described below in conjunction with the accompanying drawings.
[0095] Figure 2 Schematic diagram of the process of reading database logs provided in this application Figure 1 ,like Figure 2 As shown, the method includes:
[0096] S101 , responding to a log reading instruction, determining the start line number and the end line number of a target log file according to a specified page number and the number of lines per page.
[0097] The log reading instruction carries the specified page number and the number of rows per page.
[0098] The user terminal or subsystem that needs to read the database log sends a log reading instruction to the CNC instance centralized management and control system. For example, the electronic device 200 sends a log reading instruction to the electronic device 100. The electronic device 100 receives the log reading instruction and then responds to the log reading instruction. According to the specified page number and the number of lines per page carried by the log reading instruction, the starting line number and the ending line number of the log file that needs to be read are determined, wherein the log file that needs to be read is the target log file.
[0099] S102: Locate the target log file according to the starting line number, the ending line number and the log mapping table.
[0100] The electronic device 100 maintains a log mapping table, which includes the correspondence between the file name of each log file and the total number of lines of the log file. After the electronic device 100 determines the starting line number and the ending line number of the target log file, it searches for the file name of the target log file and the total number of lines of the target log file in the mapping table maintained by itself according to the starting line number and the ending line number of the target log file, and locates the target log file.
[0101] In a possible implementation, the log mapping table may be created in advance, for example, after the system is started, which can reduce the time for the user to query the log file for the first time.
[0102] S103: Read the target log file, merge the contents of the read target log file and display them to the user end.
[0103] After locating the target log file, the found target log file is read, and the contents of all lines of the target log file are read, and the contents of the read target log file are merged and displayed to the user end, for example, the electronic device 100 merges the contents of the read target log file and presents it to the electronic device 200.
[0104] The database log reading method provided in the embodiment of the present application first responds to the log reading instruction, determines the starting line number and the ending line number of the target log file according to the specified page number and the number of lines per page, wherein the log reading instruction carries the specified page number and the number of lines per page; then locates the target log file according to the starting line number, the ending line number and the log mapping table, the log mapping table includes the correspondence between the file name of each log file and the total number of lines; then reads the target log file, and merges the contents of the read target log file to display to the user end. Based on the log mapping table, only the necessary log files need to be read, thereby avoiding the full reading of all log files, reducing the time spent on reading log files, improving reading efficiency, reducing user waiting time, and improving the beneficial effects of user experience.
[0105] Figure 3 Schematic diagram of the process of reading database logs provided in this application Figure 2 ,like Figure 3 As shown, the method includes:
[0106] S201: Determine whether the log reading instruction is received for the first time.
[0107] Receive the log reading instruction sent by the user terminal or the subsystem, and determine whether the log reading instruction is received for the first time. If yes, execute step S202, if no, execute step S203.
[0108] S202: Initialize the log mapping table.
[0109] When it is determined that the log reading instruction is received for the first time, it indicates that the database instance centralized management and control system has not yet executed the database log reading method provided by the embodiment of the present application, that is, it is the first time to query the log file. Therefore, the log mapping table needs to be initialized.
[0110] In a possible implementation manner, a possible implementation manner of step S202 includes:
[0111] First, the initial capacity of the log mapping table is set, that is, the initial capacity of the log mapping table is generated. The initial capacity of the log mapping table refers to the number of mappings set when creating the log mapping table. The mapping between the file name of a log file and its total number of lines is a mapping. It is understandable that the size of the initial capacity can be determined based on the number of log files in actual working conditions, the total number of lines of each log file, and the storage space of the centralized control system, and the embodiments of the present application do not limit it.
[0112] In a possible implementation, the code for initializing the log mapping table may be, for example:
[0113]
[0114] Furthermore, monitoring of each log file in the log file directory is enabled for the purpose of monitoring changes in the log files in the log file directory. The log file directory can be specified according to actual working conditions, and the log files in the log file directory can be read by users or subsystems.
[0115] Then, a log mapping table is generated, that is, a correspondence between the file name of each log file in the log file directory and the total number of lines of each log file is created.
[0116] Specifically, for example, each log file in the log file directory is first obtained, and the total number of lines of each log file is obtained, and then a corresponding relationship between the file name of each log file and the total number of lines of each log file is generated.
[0117] In a possible implementation, the code for generating the log mapping table may be, for example:
[0118]
[0119] In a possible implementation, obtaining each log file includes:
[0120] First, the total number of log files required by the log mapping table is obtained. For example, the total number can be determined based on the initial capacity. Then, the first log file in the log mapping table is obtained. Then, each log file in the log file directory is obtained in sequence according to the first log file and the total number of log files.
[0121] Optionally, after monitoring of each log file in the log file directory is enabled in step S201, when the log file in the log file directory changes, the log mapping table needs to be dynamically updated.
[0122] For example, if the generation of a new log file is detected, the file name of the new log file and its total number of lines are added to the log mapping table according to the creation time of the new log file;
[0123] If it is detected that the log file is updated, the log mapping table is updated according to the content of the updated log file, that is, the file name and the total number of lines of the updated log file in the log mapping table are synchronously updated;
[0124] If it is detected that the log file is deleted, the file name and the total number of rows of the corresponding log file in the log mapping table are deleted according to the file name of the deleted log file.
[0125] Dynamically updating the log mapping table according to the monitoring situation can be understood as maintenance of the log mapping table. In a possible implementation, the code for maintaining the log mapping table can be, for example:
[0126]
[0127]
[0128] S203 , responding to the log reading instruction, determining the start line number and the end line number of the target log file according to the specified page number and the number of lines per page.
[0129] If the judgment result of step S201 is no, or after step S202, step S203 is executed. The possible implementation method, principle and technical effect of step S203 are similar to those of step S102. For details, please refer to the above description and will not be repeated here.
[0130] In a possible implementation, the code for determining the start line number and the end line number of the target log file according to the specified page number and the number of lines per page may be, for example:
[0131]
[0132] S204: Determine whether the target log file is in the log mapping table according to the termination line number.
[0133] It is determined whether the log file to be queried, ie, the target log file, is in the log mapping table according to the termination line number. If so, step S206 is executed. If not, step S205 is executed to expand the log mapping table and then step S206 is executed.
[0134] If the target log file is not in the log mapping table, the capacity is expanded. The corresponding code may be:
[0135]
[0136] S205. Expand the log mapping table.
[0137] When the queried log file is not in the log mapping table, the log mapping table capacity needs to be expanded to accommodate the mapping of the new log file.
[0138] Specifically, first obtain the file name of the last log file in the log mapping table, that is, obtain the file name of the last log file in the log mapping table, then query other log files whose creation time is later than the last log file in the log file directory, and then determine the expansion capacity of the log mapping table based on the termination line of the other queried log files and the current capacity of the log mapping table, and finally expand the current capacity of the log mapping table based on the expansion capacity. Among them, the current capacity refers to the current number of mappings in the log mapping table, and the expansion capacity refers to the number of mappings that need to be expanded.
[0139] In a possible implementation, the code for expanding the log mapping table may be, for example:
[0140]
[0141] When expanding the capacity of the log mapping table and maintaining the log mapping table, it is also necessary to ensure that the current capacity of the log mapping table does not exceed the maximum capacity to maintain system stability.
[0142] Optionally, for example, in the capacity expansion log mapping table, before the current capacity of the log mapping table is expanded according to the capacity expansion, the following is also included: Figure 4 Steps shown. Figure 4 Schematic diagram of the process of reading database logs provided in this application Figure 3 .like Figure 4 As shown, this example includes:
[0143] S301: Determine whether the capacity of the expanded log mapping table exceeds the maximum capacity.
[0144] The capacity of the log mapping table after expansion is judged and compared with the maximum capacity. The maximum capacity refers to the maximum number of mappings that the log mapping table can accommodate, which is determined by the actual working conditions such as the storage space of the centralized control system. By comparison, it is judged whether the capacity of the log mapping table after expansion is greater than or equal to the maximum capacity. If so, step S302 is executed; if not, step S305 is executed.
[0145] S302: Obtain the last log file that is not in the log mapping table.
[0146] Find the location of the file name of the last log file in the log mapping table that is not within the query range of the log mapping table.
[0147] S303: Obtain the log file to be deleted in the log mapping table according to the last log file.
[0148] The search is started from the last log file and then upwards until the number of mapping entries found meets the number of entries required for expansion. The number of mapping entries found is the number of mapping entries of the log file to be deleted, that is, the log file to be deleted is obtained.
[0149] S304: Delete the file name and the total number of lines of the log file to be deleted, so that the current capacity of the log mapping table is less than or equal to the maximum capacity.
[0150] Delete the file names and total number of rows of the log files to be deleted in sequence, so that the current capacity of the log mapping table is less than or equal to the maximum capacity, that is, does not exceed the maximum capacity.
[0151] S305: Expand the current capacity of the log mapping table according to the expanded capacity.
[0152] If the judgment result of step S301 is no, or after step S304, step S305 is executed, that is, when it is determined that the current capacity of the log mapping table does not exceed the maximum capacity, the current capacity is expanded so that the log mapping table can contain more mapping relationships between the file names of log files and their total number of lines.
[0153] From the above description, it can be seen that when the capacity of the log mapping table exceeds the maximum capacity during expansion, some records in the log mapping table need to be deleted to make room for the newly expanded records. The strategy that can be adopted is defined as the maximum capacity strategy, which specifically deletes the records at the end of the log mapping table that are not in the query range.
[0154] In a possible implementation, the code of the maximum capacity strategy may be, for example:
[0155]
[0156] S206: Locate the target log file according to the starting line number, the ending line number and the log mapping table.
[0157] When the judgment result of step S204 is yes, or step S206 is executed after step S205, the possible implementation method, principle and technical effect of step S206 are similar to the possible implementation method, principle and technical effect of step S102. For details, please refer to the aforementioned steps and will not be repeated here.
[0158] In a possible implementation, the code of step S206 may be, for example:
[0159]
[0160]
[0161] S207: Read the target log file, and merge the contents of the read target log file and display them to the user end.
[0162] The possible implementation method, principle and technical effect of step S207 are similar to the possible implementation method, principle and technical effect of step S103. For details, please refer to the aforementioned steps and will not be repeated here.
[0163] In a possible implementation, the code for reading the target log file in step S207 may be, for example:
[0164]
[0165] In a possible implementation, the code for merging and displaying the contents of the read target log file in step S207 may be, for example:
[0166]
[0167] The embodiment of the present application is to establish a mapping table, i.e., a log mapping table, for the file name of the log file and the total number of lines of the log file, calculate the starting line and the ending line of the log file to be read according to the specified page number and the number of lines per page, and then quickly locate the log file to be read and the corresponding number of lines through the log mapping table. Through this indexing method, only the necessary log file content needs to be read, avoiding the query of all log files, which can reduce the time spent on reading log files, improve reading efficiency, reduce user waiting time, and improve user experience.
[0168] Figure 5 The schematic diagram of the structure of the database log reading device provided by this application is as follows: Figure 5 As shown, the database log reading device 40 provided in this embodiment includes:
[0169] The first processing module 401 is used to respond to the log reading instruction and determine the starting line number and the ending line number of the target log file according to the specified page number and the number of lines per page, and the log reading instruction carries the specified page number and the number of lines per page;
[0170] The second processing module 402 is used to locate the target log file according to the starting line number, the ending line number and the log mapping table, where the log mapping table includes the correspondence between the file name and the total number of lines of each log file;
[0171] The reading and display module 403 is used to read the target log file, merge the contents of the read target log file and display them to the user end.
[0172] In a possible implementation manner, the first processing module 401 is further configured to:
[0173] Determine whether the log reading instruction is received for the first time;
[0174] If yes, initialize the log mapping table.
[0175] In a possible implementation manner, the first processing module 401 is further configured to:
[0176] Generate the initial capacity of the log mapping table;
[0177] Enable monitoring of each log file in the log file directory;
[0178] Generate a log mapping table.
[0179] In a possible implementation manner, the first processing module 401 is further configured to:
[0180] Get each log file and get the total number of lines in each log file;
[0181] Generates a correspondence between the file name of each log file and its total number of lines.
[0182] In a possible implementation manner, the first processing module 401 is further configured to:
[0183] Get the total number of log files required by the log mapping table;
[0184] Get the first log file in the log mapping table;
[0185] In the log file directory, get each log file in order according to the first log file and the total number of log files.
[0186] In a possible implementation manner, the first processing module 401 is further configured to:
[0187] If a new log file is detected, the file name and total number of lines of the new log file are added to the log mapping table according to the creation time of the new log file;
[0188] If it is detected that the log file is updated, the log mapping table is updated according to the content of the updated log file;
[0189] If it is detected that the log file is deleted, the file name and the total number of rows of the corresponding log file in the log mapping table are deleted according to the file name of the deleted log file.
[0190] In a possible implementation manner, the second processing module 402 is further configured to:
[0191] According to the termination line number, determine whether the target log file is in the log mapping table;
[0192] If not, expand the log mapping table.
[0193] In a possible implementation manner, the second processing module 402 is further configured to:
[0194] Get the file name of the last log file in the log mapping table;
[0195] In the log file directory, obtain other log files whose creation time is later than the last log file;
[0196] Determine the expansion capacity of the log mapping table according to the termination lines of other log files and the current capacity of the log mapping table;
[0197] The current capacity of the log mapping table is expanded according to the capacity expansion.
[0198] In a possible implementation manner, the second processing module 402 is further configured to:
[0199] Determine whether the capacity of the expanded log mapping table exceeds the maximum capacity;
[0200] If yes, get the last log file that is not in the log mapping table;
[0201] Get the log file to be deleted in the log mapping table according to the last log file;
[0202] Delete the file name and total number of rows of the log file to be deleted so that the current capacity of the log mapping table is less than or equal to the maximum capacity.
[0203] The database log reading device provided in this embodiment can execute the method provided in the above method embodiment, and its implementation principle and technical effect are similar, which will not be described in detail in this embodiment.
[0204] Figure 6 This is a schematic diagram of the structure of the electronic device provided in this application. Figure 6 As shown, the electronic device 50 provided in this embodiment includes: at least one processor 501 and a memory 502. Optionally, the device 50 also includes a communication component 503. The processor 501, the memory 502 and the communication component 503 are connected via a bus 504.
[0205] In a specific implementation process, at least one processor 501 executes the computer-executable instructions stored in the memory 502, so that at least one processor 501 executes the above method.
[0206] The specific implementation process of the processor 501 can be found in the above method embodiment, and its implementation principle and technical effect are similar, so this embodiment will not be repeated here.
[0207] In the above embodiments, it should be understood that the processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), etc. A general-purpose processor may be a microprocessor or any conventional processor. The steps of the method disclosed in the invention may be directly implemented as being executed by a hardware processor, or may be executed by a combination of hardware and software modules in the processor.
[0208] The memory may include a high-speed memory (Random Access Memory, RAM), and may also include a non-volatile memory (Non-volatile Memory, NVM), such as at least one disk memory.
[0209] The bus may be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, the bus in the drawings of the present application is not limited to only one bus or one type of bus.
[0210] The present application also provides a computer program product, including a computer program, which implements the above method when executed by a processor.
[0211] The present application also provides a computer-readable storage medium, in which computer-executable instructions are stored. When a processor executes the computer-executable instructions, the above method is implemented.
[0212] The above-mentioned readable storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk. The readable storage medium can be any available medium that can be accessed by a general or special-purpose computer.
[0213] An exemplary readable storage medium is coupled to a processor so that the processor can read information from the readable storage medium and write information to the readable storage medium. Of course, the readable storage medium can also be a component of the processor. The processor and the readable storage medium can be located in an application specific integrated circuit (Application Specific Integrated Circuits, referred to as: ASIC). Of course, the processor and the readable storage medium can also exist in the device as discrete components.
[0214] The division of units is only a logical function division, and there may be other divisions in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interface, device or unit, which can be electrical, mechanical or other forms.
[0215] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0216] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0217] If the function is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, server, or network device, etc.) to perform all or part of the steps of the methods of each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc. Various media that can store program codes.
[0218] Those skilled in the art can understand that all or part of the steps of implementing the above-mentioned method embodiments can be completed by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, the steps of the above-mentioned method embodiments are executed; and the aforementioned storage medium includes: ROM, RAM, disk or optical disk and other media that can store program codes.
[0219] Finally, it should be noted that those skilled in the art will readily conceive of other embodiments of the present invention after considering the specification and practicing the invention disclosed herein. The present invention is intended to cover any variations, uses or adaptations of the present invention, which follow the general principles of the present invention and include common knowledge or customary technical means in the art not disclosed by the present invention, are not limited to the precise structure described above and shown in the drawings, and may be modified and changed in various ways without departing from the scope thereof. The scope of the present invention is limited only by the appended claims.
Claims
1. A database log reading method, characterized in that: include: In response to a log reading instruction, determining a start line number and an end line number of a target log file according to a specified page number and the number of lines per page, wherein the log reading instruction carries the specified page number and the number of lines per page; Locate the target log file according to the starting line number, the ending line number and a log mapping table, wherein the log mapping table includes a correspondence between the file name and the total number of lines of each log file; The target log file is read, and the contents of the target log file are combined and displayed to the user end.
2. The method according to claim 1, characterized in that Before responding to the log reading instruction, the method further includes: Determine whether the log reading instruction is received for the first time; If so, initialize the log mapping table.
3. The method according to claim 2, characterized in that The initializing the log mapping table includes: Generate an initial capacity of the log mapping table; Enable monitoring of each log file in the log file directory; Generate the log mapping table.
4. The method according to claim 3, characterized in that The generating the log mapping table comprises: Obtain each of the log files, and obtain the total number of lines in each of the log files; Generate a correspondence between the file name of each log file and the total number of lines thereof.
5. The method according to claim 4, characterized in that The obtaining of each log file comprises: Obtain the total number of log files required by the log mapping table; Get the first log file in the log mapping table; In the log file directory, each log file is obtained in sequence according to the first log file and the total number of log files.
6. The method according to claim 5, characterized in that After starting to monitor each log file in the log file directory, the method further includes: If a new log file is detected to be generated, the file name of the new log file and the total number of lines of the new log file are added to the log mapping table according to the creation time of the new log file; If it is detected that the log file is updated, the log mapping table is updated according to the content of the updated log file; If it is detected that the log file is deleted, the file name and the total number of lines of the corresponding log file in the log mapping table are deleted according to the file name of the deleted log file.
7. The method according to any one of claims 2 to 6, characterized in that: After determining the starting line number and the ending line number of the target log file according to the specified page number and the number of lines per page, the method further includes: According to the termination line number, determining whether the target log file is in the log mapping table; If not, expand the log mapping table.
8. The method according to claim 7, characterized in that The expanding the log mapping table includes: Get the file name of the last log file in the log mapping table; In the log file directory, obtain other log files whose creation time is later than the last log file; Determining the expansion capacity of the log mapping table according to the termination line of the other log files and the current capacity of the log mapping table; The current capacity of the log mapping table is expanded according to the expanded capacity.
9. The method according to claim 7, characterized in that: Before the current capacity of the log mapping table is expanded according to the capacity expansion, the method further includes: Determining whether the capacity of the log mapping table after expansion exceeds the maximum capacity; If yes, obtain the last log file that is not in the log mapping table; Obtain the log file to be deleted from the log mapping table according to the last log file; The file name and the total number of lines of the log file to be deleted are deleted so that the current capacity of the log mapping table is less than or equal to the maximum capacity.
10. A database log reading device, characterized in that: include: A first processing module, configured to respond to a log reading instruction and determine a start line number and an end line number of a target log file according to a specified page number and the number of lines per page, wherein the log reading instruction carries the specified page number and the number of lines per page; A second processing module, configured to locate a target log file according to the starting line number, the ending line number, and a log mapping table, wherein the log mapping table includes a correspondence between a file name and a total number of lines of each log file; The reading and display module is used to read the target log file, and merge the read contents of the target log file and display them to the user end.
11. An electronic device, characterized in that: include: Memory, processor; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory, so that the processor performs the method according to any one of claims 1 to 9.
12. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, which are used to implement the method according to any one of claims 1 to 9 when executed by a processor.
13. A computer program product, characterized in that The invention comprises a computer program, which implements the method according to any one of claims 1 to 9 when being executed by a processor.