Log printing method and device, electronic equipment and readable storage medium

The log printing parameters entered by users are processed through pre-encapsulated log printing classes and singleton mode, and the log printing process is simplified in combination with the factory mode, which solves the problem of low log printing efficiency in the existing technology, and realizes an efficient and simplified log printing process and compatibility.

CN118939207APending Publication Date: 2024-11-12NETEASE (HANGZHOU) NETWORK CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411001136.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-24
Publication Date
2024-11-12

AI Technical Summary

Technical Problem

In the prior art, the log printing method requires the user to manually write different instructions and configuration parameters, resulting in an increase in learning time and affecting the log printing efficiency.

Method used

The pre-encapsulated log printing class receives and processes the log printing parameters entered by the user, creates a log printing instance, simplifies the log printing process with singleton mode and factory mode, and automatically obtains the software version for compatibility processing.

Benefits of technology

It effectively reduces user editing and learning time, improves log printing efficiency, saves hardware resources, simplifies instance construction steps, and improves log acquisition efficiency and compatibility.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118939207A_ABST
    Figure CN118939207A_ABST
Patent Text Reader

Abstract

The invention provides a log printing method and device, electronic equipment and a readable storage medium, and the method comprises the steps: calling a target printing class which is created and packaged in advance based on a singleton mode, and obtaining log printing parameters input by a user in an editing process; based on the log printing mode, the log printing path and the log printing format, at least one log printing function is called, and a log printing instance is created; and generating a target log based on the log printing instance according to the log printing mode and the log printing format, and storing the target log to the log printing path. Therefore, through the pre-packaged log printing class, the log printing parameters input by the user in the editing process are received and processed, then the log printing instance is created according to the log printing parameters, log printing is completed through the log printing instance, the editing learning time of the user is effectively shortened, and the log printing efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a log printing method, device, electronic device and readable storage medium. Background Art

[0002] During the software operation or service execution process, the operation or execution of the software or the provided services can be analyzed and counted by recording logs. Users can define the log printing method, log printing path and log printing format by writing a log acquisition program, and store the logs that need to be counted and queried in the target path location.

[0003] In the prior art, the method of log printing requires users to manually write different log printing methods and other instructions. Different configuration options and configuration parameters require a certain amount of learning time to set, which increases the time for log printing settings and affects log printing efficiency. Summary of the invention

[0004] In view of this, the purpose of the present application is to provide a log printing method, device, electronic device and readable storage medium, which receives and processes the log printing parameters input by the user during the editing process through a pre-packaged log printing class, and then creates a log printing instance according to the log printing parameters, and completes the log printing through the log printing instance, effectively reducing the user's editing and learning time, and helping to improve log printing efficiency.

[0005] In a first aspect, an embodiment of the present application provides a method for printing a log, the printing method comprising:

[0006] Calling the target printing class that is pre-created and encapsulated based on the singleton mode, and obtaining the log printing parameters input by the user during the editing process; wherein the log printing parameters include the log printing mode, the log printing path and the log printing format;

[0007] Based on the log printing mode, the log printing path and the log printing format, calling at least one log printing function to create a log printing instance;

[0008] A target log is generated based on the log printing instance according to the log printing method and the log printing format, and the target log is stored in the log printing path.

[0009] In a second aspect, an embodiment of the present application further provides a log printing device, the printing device comprising:

[0010] The printing parameter acquisition module is used to call the target printing class that is pre-created and encapsulated based on the singleton mode to obtain the log printing parameters entered by the user during the editing process; wherein the log printing parameters include the log printing mode, the log printing path and the log printing format;

[0011] A printing instance creation module, used to call at least one log printing function to create a log printing instance based on the log printing mode, the log printing path and the log printing format;

[0012] The log printing module is used to generate a target log based on the log printing instance according to the log printing method and the log printing format, and store the target log in the log printing path.

[0013] In a third aspect, an embodiment of the present application further provides an electronic device, comprising: a processor, a storage medium and a bus, wherein the storage medium stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor communicates with the storage medium through the bus, and the processor executes the machine-readable instructions to execute the log printing method as described in any one of the first aspects.

[0014] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the log printing method as described in any one of the first aspects is executed.

[0015] The log printing method, device, electronic device and readable storage medium provided by the embodiment of the present application call the target printing class that is pre-encapsulated based on the singleton mode to obtain the log printing parameters input by the user during the editing process; based on the log printing method, log printing path and log printing format, call at least one log printing function to create a log printing instance; based on the log printing instance, generate the target log according to the log printing method and log printing format, and store the target log in the log printing path. In this way, the log printing parameters input by the user during the editing process are received and processed through the pre-encapsulated log printing class, and then a log printing instance is created according to the log printing parameters, and the log printing is completed through the log printing instance, which effectively reduces the user's editing and learning time and helps to improve the efficiency of log printing.

[0016] Furthermore, creating a target printing class through the singleton mode can ensure that there is only one log printing instance in the subsequent log printing process, which can save hardware resources and display various log printing parameters that need to be set, making it convenient for users to set.

[0017] Furthermore, when creating a log printing instance, it can be set through the factory mode. In the factory mode, common parameters can be reused. At the same time, the instance is created in combination with the log printing method, the log printing path and the log printing format input by the user. Compared with the creation method that requires input of all parameters, the instance construction steps are simplified and the efficiency of instance construction is improved.

[0018] Furthermore, when the user is running the software for editing, the target version of the current log printing software will be automatically obtained, and the log printing function corresponding to the version will be called based on the target version, so that different versions of the log printing software are compatible from the code level. The user does not need to modify the called log printing function according to different software versions, which further simplifies the user's modification and learning costs and improves the efficiency of log acquisition.

[0019] In order to make the above-mentioned objects, features and advantages of the present application more obvious and easy to understand, preferred embodiments are specifically cited below and described in detail with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS

[0020] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.

[0021] Figure 1 A flow chart of a log printing method provided in an embodiment of the present application;

[0022] Figure 2 One of the structural schematic diagrams of a log printing device provided in an embodiment of the present application;

[0023] Figure 3 A second structural diagram of a log printing device provided in an embodiment of the present application;

[0024] Figure 4 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0025] To make the purpose, technical scheme and advantages of the embodiments of the present application clearer, the technical scheme in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all of the embodiments. The components of the embodiments of the present application usually described and shown in the drawings here can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the application claimed for protection, but merely represents the selected embodiments of the present application. Based on the embodiments of the present application, each other embodiment obtained by those skilled in the art without making creative work belongs to the scope of protection of the present application.

[0026] During the software operation or service execution process, the operation or execution of the software or the provided services can be analyzed and counted by recording logs. Users can define the log printing method, log printing path and log printing format by writing a log acquisition program, and store the logs that need to be counted and queried in the target path location.

[0027] In the prior art, the method of log printing requires users to manually write different log printing methods and other instructions. Different configuration options and configuration parameters require a certain amount of learning time to set, which increases the time for log printing settings and affects log printing efficiency.

[0028] Based on this, an embodiment of the present application provides a log printing method to reduce the user's editing and learning time and improve log printing efficiency.

[0029] See also Figure 1 , Figure 1 This is a flow chart of a log printing method provided by an embodiment of the present application. Figure 1 As shown in , the log printing method provided by the embodiment of the present application includes:

[0030] S101, calling a target printing class that is pre-encapsulated based on a singleton pattern, and obtaining log printing parameters input by a user during an editing process; wherein the log printing parameters include a log printing mode, a log printing path, and a log printing format.

[0031] S102: Based on the log printing mode, the log printing path, and the log printing format, call at least one log printing function to create a log printing instance.

[0032] S103: Generate a target log based on the log printing instance according to the log printing method and the log printing format, and store the target log in the log printing path.

[0033] The log printing method provided in the embodiment of the present application receives and processes the log printing parameters input by the user during the editing process through a pre-packaged log printing class, and then creates a log printing instance according to the log printing parameters, and completes the log printing through the log printing instance, which effectively reduces the user's editing and learning time and helps to improve the log printing efficiency.

[0034] The following is a description of the exemplary steps of the present application embodiment:

[0035] S101 , calling a target printing class that is pre-created and encapsulated based on a singleton pattern, and obtaining log printing parameters input by a user during the editing process.

[0036] In one possible implementation, during the software operation or service execution process, the operation or execution of the software or the provided service can be analyzed and counted by recording logs. The user can define the log printing method, log printing path and log printing format by writing a log acquisition program, and store the logs that need to be counted and queried in the target path location.

[0037] The log printing method includes at least one of the following: a stream printing method, a file printing method, and a socket printing method.

[0038] Among them, there are five common log levels, namely ERROR, WARNING, INFO, DEBUG, and CRITICAL; ERROR: error log, refers to more serious errors that have an impact on normal business and require operation and maintenance configuration monitoring; WARNING: warning log, general errors, which have little impact on business, but require development attention; INFO: information log, recording key information for troubleshooting, such as call time, input and output parameters, etc.; DEBUG: used for development DEBUG, runtime data in key logic; CRITICAL: the most detailed information, generally this information is only recorded in the log file.

[0039] In a possible implementation, a program for obtaining logs can be written in different programming languages ​​(e.g., Java, Python, etc.) based on the settings of various programming languages. In Python, logs are generally printed through the logging module, which provides a flexible mechanism to record information during program execution. It can classify log information according to different levels and can be configured to output this information to different destinations (e.g., console, file, etc.).

[0040] Specifically, the steps for printing logs through the logging module are: Import the module: Use importlogging to import the module -> Create a logger: Get a logger object through logging.getLogger() -> Set the log level: The minimum level of logger processing can be set through the setLevel() method -> Configure the processor: For example, add a processor that outputs to the console logging.StreamHandler() or add a processor that outputs to a file logging.FileHandler(), etc. -> Set the format of the processor: Use setFormatter() to set a specific log format for the processor -> Output log: Use different levels of methods such as logger.debug(), logger.info(), etc. to output log information of corresponding levels.

[0041] In a possible implementation, for the above-mentioned method of printing logs through the logging module, the user is required to manually set different log printing methods. Different configuration options and configuration parameters require a certain amount of learning time to set, which increases the time for log printing settings and affects log printing efficiency.

[0042] In an embodiment of the present application, a log printing file package can be pre-packaged, and different printing methods and log printing classes can be encapsulated through the log printing file package. Users can download and install the log printing file package to simply input log printing parameters, directly call the function to generate an instance to complete the log printing process, thereby improving the efficiency and flexibility of log printing.

[0043] Specifically, before the step of "calling the target printing class that is pre-encapsulated based on the singleton mode to obtain the log printing parameters input by the user during the editing process", the printing method further includes:

[0044] a1: Upload the packaged log print file package to the server.

[0045] a2: In response to a downloading and installation operation of the log print file package from the server by the user, installing the log print file package to the terminal device of the user.

[0046] a3: in response to the user's opening operation on the log printing file package, starting the file packaged in the log printing file package.

[0047] In an embodiment of the present application, the packaged log printing file includes a packaged log printing method and a packaged target printing class created based on the singleton mode. The format of the log printing file package can be a ruban-log-{version}.whl package. After being packaged into a ruban-log-{version}.whl package, the log printing file package is uploaded to the pip server.

[0048] In one possible implementation, users can install<package_name> Command to install the log printing file package.

[0049] Furthermore, the user can install the log printing file package on the user's terminal device by downloading and installing the log printing file package from the server. The encapsulated files in the log printing file package can be installed without additional operations, and the function call can be directly made through parameter input to complete log printing, thereby further improving the efficiency of log printing and the compatibility of the log installation package.

[0050] In one possible implementation, before packaging the log SDK into a log printing file package, you first need to create a target printing class through the singleton mode. Creating the target printing class through the singleton mode can ensure that there is only one log printing instance during the subsequent log printing process, which can save hardware resources. At the same time, it displays various log printing parameters that need to be set, which is convenient for users to set.

[0051] Specifically, the target printing class is created by the following steps:

[0052] b1: Call the print method to create the print parameter name and log print level in the initial print class.

[0053] b2: Determine the corresponding location or log directory based on the different log printing formats that are set.

[0054] b3: Set the number of log files to be retained and encapsulate different printing methods, and create the target printing class.

[0055] In the embodiment of the present application, during the creation of the target printing class, it supports customizing the default formatter / filter, directly calling the logger method to create it, and selecting and setting the printing parameter name and the log printing level in the target printing class, wherein the log printing level supports customization, and when the log printing level is not set, the default log printing level is INFO. Specifically, dev / fat / uat defaults to INFO, and pro defaults to DEBUG.

[0056] In one possible implementation, if it is determined that SocketHandler needs to be used (i.e., the current log printing format is the socket format), the sock file location needs to be set; if the file handler is used directly, the log directory is set, and the file handler provides a rotate function based on the file size. If the parameter is set to 0, this function is turned off; at the same time, the number of log files to be retained and different printing methods can be encapsulated. After setting the number of log files to be retained, if the current number of logs is greater than the number of log files to be retained, it will close automatically. At the same time, you can choose whether to turn on this function according to the parameters. If the parameter is set to 0, this function is turned off.

[0057] Furthermore, if the user issues an opening operation for the log printing file package, the file packaged in the log printing file package is started, and a programming operation can be performed to input parameters to call the packaged printing method to complete the log printing process.

[0058] In a possible implementation, in order to further simplify the user's operation and enable the user to input log printing parameters, a log printing program writing sample may be provided to the user separately, and the user may refer to the log printing program writing sample to input log printing parameters.

[0059] Specifically, the log printing method further includes:

[0060] c1: Provides a log printing program writing example.

[0061] In an embodiment of the present application, the log printing program writing sample can be a complete program writing sample. At the same time, in the log printing program writing sample, the parameter part that needs to be modified or personalized by the user can be highlighted, for example, marked in yellow.

[0062] In a possible implementation, the log printing program writing sample is not stored in the log printing file package, but is provided additionally.

[0063] Furthermore, the user can refer to the log printing program writing example and modify the input log printing parameters.

[0064] Specifically, the step of "obtaining log printing parameters input by the user during the editing process" includes:

[0065] d1: Obtain the log printing parameters modified and input by the user during the editing process of writing the log printing program sample with reference to the log printing program.

[0066] In a possible implementation, when editing the log printing program, the user may refer to a log printing program writing example and input log printing parameters.

[0067] Exemplarily, the parameters of the logger function, the parameters of the start_sock_consumer function, etc. may be modified.

[0068] In one possible implementation, the log printing parameters include a log printing method, a log printing path, and a log printing format. After the user inputs the log printing parameters including the log printing method, the log printing path, and the log printing format, a log printing instance can be constructed according to the log printing parameters including the log printing method, the log printing path, and the log printing format, and log printing can be completed through the created log printing instance.

[0069] S102: Based on the log printing mode, the log printing path, and the log printing format, call at least one log printing function to create a log printing instance.

[0070] In an embodiment of the present application, logs of different modules can be printed into the log printing path set by the user by creating different log printing instances.

[0071] Specifically, the step of “calling at least one log printing function to create a log printing instance based on the log printing mode, the log printing path, and the log printing format” includes:

[0072] e1: Based on the multiplexing printing parameters reused in the factory mode and the log printing mode, the log printing path and the log printing format, at least one log printing function is called to create a log printing instance.

[0073] In one possible implementation, when creating a log printing instance, settings can be made through a factory mode, in which common parameters can be reused, and an instance can be created by combining the log printing method, the log printing path, and the log printing format input by the user. Compared with the creation method that requires input of all parameters, the instance construction steps are simplified and the efficiency of instance construction is improved.

[0074] Specifically, the factory method pattern defines an interface for creating objects, but the factory itself is not responsible for creating objects, but lets the subclass decide which class to instantiate. This pattern delays the instantiation of a class to its subclasses, and completes the creation of factory methods through inheritance rather than instantiation. The factory method pattern is a further abstraction of the simple factory pattern, which maintains the advantages of the simple factory while overcoming its disadvantages, allowing the system to easily introduce new products without modifying the original product structure; the main purpose of the abstract factory pattern is to provide an interface to create a series of related objects without specifying specific classes. It ensures that the client is isolated from the creation of objects, while also ensuring that the client can use the created objects. The abstract factory pattern is suitable when the system needs to create a series of related or dependent objects, rather than a single object. The simple factory pattern, also known as the static factory method, belongs to the creation pattern. It returns instances of different classes depending on the parameters passed. The simple factory pattern defines a class specifically for creating instances of other classes, and these created classes have a common parent class. The advantage of this pattern is that it separates the creation of objects from the use of objects, but the disadvantage is that if there are too many products, the factory code will be very complicated.

[0075] In a possible implementation, the step of “calling at least one log printing function to create a log printing instance based on the log printing parameters reused in the factory mode and the log printing mode, the log printing path, and the log printing format” includes:

[0076] f1: Call the log printing function, receive the multiplexed printing parameters and the log printing mode, the log printing path and the log printing format.

[0077] f2: If a logger with the preset name does not exist, create a logger.

[0078] f3: compare the current log printing format of the logger with the input log printing format to see if they are consistent. If they are inconsistent, use the input log printing format.

[0079] f4: Check whether standard output is currently used. If standard output is used, add a stream processor to the logger.

[0080] f5: According to the current log printing mode, adjust the logger, and create a log printing instance based on the adjusted logger.

[0081] In an embodiment of the present application, the logger function accepts multiple log printing parameters, including the name of the logger, the path of the log file, the path of the socket file, the service name, whether to enable standard output, the log format mode (schema), and the tracking ID. First, check whether a logger named name already exists. If not, create a new logger. If a log format mode is provided and it is different from the current log format mode, use the new log format mode. Otherwise, use the current log format mode. Then, create a log formatter (formatter), which is used to format the log message into a specified format. Next, create a logger, set its log level, and add a log filter. The role of this log filter is to do some processing on the log message before it is processed, such as adding some custom fields. If standard output is enabled, a stream handler is added to the logger. The role of this stream handler is to output the log message to standard output. Then, call the enable_file_sock method, which is used to enable file (file) and socket (socket) logging. Finally, the created or obtained logger is returned. Users can create a log printing instance by calling the logger function.

[0082] In a possible implementation, different users may use different versions of software, and the log printing functions corresponding to different software versions may differ to a certain extent. Therefore, when creating a log printing instance by calling at least one log printing function, compatibility with different software versions is required.

[0083] Specifically, the step of "calling at least one log printing function to create a log printing instance" includes:

[0084] g1: Get the target version of the current log printing software, call at least one encapsulated log printing function, and create a log printing instance.

[0085] In one possible implementation, when the user is running the software for editing, the target version of the current log printing software is automatically obtained, and the log printing function corresponding to the version is called based on the target version, so that different versions of the log printing software are compatible from the code level. The user does not need to modify the called log printing function according to different software versions, which further simplifies the user's modification and learning costs and improves the efficiency of log acquisition.

[0086] Furthermore, after the log printing instance is created, a target log may be generated through the log printing instance, and the generated target log may be stored in the log printing path input by the user.

[0087] S103: Generate a target log based on the log printing instance according to the log printing method and the log printing format, and store the target log in the log printing path.

[0088] In an embodiment of the present application, in the process of generating a target log, the target log can be generated according to the log printing level set by the user.

[0089] Specifically, the step of "generating a target log based on the log printing instance according to the log printing method and the log printing format" includes:

[0090] h1: Generate the target log based on the log printing instance, in accordance with the log printing mode and the log printing format, and with reference to the log printing level.

[0091] In the embodiment of the present application, for the log printing level, the target log with a low log printing level includes log information with a high log printing level; and the log with a high log printing level will not output the log information with a low log printing level.

[0092] Specifically, DEBUG is the most built-in severity level (lowest printing level), and CRITICAL is the highest built-in severity level (highest printing level). For example, if the severity level is INFO, the logger will only process INFO, WARNING, ERROR, and CRITICAL messages, and will ignore DEBUG messages.

[0093] In a possible implementation, when the log printing mode is the socket printing mode, the log printing can be completed by calling the sockethandler method to start a process based on sock_file (unix domain socket). This can avoid content duplication and disorder when multiple processes write logs to a printing path (file) at the same time.

[0094] Specifically, when the log printing mode is a socket printing mode, the step of "generating a target log based on the log printing instance according to the log printing mode and the log printing format, and storing the target log in the log printing path" includes:

[0095] i1: Generate a target log based on the log printing instance according to the log printing method and the log printing format through multi-threading, and store the target log in a cache.

[0096] i2: Start the only consumer process to store the target log from the cache to the log printing path.

[0097] In the embodiment of the present application, the method of start_sock_consumer is called, and its function is to start a socket consumer process. This method accepts multiple log printing parameters, including the socket client, the path of the socket file, the path of the log file, the parameters of the socket client, and the file name. First, check whether the current process is the main process. If it is not the main process, return directly. If the socket client is not provided, create a new socket client. When creating a socket client, it will first ensure that the path of the log file exists, and then create the socket client with the given parameters. Then, save the created socket client to the _socket_client attribute. Next, create a new process and set its target to the run method of the socket client, and the parameters are the parameters of the given socket client. Finally, start the newly created process and add it to the _socket_process list, and then complete the storage of the target log through the unique consumer process.

[0098] In this way, when multiple processes store the target log to the cache at the same time, the only consumer process only executes one log printing path (file or screen) to store the target log at the same time. While ensuring the efficiency of storing the target log to the cache, it can avoid content duplication and disorder when multiple processes write logs to a printing path (file) at the same time.

[0099] The log printing method provided by the embodiment of the present application calls the target printing class that is pre-encapsulated based on the singleton mode to obtain the log printing parameters input by the user during the editing process; based on the log printing method, log printing path and log printing format, calls at least one log printing function to create a log printing instance; based on the log printing instance, generates a target log according to the log printing method and log printing format, and stores the target log in the log printing path. In this way, the log printing parameters input by the user during the editing process are received and processed through the pre-encapsulated log printing class, and then a log printing instance is created according to the log printing parameters, and the log printing is completed through the log printing instance, which effectively reduces the user's editing and learning time and helps to improve the efficiency of log printing.

[0100] Based on the same inventive concept, the embodiment of the present application also provides a log printing device corresponding to the log printing method. Since the principle of solving the problem by the device in the embodiment of the present application is similar to the above-mentioned log printing method in the embodiment of the present application, the implementation of the device can refer to the implementation of the method, and the repeated parts will not be repeated.

[0101] See also Figure 2 , Figure 3 , Figure 2 This is one of the structural schematic diagrams of a log printing device provided in an embodiment of the present application. Figure 3 This is a second structural diagram of a log printing device provided in an embodiment of the present application. Figure 2 As shown in , the printing device 200 includes:

[0102] The printing parameter acquisition module 210 is used to call the target printing class that is pre-created and encapsulated based on the singleton mode to obtain the log printing parameters input by the user during the editing process; wherein the log printing parameters include the log printing mode, the log printing path and the log printing format;

[0103] A printing instance creation module 220, configured to call at least one log printing function to create a log printing instance based on the log printing mode, the log printing path and the log printing format;

[0104] The log printing module 230 is used to generate a target log based on the log printing instance according to the log printing method and the log printing format, and store the target log in the log printing path.

[0105] In a possible implementation, when the printing instance creation module 220 is used to call at least one log printing function to create a log printing instance based on the log printing mode, the log printing path, and the log printing format, the printing instance creation module 220 is used to:

[0106] Based on the multiplexing printing parameters reused in the factory mode and the log printing mode, the log printing path and the log printing format, at least one log printing function is called to create a log printing instance.

[0107] In a possible implementation, when the print instance creation module 220 is used to call at least one log printing function to create a log printing instance based on the log printing parameters reused in the factory mode and the log printing mode, the log printing path, and the log printing format, the print instance creation module 220 is used to:

[0108] Calling the log printing function, receiving the multiplexing printing parameters and the log printing mode, the log printing path and the log printing format;

[0109] If a logger with the preset name does not exist, create a logger;

[0110] Compare the current log printing format of the log recorder with the input log printing format to see if they are consistent, if not, use the input log printing format;

[0111] Check whether standard output is currently used. If standard output is used, add a stream processor to the logger.

[0112] According to the current log printing mode, the logger is adjusted, and a log printing instance is created based on the adjusted logger.

[0113] In a possible implementation, when the printing instance creation module 220 is used to call at least one log printing function to create a log printing instance, the printing instance creation module 220 is used to:

[0114] Obtain the target version of the current log printing software, call at least one encapsulated log printing function, and create a log printing instance; wherein different software versions correspond to different log printing functions.

[0115] In a possible implementation, the log printing method includes at least one of the following:

[0116] Stream printing method, file printing method, socket printing method.

[0117] In a possible implementation, when the log printing mode is a socket printing mode, the log printing module 230 is used to generate a target log based on the log printing instance according to the log printing mode and the log printing format, and store the target log in the log printing path, the log printing module 230 is used to:

[0118] Generate a target log based on the log printing instance according to the log printing method and the log printing format through multithreading, and store the target log in a cache;

[0119] A unique consumer process is started to store the target log from the cache to the log printing path.

[0120] In a possible implementation, Figure 3 As shown, the printing device 200 further includes a file package uploading module 240, and the file package uploading module 240 is used to:

[0121] Upload the packaged log print file package to the server;

[0122] In response to a download and installation operation of the log print file package from the server by the user, installing the log print file package to the terminal device of the user;

[0123] In response to the user's opening operation on the log printing file package, the file packaged in the log printing file package is started.

[0124] In a possible implementation, Figure 3As shown, the printing device 200 further includes a printing class creation module 250, and the printing class creation module 250 is used to create the target printing class through the following steps:

[0125] Call the print method to create the print parameter name and log print level in the initial print class;

[0126] Determine the corresponding location or log directory based on the different log printing formats set;

[0127] The number of log files to be retained is set, different printing modes are encapsulated, and the target printing class is created.

[0128] In a possible implementation, when the log printing module 230 is used to generate a target log based on the log printing instance according to the log printing method and the log printing format, the log printing module 230 is used to:

[0129] Generate the target log based on the log printing instance, in accordance with the log printing mode and the log printing format, and with reference to the log printing level;

[0130] The target log with a low log printing level includes log information with a high log printing level.

[0131] In a possible implementation, Figure 3 As shown, the printing device 200 further includes a sample providing module 260, and the sample providing module 260 is used to:

[0132] Provides log printing program writing examples.

[0133] When the printing parameter acquisition module 210 is used to acquire the log printing parameters input by the user during the editing process, the printing parameter acquisition module 210 is used to:

[0134] The log printing parameters input by the user during the editing process of writing the log printing program sample with reference to the log printing program are obtained.

[0135] The log printing device provided by the embodiment of the present application calls the target printing class that is pre-encapsulated based on the singleton mode to obtain the log printing parameters input by the user during the editing process; based on the log printing method, log printing path and log printing format, calls at least one log printing function to create a log printing instance; based on the log printing instance, generates a target log according to the log printing method and log printing format, and stores the target log in the log printing path. In this way, the log printing parameters input by the user during the editing process are received and processed through the pre-encapsulated log printing class, and then a log printing instance is created according to the log printing parameters, and the log printing is completed through the log printing instance, which effectively reduces the user's editing and learning time and helps to improve the efficiency of log printing.

[0136] See also Figure 4 , Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Figure 4 As shown in , the electronic device 400 includes a processor 410 , a memory 420 and a bus 430 .

[0137] The memory 420 stores machine-readable instructions executable by the processor 410. When the electronic device 400 is running, the processor 410 communicates with the memory 420 via the bus 430, so that the processor 410 executes the following instructions when running:

[0138] Calling the target printing class that is pre-created and encapsulated based on the singleton mode, and obtaining the log printing parameters input by the user during the editing process; wherein the log printing parameters include the log printing mode, the log printing path and the log printing format;

[0139] Based on the log printing mode, the log printing path and the log printing format, calling at least one log printing function to create a log printing instance;

[0140] A target log is generated based on the log printing instance according to the log printing method and the log printing format, and the target log is stored in the log printing path.

[0141] In a possible implementation, in the instructions executed by the processor 410, calling at least one log printing function based on the log printing mode, the log printing path, and the log printing format to create a log printing instance includes:

[0142] Based on the multiplexing printing parameters reused in the factory mode and the log printing mode, the log printing path and the log printing format, at least one log printing function is called to create a log printing instance.

[0143] In a possible implementation, in the instruction executed by the processor 410, the log printing parameters based on factory mode reuse, the log printing mode, the log printing path, and the log printing format call at least one log printing function to create a log printing instance, including:

[0144] Calling the log printing function, receiving the multiplexing printing parameters and the log printing mode, the log printing path and the log printing format;

[0145] If a logger with the preset name does not exist, create a logger;

[0146] Compare the current log printing format of the log recorder with the input log printing format to see if they are consistent, if not, use the input log printing format;

[0147] Check whether standard output is currently used. If standard output is used, add a stream processor to the logger.

[0148] According to the current log printing mode, the logger is adjusted, and a log printing instance is created based on the adjusted logger.

[0149] In a possible implementation, in the instructions executed by the processor 410, calling at least one log printing function to create a log printing instance includes:

[0150] Obtain the target version of the current log printing software, call at least one encapsulated log printing function, and create a log printing instance; wherein different software versions correspond to different log printing functions.

[0151] In a possible implementation manner, the log printing method includes at least one of the following:

[0152] Stream printing method, file printing method, socket printing method.

[0153] In a possible implementation, in the instructions executed by the processor 410, when the log printing mode is a socket printing mode, generating a target log based on the log printing instance according to the log printing mode and the log printing format, and storing the target log to the log printing path includes:

[0154] Generate a target log based on the log printing instance according to the log printing method and the log printing format through multithreading, and store the target log in a cache;

[0155] A unique consumer process is started to store the target log from the cache to the log printing path.

[0156] In a possible implementation manner, the instructions executed by the processor 410 further include:

[0157] Upload the packaged log print file package to the server;

[0158] In response to a download and installation operation of the log print file package from the server by the user, installing the log print file package to the terminal device of the user;

[0159] In response to the user's opening operation on the log printing file package, the file packaged in the log printing file package is started.

[0160] In a possible implementation manner, in the instructions executed by the processor 410, the target printing class is created through the following steps:

[0161] Call the print method to create the print parameter name and log print level in the initial print class;

[0162] Determine the corresponding location or log directory based on the different log printing formats set;

[0163] The number of log files to be retained is set, different printing modes are encapsulated, and the target printing class is created.

[0164] In a possible implementation, in the instructions executed by the processor 410, generating a target log based on the log printing instance according to the log printing method and the log printing format includes:

[0165] Generate the target log based on the log printing instance, in accordance with the log printing mode and the log printing format, and with reference to the log printing level;

[0166] The target log with a low log printing level includes log information with a high log printing level.

[0167] In a possible implementation manner, the instructions executed by the processor 410 further include:

[0168] Provides log printing program writing examples.

[0169] In a possible implementation, in the instructions executed by the processor 410, the step of obtaining the log printing parameters input by the user during the editing process includes:

[0170] The log printing parameters input by the user during the editing process of writing the log printing program sample with reference to the log printing program are obtained.

[0171] Through the above method, the log printing parameters input by the user during the editing process are received and processed by the pre-encapsulated log printing class, and then a log printing instance is created according to the log printing parameters, and log printing is completed through the log printing instance, which effectively reduces the user's editing learning time and helps to improve the efficiency of log printing. At the same time, the user can install the log printing file package to the user's terminal device by downloading and installing the log printing file package from the server, and the encapsulated files in the log printing file package can be installed without additional operations, and the function call is directly performed through parameter input to complete log printing, further improving the efficiency of log printing and the compatibility of the log installation package. At the same time, creating a target printing class through a singleton mode can ensure that there is only one log printing instance in the subsequent log printing operation process, which can save hardware resources, and at the same time display various log printing parameters that need to be set, which is convenient for users to set. At the same time, when creating a log printing instance, it can be set through the factory mode, and the general parameters can be reused in the factory mode. At the same time, the log printing method input by the user, the log printing path and the log printing format are combined to create an instance, which simplifies the instance construction steps and improves the efficiency of instance construction compared to the creation method that requires inputting all parameters. Furthermore, when the user of the running software is editing, the target version of the current log printing software will be automatically obtained, and the log printing function corresponding to the version will be called based on the target version, so that different versions of the log printing software are compatible from the code level, without the need for the user to modify the called log printing function according to different software versions, further simplifying the user's modification and learning costs, and improving the efficiency of log acquisition. Furthermore, when multiple processes store target logs to the cache at the same time, the only consumer process only executes one log printing path (file or screen) to store the target log at the same time, which can ensure the efficiency of storing the target log to the cache while avoiding content duplication and disorder when multiple processes write logs to a printing path (file) at the same time.

[0172] The present application also provides a computer-readable storage medium, on which a computer program is stored, so that when the computer program is executed by a processor, the following instructions are executed:

[0173] Calling the target printing class that is pre-created and encapsulated based on the singleton mode, and obtaining the log printing parameters input by the user during the editing process; wherein the log printing parameters include the log printing mode, the log printing path and the log printing format;

[0174] Based on the log printing mode, the log printing path and the log printing format, calling at least one log printing function to create a log printing instance;

[0175] A target log is generated based on the log printing instance according to the log printing method and the log printing format, and the target log is stored in the log printing path.

[0176] In a possible implementation, in the instructions executed by the computer-readable storage medium, calling at least one log printing function based on the log printing mode, the log printing path, and the log printing format to create a log printing instance includes:

[0177] Based on the multiplexing printing parameters reused in the factory mode and the log printing mode, the log printing path and the log printing format, at least one log printing function is called to create a log printing instance.

[0178] In a possible implementation, in the instructions executed by the computer-readable storage medium, the log printing parameters based on factory mode reuse, the log printing mode, the log printing path, and the log printing format call at least one log printing function to create a log printing instance, including:

[0179] Calling the log printing function, receiving the multiplexing printing parameters and the log printing mode, the log printing path and the log printing format;

[0180] If a logger with the preset name does not exist, create a logger;

[0181] Compare the current log printing format of the log recorder with the input log printing format to see if they are consistent, if not, use the input log printing format;

[0182] Check whether standard output is currently used. If standard output is used, add a stream processor to the logger.

[0183] According to the current log printing mode, the logger is adjusted, and a log printing instance is created based on the adjusted logger.

[0184] In a possible implementation, in the instructions executed by the computer-readable storage medium, calling at least one log printing function to create a log printing instance includes:

[0185] Obtain the target version of the current log printing software, call at least one encapsulated log printing function, and create a log printing instance; wherein different software versions correspond to different log printing functions.

[0186] In a possible implementation manner, the log printing method includes at least one of the following:

[0187] Stream printing method, file printing method, socket printing method.

[0188] In a possible implementation, in the instructions executed by a computer-readable storage medium, when the log printing mode is a socket printing mode, generating a target log based on the log printing instance according to the log printing mode and the log printing format, and storing the target log in the log printing path includes:

[0189] Generate a target log based on the log printing instance according to the log printing method and the log printing format through multithreading, and store the target log in a cache;

[0190] A unique consumer process is started to store the target log from the cache to the log printing path.

[0191] In a possible implementation manner, the instructions executed by the computer-readable storage medium further include:

[0192] Upload the packaged log print file package to the server;

[0193] In response to a download and installation operation of the log print file package from the server by the user, installing the log print file package to the terminal device of the user;

[0194] In response to the user's opening operation on the log printing file package, the file packaged in the log printing file package is started.

[0195] In a possible implementation manner, in the instructions executed by the computer-readable storage medium, the target printing class is created by the following steps:

[0196] Call the print method to create the print parameter name and log print level in the initial print class;

[0197] Determine the corresponding location or log directory based on the different log printing formats set;

[0198] The number of log files to be retained is set, different printing modes are encapsulated, and the target printing class is created.

[0199] In a possible implementation, in the instructions executed by the computer-readable storage medium, generating a target log based on the log printing instance according to the log printing method and the log printing format includes:

[0200] Generate the target log based on the log printing instance, in accordance with the log printing mode and the log printing format, and with reference to the log printing level;

[0201] The target log with a low log printing level includes log information with a high log printing level.

[0202] In a possible implementation manner, the instructions executed by the computer-readable storage medium further include:

[0203] Provides log printing program writing examples.

[0204] In a possible implementation manner, in the instructions executed by the computer-readable storage medium, the step of obtaining the log printing parameters input by the user during the editing process includes:

[0205] The log printing parameters input by the user during the editing process of writing the log printing program sample with reference to the log printing program are obtained.

[0206] Through the above method, the log printing parameters input by the user during the editing process are received and processed by the pre-encapsulated log printing class, and then a log printing instance is created according to the log printing parameters, and log printing is completed through the log printing instance, which effectively reduces the user's editing learning time and helps to improve the efficiency of log printing. At the same time, the user can install the log printing file package to the user's terminal device by downloading and installing the log printing file package from the server, and the encapsulated files in the log printing file package can be installed without additional operations, and the function call is directly performed through parameter input to complete log printing, further improving the efficiency of log printing and the compatibility of the log installation package. At the same time, creating a target printing class through a singleton mode can ensure that there is only one log printing instance in the subsequent log printing operation process, which can save hardware resources, and at the same time display various log printing parameters that need to be set, which is convenient for users to set. At the same time, when creating a log printing instance, it can be set through the factory mode, and the general parameters can be reused in the factory mode. At the same time, the log printing method input by the user, the log printing path and the log printing format are combined to create an instance, which simplifies the instance construction steps and improves the efficiency of instance construction compared to the creation method that requires inputting all parameters. Furthermore, when the user of the running software is editing, the target version of the current log printing software will be automatically obtained, and the log printing function corresponding to the version will be called based on the target version, so that different versions of the log printing software are compatible from the code level, without the need for the user to modify the called log printing function according to different software versions, further simplifying the user's modification and learning costs, and improving the efficiency of log acquisition. Furthermore, when multiple processes store target logs to the cache at the same time, the only consumer process only executes one log printing path (file or screen) to store the target log at the same time, which can ensure the efficiency of storing the target log to the cache while avoiding content duplication and disorder when multiple processes write logs to a printing path (file) at the same time.

[0207] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.

[0208] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, 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 through some communication interfaces, and the indirect coupling or communication connection of devices or units can be electrical, mechanical or other forms.

[0209] 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.

[0210] In addition, each functional unit in each embodiment of the present application 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.

[0211] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a non-volatile computer-readable storage medium that is executable by a processor. Based on this understanding, the technical solution of the present application can essentially be embodied in the form of a software product, or in other words, the part that contributes to the prior art or the part of the technical solution. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.

[0212] Finally, it should be noted that the above-described embodiments are only specific implementation methods of the present application, which are used to illustrate the technical solutions of the present application, rather than to limit them. The protection scope of the present application is not limited thereto. Although the present application is described in detail with reference to the above-mentioned embodiments, ordinary technicians in the field should understand that any technician familiar with the technical field can still modify the technical solutions recorded in the above-mentioned embodiments within the technical scope disclosed in the present application, or can easily think of changes, or make equivalent replacements for some of the technical features therein; and these modifications, changes or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application, and should be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be based on the protection scope of the claims.

Claims

1. A log printing method, characterized in that: The printing method comprises: Calling the target printing class that is pre-created and encapsulated based on the singleton mode, and obtaining the log printing parameters input by the user during the editing process; wherein the log printing parameters include the log printing mode, the log printing path and the log printing format; Based on the log printing mode, the log printing path and the log printing format, calling at least one log printing function to create a log printing instance; A target log is generated based on the log printing instance according to the log printing method and the log printing format, and the target log is stored in the log printing path.

2. The printing method according to claim 1, characterized in that: The step of calling at least one log printing function based on the log printing mode, the log printing path, and the log printing format to create a log printing instance includes: Based on the multiplexing printing parameters reused in the factory mode and the log printing mode, the log printing path and the log printing format, at least one log printing function is called to create a log printing instance.

3. The printing method according to claim 2, characterized in that: The log printing parameters reused based on the factory mode, the log printing mode, the log printing path and the log printing format, calling at least one log printing function, and creating a log printing instance include: Calling the log printing function, receiving the multiplexing printing parameters and the log printing mode, the log printing path and the log printing format; If a logger with the preset name does not exist, create a logger; Compare the current log printing format of the log recorder with the input log printing format to see if they are consistent, if not, use the input log printing format; Check whether standard output is currently used. If standard output is used, add a stream processor to the logger. According to the current log printing mode, the logger is adjusted, and a log printing instance is created based on the adjusted logger.

4. The printing method according to claim 1, characterized in that: The calling of at least one log printing function to create a log printing instance includes: Obtain the target version of the current log printing software, call at least one encapsulated log printing function, and create a log printing instance; wherein different software versions correspond to different log printing functions.

5. The printing method according to claim 1, characterized in that: The log printing method includes at least one of the following: Stream printing method, file printing method, socket printing method.

6. The printing method according to claim 5, characterized in that: When the log printing mode is a socket printing mode, generating a target log based on the log printing instance according to the log printing mode and the log printing format, and storing the target log in the log printing path includes: Generate a target log based on the log printing instance according to the log printing method and the log printing format through multithreading, and store the target log in a cache; A unique consumer process is started to store the target log from the cache to the log printing path.

7. The printing method according to claim 1, characterized in that: Before calling the target printing class pre-created based on the singleton mode and obtaining the log printing parameters input by the user during the editing process, the printing method further includes: Upload the packaged log print file package to the server; In response to a download and installation operation of the log print file package from the server by the user, installing the log print file package to the terminal device of the user; In response to the user's opening operation on the log printing file package, the file packaged in the log printing file package is started.

8. The printing method according to claim 1, characterized in that: Create the target printing class by following the steps below: Call the print method to create the print parameter name and log print level in the initial print class; Determine the corresponding location or log directory based on the different log printing formats set; The number of log files to be retained is set, different printing modes are encapsulated, and the target printing class is created.

9. The printing method according to claim 8, characterized in that: The generating a target log based on the log printing instance according to the log printing method and the log printing format includes: Generate the target log based on the log printing instance, in accordance with the log printing mode and the log printing format, and with reference to the log printing level; The target log with a low log printing level includes log information with a high log printing level.

10. The printing method according to claim 1, characterized in that: The printing method further comprises: Provide log printing program writing examples; The step of obtaining the log printing parameters input by the user during the editing process includes: The log printing parameters input by the user during the editing process of writing the log printing program sample with reference to the log printing program are obtained.

11. A log printing device, characterized in that: The printing device comprises: The printing parameter acquisition module is used to call the target printing class that is pre-created and encapsulated based on the singleton mode to obtain the log printing parameters entered by the user during the editing process; wherein the log printing parameters include the log printing mode, the log printing path and the log printing format; A printing instance creation module, used to call at least one log printing function to create a log printing instance based on the log printing mode, the log printing path and the log printing format; The log printing module is used to generate a target log based on the log printing instance according to the log printing method and the log printing format, and store the target log in the log printing path.

12. An electronic device, characterized in that: include: A processor, a storage medium and a bus, wherein the storage medium stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor communicates with the storage medium via the bus, and the processor executes the machine-readable instructions to perform the steps of the log printing method as described in any one of claims 1 to 10.

13. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the log printing method according to any one of claims 1 to 10 are executed.