Log output method and device
By reading and judging the log level through the global log channel, the log output content can be flexibly adjusted without interrupting the running of the application, solving the problem of low log output efficiency and improving the flexibility and efficiency of the log output.
Patent Information
- Application Number
- CN202410271674.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-03-11
- Publication Date
- 2024-08-27
AI Technical Summary
In the existing technology, the adjustment of the log output content is cumbersome and requires interrupting the running of the application program to update the log configuration information, resulting in low log output efficiency.
By calling the global log channel to read the global log level information when receiving a log acquisition request, and judging whether it meets the global log level based on the target log level, if it does, filter the pre-stored log data to output matching logs. Flexibly adjust log content.
Without interrupting the running of the application, the efficiency and flexibility of log output are improved to meet the needs of personalized log acquisition requests.
Smart Images

Figure CN118550786A
Abstract
Description
Technical Field
[0001] This document relates to the field of data processing, and in particular to a log output method and device. Background Art
[0002] The so-called log refers to a collection of certain operations and their results of the objects specified by the system in a time-ordered manner. The log file can be a record of the interaction between the system and its users. It is a data collection method that automatically captures the type, content or time of interaction between people and system terminals.
[0003] In actual applications, users' requirements for log output content are not static. In order to adjust the log output content, it is often necessary to interrupt the operation of the application used to output the log. After the user updates the log configuration information, the application is restarted to output the log according to the updated configuration information. The process is cumbersome and reduces the efficiency of log output. Summary of the invention
[0004] An embodiment of the present specification aims to provide a log output method and device to solve the problem of how to flexibly adjust the log output content.
[0005] To solve the above technical problems, an embodiment of this specification is implemented as follows:
[0006] In a first aspect, an embodiment of the present specification provides a log output method, including:
[0007] When receiving a log acquisition request for an application, the configured global log level information is read by calling a global log channel started by the application; the global log level information represents the common log level information when outputting logs in response to the log acquisition request;
[0008] In the case where it is detected that the log acquisition request carries a target log level, determining whether the target log level meets the log level indicated by the global log level information;
[0009] When the determination result is that the target log level is met, the pre-stored log data is screened and processed according to the target log level, and a target log matching the target log level is obtained and output.
[0010] In a second aspect, another embodiment of the present specification provides a log output device, including:
[0011] A reading unit, configured to read the configured global log level information by calling the global log channel started by the application when receiving a log acquisition request for the application; the global log level information represents the common log level information when outputting logs in response to the log acquisition request;
[0012] A judging unit, configured to judge, when detecting that the log acquisition request carries a target log level, whether the target log level meets the log level indicated by the global log level information;
[0013] The screening unit is used to screen the pre-stored log data according to the target log level when the judgment result is compliance, obtain the target log matching the target log level and output it.
[0014] In a third aspect, another embodiment of the present specification provides a log output device, comprising: a memory, a processor, and computer executable instructions stored on the memory and executable on the processor, wherein the computer executable instructions, when executed by the processor, implement the steps of the log output method as described in the first aspect above.
[0015] In a fourth aspect, another embodiment of the present specification provides a computer-readable storage medium, wherein the computer-readable storage medium is used to store computer-executable instructions, and when the computer-executable instructions are executed by a processor, the steps of the log output method described in the first aspect above are implemented.
[0016] The log output method provided in this embodiment firstly reads the configured global log level information by calling the global log channel started by the application when receiving a log acquisition request for the application; the global log level information represents the common log level information when outputting the log in response to the log acquisition request; then, when it is detected that the log acquisition request carries a target log level, it is determined whether the target log level meets the log level indicated by the global log level information; finally, when the determination result is that it meets the requirements, the pre-stored log data is screened and processed according to the target log level, and the target log matching the target log level is obtained and output. In this way, the target log level can reflect the personalized needs of the log acquisition request for the target log to be output, and the global log level information can reflect the common log level information when responding to any log acquisition request for log output during the application operation. Through the pre-created global log channel, the common log level information can be read when processing any log acquisition request, so that the common log level information can be used for log output in the absence of personalized needs. If the log acquisition request is detected to carry a target log level, it means that there is a personalized need, and it is necessary to determine whether the target log level meets the log level indicated by the global log level information to determine whether the personalized needs of the log acquisition request can be met by the common log level. If the judgment result is met, it means that the personalized needs can be met on the basis of the general log level information, and the pre-stored log data is screened and processed according to the target log level, so that the target log finally output meets the personalized needs of the log acquisition request. Therefore, through the log output method provided by this embodiment, the target log level carried in the log acquisition request can be configured, and the log content of the target log output in response to the log acquisition request can be flexibly adjusted for a single log acquisition request without changing the general log level information. During the processing of the log acquisition request, there is no need to interrupt the operation of the application and manually modify the general log level information, thereby improving the log output efficiency and flexibility. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] In order to more clearly illustrate the technical solutions in one or more embodiments of the present specification, 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 some embodiments recorded in the present specification. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0018] Figure 1 A log output method processing flow chart provided in one embodiment of this specification;
[0019] Figure 2A schematic diagram of a log output system provided in accordance with an embodiment of the present invention;
[0020] Figure 3 A schematic diagram of a log output device provided in one embodiment of this specification;
[0021] Figure 4 A schematic diagram of the structure of a log output device provided in one embodiment of this specification. DETAILED DESCRIPTION
[0022] In order to enable those skilled in the art to better understand the technical solutions in one or more embodiments of this specification, the following will be combined with the drawings in one or more embodiments of this specification to clearly and completely describe the technical solutions in one or more embodiments of this specification. Obviously, the described embodiments are only part of the embodiments of this specification, not all of the embodiments. Based on one or more embodiments of this specification, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of this document.
[0023] This specification provides a log output method embodiment:
[0024] Reference Figure 1 The log output method provided in this embodiment specifically includes the following steps S102 to S106.
[0025] Step S102, when receiving a log acquisition request for an application, reading the configured global log level information by calling the global log channel started by the application; the global log level information represents the common log level information when outputting logs in response to the log acquisition request.
[0026] An application can be any application that can generate and output logs.
[0027] The global log channel may be a user-defined channel pre-created by a user using a programming language. When the number of applications is greater than or equal to one, for each application, the application may be pre-configured with a unique global log channel.
[0028] A channel is a data structure used to communicate between different threads / coroutines. The global log channel can be used to transmit and interact with global log level information.
[0029] After the main program of the application is started, the main program can start a global, unique channel for setting the log level throughout the life cycle of the program, namely the global log channel. The main program of the application is the main entry function of the application. The log level is a classification information used to identify the importance of log information, which determines which logs will be recorded and output.
[0030] By calling the global log channel, you can read the global log level information of one or more pre-configured dimensions. The dimension can represent the classification basis used to divide the log output content into multiple levels.
[0031] The global log level information represents the common log level information when responding to a log acquisition request and outputting logs. The global log level information can be the common log output configuration information when responding to any log acquisition request and outputting logs, that is, the log output configuration information needs to be used to output logs during the process of processing any log acquisition request.
[0032] For example, global log level information of the quantity dimension is pre-configured. Specifically, the log output content can be pre-divided into multiple levels according to the number of log items. In the multiple levels, "1" means that the number of log items to be output is within a first preset number range, "2" means that the number of log items to be output is within a second preset number range, and so on.
[0033] For another example, the global log level information of the data type dimension is pre-configured. Specifically, the log output content can be pre-divided into multiple levels according to the data type. In these multiple levels, "Type 1" indicates that the log content to be output belongs to the first data type, "Type 2" indicates that the log content to be output belongs to the second data type, and so on.
[0034] For example, the definition of the global log channel is as follows:
[0035] Type logLevelChannel struct{
[0036] LevelNumber int / / includes 0-9, the default value is 0
[0037] levelName: string / / includes error, info, debug, and message. The default value is info.
[0038] }
[0039] Among them, logLevelChannel is the name of the custom named channel. Levelnumber and levelName can represent the global log level information of different dimensions respectively. Specifically, LevelNumber is used to represent the log level of the quantity dimension, and levelName is used to represent the log level of the data type dimension. int is used to represent that the character type of the value of LevelNumber is an integer type, and string is used to represent that the character type of the value of levelName is a string type.
[0040] The value of LevelNumber can be an integer between 0 and 9, and the default value is 0. The value of levelName can be error, info, debug, or message, and the default value is info.
[0041] The larger the value of Levelnumber, the more content is output in the log; the smaller the value of Levelnumber, the less content is output in the log. Levelnumber 0 can represent the least content output, and Levelnumber 9 represents the most content output.
[0042] LevelName error means outputting information about errors, LevelName debug means outputting debugging information, LevelName info means outputting ordinary call information, and LevelName message means outputting general program running information.
[0043] The recipient of the log acquisition request can be a specified application. After the main program of the application is started, a global log channel can be automatically started. The life cycle of the global log channel is the entire life cycle of the program, and the global log channel is a channel used globally. During the operation of the application, the global log channel can be called by the log method caller at any time to read the pre-configured global log level information.
[0044] In addition, after creating the global log channel, the user can configure the global log channel. Specifically, during the configuration process, the global log level information of at least one preset dimension can be configured among the multiple preset dimensions defined when creating the global log channel.
[0045] The log acquisition request for an application can be used to request the application to output logs.
[0046] Log acquisition requests for applications can be triggered by real-time user input or automatically generated when a specified type of data operation is detected.
[0047] For example, when a user inputs a keystroke to an application, a log acquisition request for the application is generated based on the keystroke input. Or, when an application receives a data processing request, and the response flow of the data processing request depends on local data in the pre-stored log information, a log acquisition request for the application is automatically generated.
[0048] Based on similar technical concepts, the above step S102 can also be replaced as follows: during the code execution process, if a preset code segment is detected, the configured global log level information is read by calling the global log channel started by the application; the global log level information represents the common log level information when outputting logs in response to a log acquisition request; and it forms a new implementation method with other processing steps in this embodiment.
[0049] For example, a user writes a long string of code for an application to execute. For ease of description, the long string of code can be called a to-be-executed file. The to-be-executed file includes three preset code segments, and the positions of the three preset code segments in the to-be-executed file are different. During the running of the to-be-executed file, if the application detects the first preset code segment at the first time point, it reads the pre-configured global log level information by calling the global log channel and executes the subsequent log output process; if the application detects the second preset code segment at the second time point, it reads the pre-configured global log level information by calling the global log channel and executes the subsequent log output process; if the application detects the third preset code segment at the third time point, it reads the pre-configured global log level information by calling the global log channel and executes the subsequent log output process.
[0050] Step S104: when it is detected that the log acquisition request carries a target log level, it is determined whether the target log level meets the log level indicated by the global log level information.
[0051] During the running of the application, the global log level information may be the common log output configuration information used by the application when outputting logs in response to any log acquisition request, and the target log level may describe the personalized requirements of a single log acquisition request.
[0052] The global log level information represents the common log level information when outputting logs in response to a log acquisition request, and the log level indicated by the global log level information refers to one or more log levels read from the common log level information.
[0053] It should be noted that whether the application can meet the personalized needs of a single log acquisition request when outputting logs needs to be determined by the global log level information. If the personalized needs can be met, the application will output logs. If the personalized needs cannot be met, the application will reject the log acquisition request.
[0054] A log acquisition request may or may not carry a target log level. The target log level can be a one-time log level for a single log acquisition request, describing the personalized needs of the log acquisition request. For each log acquisition request, the target log level carried by the log acquisition request will not change the global log level information, nor will it affect the log output process of other log acquisition requests other than the log acquisition request.
[0055] By judging whether the target log level meets the log level indicated by the global log level information, it can be determined whether the personalized needs of the log acquisition request can be met by the general log output configuration information; if the personalized needs of the log acquisition request can be met by the general log output configuration information, step S106 is executed; if the personalized needs of the log acquisition request cannot be met by the general log output configuration information, the log acquisition request is rejected.
[0056] In actual applications, the application can use the method provided by the log toolkit to execute the step of "reading the configured global log level information by calling the global log channel started by the application" and step S104.
[0057] For example, Log is a log toolkit that can provide the V() method, which can determine the log level, and can also provide the println method to print the log content. log.V is a method for determining the log level. When the application runs to log.V, the V() method will check whether the current content in its brackets meets the log level required by the global log level information.
[0058] Code Example 1: Log.V(3).println("The log level of this output is 3")
[0059] When executing the above code example 1, the application can extract the value "3" in the brackets of "V(3)" as the target log level, and can also read the pre-configured global log level information by calling the global log channel. If the global log channel has "levelNumber 4", it can be seen that 3<4, then the target log level meets the log level indicated by the global log level information, and log.V(3) will output content. If the global log channel has "levelNumber 2", it can be seen that 3>2, then the target log level does not meet the log level indicated by the global log level information, and log.V(3) will not output content.
[0060] Code Example 2: Log.V("error").println("The log level of this output is error")
[0061] When executing the above code example 2, the application can extract the string "error" in the brackets of "V("error")" as the target log level, and can also read the pre-configured global log level information by calling the global log channel. If the global log channel has "levelName error", then log.V("error") is the same as levelName, the target log level meets the log level indicated by the global log level information, and log.V("error") will output content. If the global log channel has "levelName debug", then log.V("error") is different from levelName, the target log level does not meet the log level indicated by the global log level information, and log.V("error") will not output content.
[0062] During the code execution process, the application will run the log.V() function each time it executes a code segment with log.V(), thereby achieving the purpose of dynamically adjusting the log level based on the general log output configuration information and the personalized needs of each log acquisition request.
[0063] For example, a user writes a long string of code for an application to execute. For ease of description, this long string of code can be called a to-be-executed file. During the execution of the to-be-executed file, many operations require calling log.V. In one place, only a simple variable definition is required, and the number of log entries to be output is very low, so log.V(1) is pre-written. In another place, a complex external data processing request needs to be processed, and the specific amount of data to be sent and received needs to be known. The number of log entries to be output is very high, so log.V(8) is pre-written.
[0064] In a specific implementation, the target log level includes a first log level in a quantity dimension; determining whether the target log level meets the log level indicated by the global log level information includes: determining a second log level in the quantity dimension in the global log level information; if the first log level is less than or equal to the second log level, determining that the target log level meets the log level indicated by the global log level information; if the first log level is greater than the second log level, determining that the target log level does not meet the log level indicated by the global log level information.
[0065] The first log level in the quantity dimension may describe a preset quantity range within which the number of log items that the log acquisition request requests to output to the application falls.
[0066] The global log level information may include log levels of multiple preset dimensions. The quantity dimension may be one of the multiple preset dimensions.
[0067] The second log level of the quantity dimension may describe a preset quantity range of the maximum number of log entries allowed to be output that is preconfigured by the application.
[0068] It should be noted that, for different preset dimensions, the criteria for determining whether the target log level meets the log level indicated by the global log level information may be different or may be different.
[0069] In terms of quantity, the target log level complies with the log level indicated by the global log level information, and the value of the first log level may be less than or equal to the value of the second log level.
[0070] The first log level and the second log level are compared and processed according to the numerical values. If the first log level is less than or equal to the second log level, it means that the personalized demand of the log acquisition request can be met by the general log output configuration information, and the target log level is determined to be consistent with the log level indicated by the global log level information; if the first log level is greater than the second log level, it means that the personalized demand of the log acquisition request cannot be met by the general log configuration information, and the target log level is determined to be inconsistent with the log level indicated by the global log level information.
[0071] For example, "LevelNumber 5" in the global log channel, that is, the value of the second log level is "5", when the value of the first log level is any integer between 0-5, it can be determined that the target log level meets the log level indicated by the global log level information. When the value of the first log level is any integer between 6-9, it can be determined that the target log level does not meet the log level indicated by the global log level information.
[0072] It should be noted that, when the first log level is less than the second log level, the first log level can be used as the target log level, considering that the first log level is less than the target log level, indicating that the number of log items to be output by the log acquisition request is less than the number of log items in the general configuration, so the pre-stored log data can be screened based on the number of log items in the general configuration to reduce the number of log items actually output to meet the personalized needs of the log acquisition request. The number of log items in the pre-stored log data can be reduced by screening, but cannot be increased, so when the first log level is greater than the second log level, the personalized needs of the log acquisition request cannot be met by the general log configuration information.
[0073] In a specific implementation, the target log level includes a third log level of a data type dimension; determining whether the target log level meets the log level indicated by the global log level information includes: determining a fourth log level of the data type dimension in the global log level information; performing comparison processing on the third log level and the fourth log level to obtain a comparison result; if the comparison result indicates that the third log level is consistent with the fourth log level, then determining that the target log level meets the log level indicated by the global log level information; if the comparison result indicates that the third log level is inconsistent with the fourth log level, then determining that the target log level does not meet the log level indicated by the global log level information.
[0074] In the global log level information, the number of the fourth log level of the data type dimension may be one or more.
[0075] With respect to the data type dimension, the target log level complies with the log level indicated by the global log level information, and the data type corresponding to the third log level may be the same as the data type corresponding to the fourth log level.
[0076] When there are multiple fourth log levels in the data type dimension, the third log level can be compared with each of the multiple fourth log levels to obtain a comparison result; if the comparison result indicates that the third log level is consistent with one of the multiple fourth log levels, it means that the personalized needs of the log acquisition request can be met by the general log output configuration information, and then it is determined that the target log level meets the log level indicated by the global log level information; if the comparison result indicates that the third log level is different from the multiple fourth log levels, it means that the personalized needs of the log acquisition request cannot be met by the general log configuration information, and then it is determined that the target log level does not meet the log level indicated by the global log level information.
[0077] In a specific implementation, the log output method further includes: if it is determined that the log acquisition request does not carry the target log level, outputting the log according to the log level read from the global log level information.
[0078] The log level read from the global log level information can be a common log level when processing any log acquisition request.
[0079] In the case where the global log level information includes log levels of multiple preset dimensions, one or more log levels of the preset dimensions may be pre-selected as a common log level for use when processing a log acquisition request that does not carry a target log level.
[0080] When processing any log acquisition request, log output is performed by default according to the log level in the global log level information (for example, log level 8). If a log acquisition request carries a target log level (for example, log level 3), the target log level is a one-time log level used in the process of processing the log acquisition request, and will become invalid after the log acquisition request is processed. In the process of log output for the log acquisition request, the log level 8 in the global log level information is not changed to log level 3. When the next log acquisition request is received, if the next request does not carry the target log level, the log output is still performed according to the log level 8 stored in the global log channel.
[0081] Step S106, when the determination result is compliance, the pre-stored log data is screened according to the target log level, and a target log matching the target log level is obtained and output.
[0082] The pre-stored log data may be log data of an application generated and stored according to general log output configuration information.
[0083] The judgment result of compliance means that the target log level complies with the log level indicated by the global log level information; the judgment result of non-compliance means that the target log level does not comply with the log level indicated by the global log level information.
[0084] When the target log level is the first log level in the quantity dimension, the target log matching the target log level means that the number of log entries of the target log is within the target preset quantity range corresponding to the target log level.
[0085] When the target log level is the first log level of the quantity dimension, the pre-stored log data is filtered according to the target log level to obtain the target log. The pre-stored log data can be filtered according to the preset filtering method of the quantity dimension to obtain the target log, and the number of log entries in the target log is within the target preset quantity range.
[0086] For example, the target log level can be expressed as "LevelNumber 2", and the target preset number range corresponding to the target log level can be expressed as [x1, x2]. The number of logs in the pre-stored log data is N, and the pre-stored log data is filtered and processed according to the preset filtering method of the quantity dimension to obtain the target log. The number of target logs n is in [x1, x2], and n is less than or equal to N. x1, x2, N, n are all natural numbers greater than 0.
[0087] Exemplarily, the pre-stored log data is filtered according to a preset filtering method in the quantity dimension to obtain a target log. The priority order of each log type in the pre-stored log data can be determined, and the log data of the first log type is removed from the pre-stored log data according to the priority order. The number of log entries of the remaining log data is compared with the boundary value of the target preset quantity range. If it is determined based on the comparison result that the remaining log data is within the target preset quantity range, the filtering is stopped and the remaining target log data is determined as the target log. If it is determined based on the comparison result that the remaining log data is greater than the maximum value of the target preset quantity range, the log data of the next log type is removed from the pre-stored log data according to the priority order… until the remaining log data is within the target preset quantity range, and the remaining target log data is determined as the target log.
[0088] The pre-stored log data is filtered and processed according to a preset filtering method of the quantity dimension to obtain the target log. Alternatively, a target sampling ratio is determined based on the second log level and the first log level, and the pre-stored log data is sampled and processed according to the target sampling ratio to obtain the target log.
[0089] In the case where the target log level is the third log level of the data type dimension, the target log that matches the target log level means that the data type of the target log is the same as the data type corresponding to the target log level.
[0090] When the target log level is the third log level of the data type dimension, the pre-stored log data is filtered and processed according to the target log level to obtain the target log. The pre-stored log data can be filtered and processed according to the preset filtering method of the data type dimension to obtain the target log, and the data type of the target log is consistent with the third log level.
[0091] The pre-stored log data is filtered according to a preset filtering method of the data type dimension to obtain the target log, which may be to determine the target data type corresponding to the third log level, and filter the pre-stored log data according to the target data type to obtain the target log.
[0092] In a specific implementation, the log acquisition request includes a log output destination address; the pre-stored log data is filtered and processed according to the target log level to obtain a target log that matches the target log level and output it, including: the pre-stored log data is filtered and processed according to the target log level to obtain a target log; and the target log is output according to the log output destination address.
[0093] The log output destination address is used to indicate the destination address for the application to output logs, that is, the log acquisition request expects the application to output the target log and store it at the destination address.
[0094] Outputting the target log according to the log output destination address may be outputting the target log and storing it at the log output destination address.
[0095] The log output destination address may be address information for storing log files.
[0096] The log output destination address can also be replaced by the file name of the log file. The application can query the address information of the stored log file based on the file name. There is a corresponding relationship between the file name and the address information of the stored log file. The application can query the unique address information of the stored log file based on the file name and the corresponding query.
[0097] For example, during the code execution, after log.V(x) is executed, if it is determined that x meets the general log configuration information, the log is output to the standard output or to a specified log file. x is a custom-written character or string.
[0098] Among them, log.V(x).println("xxxxx") means outputting logs to standard output.
[0099] log.V(x).file(" / data1 / log / access.log") means outputting logs to the specified log file " / data1 / log / access.log".
[0100] In a specific implementation, the log output method further includes: if it is determined that the target log level does not meet the log level indicated by the global log level information, generating prompt information; the prompt information is used to prompt the user that the target log output corresponding to the log acquisition request fails.
[0101] The target log level does not meet the log level indicated by the global log level information, indicating that the personalized requirements of the log acquisition request cannot be met by the general log output configuration information. In this case, a prompt message can be generated to prompt the user that the target log output corresponding to the log acquisition request has failed.
[0102] The prompt information may also include a failure reason for the target log output failure, which may be determined by a comparison result between the target log level and the global log level information.
[0103] For example, the target log level includes "LevelNumber 4", the global log level information includes "LevelNumber3", 3<4, so it can be determined that the reason for the failure of the target log output is that the log level of the pre-configured quantity dimension in the global log channel is too low.
[0104] In a specific implementation, the log output method also includes: receiving a global information update instruction; parsing the global information update instruction to obtain dimension index information corresponding to the global information update instruction and a preset log level corresponding to the global update instruction; determining a target dimension corresponding to the global information update instruction from multiple preset dimensions based on the dimension index information; and updating the global log level information of the target dimension based on the preset log level.
[0105] The application receiving the log acquisition request may call the log adjustment service. The log adjustment service may be an http service. The log adjustment service may provide one or more interfaces. In the case where the log adjustment service may provide multiple interfaces, each interface may correspond to a preset dimension of the custom configuration when creating a global log channel.
[0106] Exemplarily, the log adjustment service may provide the following interface:
[0107] (1)http: / / localhost:8888 / ?loglevelnumber interface
[0108] (2)http: / / localhost:8888 / ?loglevelName interface
[0109] The above interface (1) corresponds to the quantity dimension of the custom configuration when creating a global log channel, and the above interface (2) corresponds to the data type dimension of the custom configuration when creating a global log channel.
[0110] Users can adjust the global log level information in the global log channel by triggering the application to call the log adjustment service interface.
[0111] Receiving the global information update instruction may be receiving a target instruction text written by a user, or may be determining a target instruction text selected by the user based on a user input and a pre-configured correspondence between the user input and the instruction text.
[0112] Exemplarily, the target instruction text 1 may be:
[0113] Curl http: / / localhost:8888 / ? loglevelnumber=2
[0114] Assuming that before receiving the global information update instruction, the value of "loglevelNumber" in the global log channel is "4", the target instruction text 1 can be used to adjust the value of "loglevelNumber" in the global log channel from "4" to "2".
[0115] Before receiving the global information update instruction, when executing a line of code log.v(3), the application extracts "3" from log.v(3) as the first log level, calls the global log channel to read "loglevelNumber 4", and uses "4" as the second log level. 3<4, the application can output the corresponding target log when executing log.v(3).
[0116] After receiving the global information update instruction, the application extracts "3" from log.v(3) as the first log level when executing another line of code log.v(3), calls the global log channel to read "loglevelNumber 2", and uses "2" as the second log level. 3>2, so the application fails to output the target log when executing log.v(3).
[0117] Exemplarily, the target instruction text 2 may be:
[0118] Curl http: / l / localhost:8888 / ? Loglevelname=debug
[0119] Assuming that before receiving the global information update instruction, the value of "loglevelName" in the global log channel is "error", the target instruction text 2 can be used to adjust the value of "loglevelName" in the global log channel from "error" to "debug".
[0120] Before receiving the global information update instruction, when executing a line of code log.v(error), the application extracts "error" from log.v(error) as the third log level, calls the global log channel to read "loglevelNameerror", and uses "error" as the fourth log level. After comparison, it is determined that the third log level is consistent with the fourth log level. Then, the application can output the corresponding target log when executing log.v(error).
[0121] After receiving the global information update instruction, when executing another line of code log.v(error), the application extracts "error" from log.v(error) as the third log level, calls the global log channel to read "loglevelNamedebug", and uses "debug" as the fourth log level. After comparison, it is determined that the third log level is inconsistent with the fourth log level. In this case, the application fails to output the target log when executing log.v(error).
[0122] The global information update instruction is parsed and processed to obtain dimension index information corresponding to the global information update instruction and a preset log level corresponding to the global update instruction.
[0123] For example, the target instruction text 1 is Curl http: / / localhost:8888 / ?loglevelnumber=2, and the target instruction text 1 is parsed to obtain the dimension index information “?loglevelnumber” and the preset log level “2”.
[0124] According to the dimension index information, a target dimension corresponding to the global information update instruction is determined from a plurality of preset dimensions.
[0125] Multiple preset dimensions can be custom configured when creating a global log channel.
[0126] There is a corresponding relationship between the dimension index information and the preset dimension.
[0127] The dimension index information may be the name of a preset dimension, may be an identifier of a preset dimension, or may be a character string obtained by concatenating the name of the preset dimension and specified characters.
[0128] According to the dimension index information and the correspondence between the pre-configured dimension index information and the preset dimension, a target dimension that uniquely corresponds to the dimension index information may be determined from among multiple preset dimensions.
[0129] According to the preset log level, the global log level information of the target dimension is updated, and the historical log level in the global log level information of the target dimension is replaced by the preset log level.
[0130] By triggering the application to call the interface of the log adjustment service through the global information update instruction to update the global log level information in the global log channel, the hot update of the general log configuration information can be completed without interrupting the operation of the application.
[0131] In actual applications, in the process of migrating departmental projects to containers, more and more projects need to be migrated to containerized platforms. Considering that the Kubernetes of the containerized platform is deployed on a virtualization cluster, the increase in the number of projects and the number of Kubernetes clusters may lead to a substantial increase in the demand for observing the relationship between the virtual machines on the Kubernetes cluster and the physical machines corresponding to the virtual machines. In order to meet the growing demand for observation, it is often necessary to obtain log data frequently. In different operation steps, the content of the log data required for observation is not static. Some steps may only require a small amount of data, some steps may require very specific data, and some steps may require data of a specific data type, and so on. Therefore, a log output method is needed, which can flexibly adjust the log content output by the application without interrupting the operation of the application, and improve the efficiency of log output, so as to better meet the observation needs and promptly discover anomalies that occur during the operation of the application.
[0132] Virtualization can be a service system that uses one or more virtualization software to provide the addition, deletion, modification and query of virtual machines. A virtual machine can be a simulated computer or server created by virtualization software, such as qemu. A physical machine can be a real computer or server that exists in the real world. Kubernetes can be a container orchestration management tool. A container image is a lightweight, independent executable software package of a software that contains everything needed to run it, such as code, system tools, system libraries, settings, etc. A container is the running state of a program in a container image.
[0133] In summary, the log output method provided by the present embodiment, first, when receiving a log acquisition request for an application, reads the configured global log level information by calling the global log channel started by the application; the global log level information represents the common log level information when outputting logs in response to the log acquisition request; then, when it is detected that the log acquisition request carries a target log level, it is determined whether the target log level meets the log level indicated by the global log level information; finally, when the determination result is that it meets the requirements, the pre-stored log data is screened and processed according to the target log level, and the target log matching the target log level is obtained and output. In this way, the target log level can reflect the personalized needs of the log acquisition request for the target log to be output, and the global log level information can reflect the common log level information when responding to any log acquisition request for log output during the application operation. Through the pre-created global log channel, the common log level information can be read when processing any log acquisition request, so that the common log level information can be used for log output in the absence of personalized needs. If the log acquisition request is detected to carry a target log level, it means that there is a personalized need, and it is necessary to determine whether the target log level meets the log level indicated by the global log level information to determine whether the personalized needs of the log acquisition request can be met by the common log level. If the judgment result is met, it means that the personalized needs can be met on the basis of the general log level information, and the pre-stored log data is screened and processed according to the target log level, so that the target log finally output meets the personalized needs of the log acquisition request. Therefore, through the log output method provided by this embodiment, the target log level carried in the log acquisition request can be configured, and the log content of the target log output in response to the log acquisition request can be flexibly adjusted for a single log acquisition request without changing the general log level information. During the processing of the log acquisition request, there is no need to interrupt the operation of the application and manually modify the general log level information, thereby improving the log output efficiency and flexibility.
[0134] Based on the same technical concept, the embodiment of the present application also provides another log output system. Figure 2 A schematic diagram of a log output system according to an embodiment of the present invention.
[0135] like Figure 2 As shown, after the main program 202 of the application is started, the log level global channel 204 can be started.
[0136] Log level global channel 204 can refer to Figure 1 The corresponding description part of the global log channel in the embodiment.
[0137] When receiving the log acquisition request, the application program may call the log level global channel 204 through the log method caller 206 to read the pre-configured global log level information.
[0138] When the log acquisition request carries the target log level, the application may perform log output processing according to the target log level and the global log level information to obtain log output content 208 .
[0139] The log output content 208 can be found in Figure 1 The corresponding description part of the target log in the embodiment.
[0140] Specifically, the application can determine whether the target log level meets the log level indicated by the global log level information: if the judgment result is that it meets the requirements, the pre-stored log data is filtered and processed according to the target log level to obtain the log output content 208 that matches the target log level; if the judgment result is that it does not meet the requirements, a prompt message is generated, and the prompt message is used to prompt the user that the output of the log output content 208 corresponding to the log acquisition request has failed.
[0141] When the log acquisition request does not carry the target log level, the application can perform log output processing according to the global log level information to obtain log output content 208.
[0142] The user 210 may send a global information update instruction to the application, and the global information update instruction may be used to trigger the main program 202 of the application to call the interface of the log adjustment service 212 to adjust the global log level information in the log level global channel 204 .
[0143] Since the technical concept is the same, the description in this embodiment is relatively simple, and the relevant parts may refer to the corresponding description of the method embodiment provided above.
[0144] Figure 3 A schematic diagram of a log output device provided by an embodiment of the present invention is shown in FIG. Figure 3 As shown, the log output device 300 includes:
[0145] The reading unit 302 is used to read the configured global log level information by calling the global log channel started by the application when receiving a log acquisition request for the application; the global log level information represents the common log level information when the log is output in response to the log acquisition request;
[0146] The judging unit 304 is configured to judge whether the target log level meets the log level indicated by the global log level information when detecting that the log acquisition request carries a target log level;
[0147] The screening unit 306 is used to screen the pre-stored log data according to the target log level when the determination result is compliance, obtain the target log that matches the target log level and output it.
[0148] Optionally, the target log level includes a first log level in a quantity dimension; when the judging unit 304 judges whether the target log level meets the log level indicated by the global log level information, the judging unit 304 performs the following steps:
[0149] Determine a second log level of quantity dimension in the global log level information;
[0150] If the first log level is less than or equal to the second log level, determining that the target log level meets the log level indicated by the global log level information;
[0151] If the first log level is greater than the second log level, it is determined that the target log level does not meet the log level indicated by the global log level information.
[0152] Optionally, the target log level includes a third log level of a data type dimension; when determining whether the target log level meets the log level indicated by the global log level information, the determining unit 304 performs the following steps:
[0153] Determining a fourth log level of a data type dimension in the global log level information;
[0154] Comparing the third log level and the fourth log level to obtain a comparison result;
[0155] If the comparison result indicates that the third log level is consistent with the fourth log level, determining that the target log level is consistent with the log level indicated by the global log level information;
[0156] If the comparison result indicates that the third log level is inconsistent with the fourth log level, it is determined that the target log level does not conform to the log level indicated by the global log level information.
[0157] Optionally, the log output device 300 further includes:
[0158] A receiving unit, used for receiving a global information update instruction;
[0159] A parsing unit, configured to parse the global information update instruction to obtain dimension index information corresponding to the global information update instruction and a preset log level corresponding to the global update instruction;
[0160] a determining unit, configured to determine, according to the dimension index information, a target dimension corresponding to the global information update instruction from a plurality of preset dimensions;
[0161] An updating unit is used to update the global log level information of the target dimension according to the preset log level.
[0162] Optionally, the log output device 300 further includes:
[0163] The generating unit is used to generate prompt information if it is determined that the target log level does not meet the log level indicated by the global log level information; the prompt information is used to prompt the user that the output of the target log corresponding to the log acquisition request fails.
[0164] Optionally, the log acquisition request includes a log output destination address; when the screening unit 306 screens the pre-stored log data according to the target log level, obtains and outputs a target log matching the target log level, the following steps are performed:
[0165] Filter and process the pre-stored log data according to the target log level to obtain the target log;
[0166] The target log is output according to the log output destination address.
[0167] Optionally, the screening unit 306 is further used for:
[0168] If it is determined that the log acquisition request does not carry the target log level, log output is performed according to the log level read from the global log level information.
[0169] The log output device provided by this embodiment includes: a reading unit, which is used to read the configured global log level information by calling the global log channel started by the application when receiving a log acquisition request for the application; the global log level information represents the common log level information when the log is output in response to the log acquisition request; a judgment unit, which is used to judge whether the target log level meets the log level indicated by the global log level information when it is detected that the log acquisition request carries a target log level; and a screening unit, which is used to screen the pre-stored log data according to the target log level when the judgment result is that it meets the target log level, obtain the target log that matches the target log level and output it. In this way, the target log level can reflect the personalized needs of the log acquisition request for the target log to be output, and the global log level information can reflect the common log level information when responding to any log acquisition request for log output during the application operation. Through the pre-created global log channel, the common log level information can be read when processing any log acquisition request, so that the common log level information can be used for log output in the absence of personalized needs. If the log acquisition request is detected to carry a target log level, it means that there is a personalized need, and it is necessary to determine whether the target log level meets the log level indicated by the global log level information to determine whether the personalized needs of the log acquisition request can be met by the common log level. If the judgment result is met, it means that the personalized needs can be met on the basis of the general log level information, and the pre-stored log data is screened and processed according to the target log level, so that the target log finally output meets the personalized needs of the log acquisition request. Therefore, through the log output method provided by this embodiment, the target log level carried in the log acquisition request can be configured, and the log content of the target log output in response to the log acquisition request can be flexibly adjusted for a single log acquisition request without changing the general log level information. During the processing of the log acquisition request, there is no need to interrupt the operation of the application and manually modify the general log level information, thereby improving the log output efficiency and flexibility.
[0170] The log output device provided in an embodiment of this specification can implement each process in the aforementioned method embodiment and achieve the same functions and effects, which will not be repeated here.
[0171] Furthermore, an embodiment of the present specification also provides a log output device, Figure 4 A structural diagram of a log output device provided in an embodiment of this specification, such as Figure 4As shown, the device includes: a memory 401, a processor 402, a bus 403 and a communication interface 404. The memory 401, the processor 402 and the communication interface 404 communicate through the bus 403, and the communication interface 404 may include an input and output interface, which includes but is not limited to a keyboard, a mouse, a display, a microphone, a loudspeaker, etc.
[0172] Figure 4 In the embodiment, the memory 401 stores computer executable instructions that can be run on the processor 402. When the computer executable instructions are executed by the processor 402, the following process is implemented:
[0173] When receiving a log acquisition request for an application, the configured global log level information is read by calling a global log channel started by the application; the global log level information represents the common log level information when outputting logs in response to the log acquisition request;
[0174] In the case where it is detected that the log acquisition request carries a target log level, determining whether the target log level meets the log level indicated by the global log level information;
[0175] When the determination result is that the target log level is met, the pre-stored log data is screened and processed according to the target log level, and a target log matching the target log level is obtained and output.
[0176] The log output device provided in an embodiment of this specification can implement each process in the aforementioned method embodiment and achieve the same functions and effects, which will not be repeated here.
[0177] Furthermore, another embodiment of the present specification provides a computer-readable storage medium, wherein the computer-readable storage medium is used to store computer-executable instructions, and when the computer-executable instructions are executed by a processor, the following process is implemented:
[0178] When receiving a log acquisition request for an application, the configured global log level information is read by calling a global log channel started by the application; the global log level information represents the common log level information when outputting logs in response to the log acquisition request;
[0179] In the case where it is detected that the log acquisition request carries a target log level, determining whether the target log level meets the log level indicated by the global log level information;
[0180] When the determination result is that the target log level is met, the pre-stored log data is screened and processed according to the target log level, and a target log matching the target log level is obtained and output.
[0181] The computer-readable storage medium includes a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.
[0182] The computer-readable storage medium provided in an embodiment of this specification can implement each process in the aforementioned method embodiment and achieve the same functions and effects, which will not be repeated here.
[0183] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-readable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0184] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0185] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0186] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0187] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0188] Memory may include non-permanent storage in a computer-readable storage medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. Memory is an example of a computer-readable storage medium.
[0189] Computer-readable storage media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer-readable instructions, data structures, program modules or other data. Examples of computer-readable storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable storage media does not include temporary computer-readable media (transitory media), such as modulated data signals and carrier waves.
[0190] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity 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, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
[0191] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.
[0192] The above is only an embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included in the scope of the claims of the present application.
Claims
1. A log output method, characterized in that: include: When receiving a log acquisition request for an application, reading the configured global log level information by calling a global log channel started by the application; The global log level information represents the common log level information when outputting logs in response to a log acquisition request; In the case where it is detected that the log acquisition request carries a target log level, determining whether the target log level meets the log level indicated by the global log level information; When the determination result is that the target log level is met, the pre-stored log data is screened and processed according to the target log level, and a target log matching the target log level is obtained and output.
2. The method according to claim 1, characterized in that The target log level includes a first log level in a quantity dimension; and the determining whether the target log level meets the log level indicated by the global log level information includes: Determine a second log level of quantity dimension in the global log level information; If the first log level is less than or equal to the second log level, determining that the target log level meets the log level indicated by the global log level information; If the first log level is greater than the second log level, it is determined that the target log level does not meet the log level indicated by the global log level information.
3. The method according to claim 1, characterized in that The target log level includes a third log level of a data type dimension; and the determining whether the target log level meets the log level indicated by the global log level information includes: Determining a fourth log level of a data type dimension in the global log level information; Comparing the third log level and the fourth log level to obtain a comparison result; If the comparison result indicates that the third log level is consistent with the fourth log level, determining that the target log level is consistent with the log level indicated by the global log level information; If the comparison result indicates that the third log level is inconsistent with the fourth log level, it is determined that the target log level does not conform to the log level indicated by the global log level information.
4. The method according to claim 1, characterized in that Also includes: Receive global information update instructions; Parsing the global information update instruction to obtain dimension index information corresponding to the global information update instruction and a preset log level corresponding to the global update instruction; Determining, according to the dimension index information, a target dimension corresponding to the global information update instruction from a plurality of preset dimensions; According to the preset log level, the global log level information of the target dimension is updated.
5. The method according to claim 1, characterized in that Also includes: If it is determined that the target log level does not meet the log level indicated by the global log level information, generating prompt information; The prompt information is used to prompt the user that the target log output corresponding to the log acquisition request fails.
6. The method according to claim 1, characterized in that The log acquisition request includes a log output destination address; The filtering and processing of the pre-stored log data according to the target log level to obtain and output a target log matching the target log level includes: Filter and process the pre-stored log data according to the target log level to obtain the target log; The target log is output according to the log output destination address.
7. The method according to claim 1, characterized in that The method further comprises: When it is detected that the log acquisition request does not carry the target log level, log output is performed according to the log level read from the global log level information.
8. A log output device, characterized in that: include: A reading unit, configured to read the configured global log level information by calling the global log channel started by the application when receiving a log acquisition request for the application; The global log level information represents the common log level information when outputting logs in response to a log acquisition request; A judging unit, configured to judge, when detecting that the log acquisition request carries a target log level, whether the target log level meets the log level indicated by the global log level information; The screening unit is used to screen the pre-stored log data according to the target log level when the judgment result is compliance, obtain the target log matching the target log level and output it.
9. A log output device, characterized in that: It comprises a memory and a processor, wherein the memory stores computer executable instructions, and when the computer executable instructions are executed on the processor, the steps of the log output method described in any one of claims 1 to 7 can be implemented.
10. A computer-readable storage medium having computer-executable instructions stored therein, characterized in that: When the computer executable instructions are executed by a processor, the steps of the log output method described in any one of claims 1 to 7 can be implemented.
