WO2016202070A1 - Method and device for recording log in network system - Google Patents

Method and device for recording log in network system Download PDF

Info

Publication number
WO2016202070A1
WO2016202070A1 PCT/CN2016/079204 CN2016079204W WO2016202070A1 WO 2016202070 A1 WO2016202070 A1 WO 2016202070A1 CN 2016079204 W CN2016079204 W CN 2016079204W WO 2016202070 A1 WO2016202070 A1 WO 2016202070A1
Authority
WO
WIPO (PCT)
Prior art keywords
log
file
log file
files
recording
Prior art date
Application number
PCT/CN2016/079204
Other languages
French (fr)
Chinese (zh)
Inventor
朱杰
Original Assignee
中兴通讯股份有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 中兴通讯股份有限公司 filed Critical 中兴通讯股份有限公司
Publication of WO2016202070A1 publication Critical patent/WO2016202070A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/30Monitoring
    • G06F11/34Recording or statistical evaluation of computer activity, e.g. of down time, of input/output operation ; Recording or statistical evaluation of user activity, e.g. usability assessment

Definitions

  • This document relates to, but is not limited to, the field of communications, and relates to a method and apparatus for recording logs in a network system.
  • a log is a file that a device or system uses to log operational information and can be used for fault analysis.
  • the common practice is to write the log directly into the memory or file. Since the log writing is not standardized, it is inefficient in the subsequent management analysis of the log.
  • the formatted log is also configured according to the preset log specification, because different systems have different management requirements for the log, the log is recorded in the same manner, which cannot meet the management requirements of different systems for the log.
  • the embodiment of the invention provides a method and a device for recording logs in a network system, which solves the problem that the log management mode cannot meet the management requirements of the system and the log management efficiency is low.
  • the embodiment of the invention provides a method for recording logs in a network system, including:
  • the log record operation is performed according to the template information of the log.
  • the performing the log recording operation according to the template information of the log includes:
  • the method further includes:
  • the log file with the earliest creation time except the initialization log file is deleted according to the creation time of the log file.
  • the method before the performing the recording operation of the log according to the template information of the log, the method further includes:
  • the new access path of the log file corresponding to the log in the storage area is obtained, and all the log files on the original access path are stored on the new access path.
  • the method further includes:
  • An embodiment of the present invention further provides an apparatus for recording a log in a network system, including:
  • the first obtaining module is configured to obtain configuration information of the log
  • Generating a module configured to generate template information of the log according to the configuration information of the log;
  • the recording module is configured to perform a log recording operation according to the template information of the log when receiving the log record request.
  • the recording module includes:
  • the determining unit is configured to determine whether the size of the current log file exceeds a threshold of a preset file size after adding a log in the current log file;
  • Creating a unit configured to create a new log file if the determining unit determines that the size of the current log file exceeds a threshold of the file size
  • a recording unit configured to record the log using the new log file.
  • the device further includes:
  • the first determining module is configured to determine, after the recording module performs a log recording operation according to the template information of the log, if a new log file is detected, determine whether the total number of the log files exceeds a threshold of a preset number of files. ;
  • the first deletion module is configured to delete the log file with the earliest creation time except the initialization log file according to the creation time of the log file, if the first determination module determines that the total number of the log files exceeds the threshold of the number of the files.
  • the device further includes:
  • the second judging module is configured to determine whether the access path of the log file corresponding to the log in the storage area changes before the recording module performs the log recording operation according to the template information of the log;
  • a second obtaining module configured to: if the second determining module determines that the access path of the log file in the storage area changes, acquiring a new access path of the log file corresponding to the log in the storage area;
  • a storage module that is set to store all log files on the original access path on the new access path.
  • the device further includes:
  • the second deleting module is configured to delete the log file corresponding to the log on the original access path if the second determining module determines that the access path of the log file in the storage area changes.
  • the embodiment of the present invention further provides a computer readable storage medium, where the computer readable storage medium stores computer executable instructions, and when the computer executable instructions are executed, a method for recording a log in a network system is implemented.
  • the above technical solution obtains the configuration information of the log, and learns the management requirements of the external management personnel.
  • the template information of the log is generated according to the log configuration information to ensure the standardization of the log.
  • the template record is directly used.
  • the log makes the recording efficient.
  • the log mode of the embodiment of the present invention can adapt to the management requirements of the system, and the recording efficiency is high.
  • FIG. 1 is a flowchart of a method for recording a log in a network system according to Embodiment 1 of the present invention
  • FIG. 2 is a flowchart of a method for recording a log in a network system according to Example 1 in Embodiment 2 of the present invention
  • FIG. 3 is a flowchart of a method for recording a log in a network system provided by example 2 in Embodiment 2 of the present invention
  • FIG. 4 is a flowchart of a method for recording a log in a network system provided by example 3 in Embodiment 2 of the present invention.
  • FIG. 5 is a schematic structural diagram of an apparatus for recording a log in a network system according to Embodiment 3 of the present invention.
  • FIG. 6 is another schematic structural diagram of an apparatus for recording a log in a network system according to Embodiment 3 of the present invention.
  • FIG. 1 is a flowchart of a method for recording a log in a network system according to an embodiment of the present invention. The method shown in Figure 1 includes:
  • Step 101 Obtain configuration information of a log.
  • Step 102 Generate template information of the log according to the configuration information of the log.
  • Step 103 When receiving the log record request, perform a log recording operation according to the template information of the log.
  • the method provided by the embodiment of the present invention acquires the configuration information of the log, and learns the external administrator.
  • the log management information is generated based on the log configuration information, and the log template information can be generated.
  • the template is used to record the log directly, so that the recording efficiency is high.
  • the recording mode of the log in the embodiment of the present invention can adapt to the management requirements of the system, and the recording efficiency is high.
  • the configuration parameters of the log include at least one of the following: a log preamble (such as a timestamp information), an initialization log file, a log file number, a log file size, an access path of the log file in the storage area, a name of the log file, and a subsequent The name of the newly created log file.
  • a log preamble such as a timestamp information
  • the name of the initialization log file is log_0.txt.
  • the name of the newly created log file may be log_index.txt, where index is a natural number greater than or equal to 1.
  • Log_0.txt generally contains more important information such as system initialization.
  • the log_0.txt file When the number of log files exceeds the threshold of the number of files configured by the log, the log_0.txt file will not be deleted.
  • the advantage of this is that the system initialization can be important.
  • log_0.txt file is not deleted.
  • the remaining files are: log_0.txt, log_2.txt, log_3.txt, log_4.txt.
  • the performing the log recording operation according to the template information of the log includes:
  • the preset file size threshold is 2M (megabytes); after the log is added, if the log file size is greater than 2M, a new log file is created, and the log is recorded in the new log file.
  • the log is recorded by using the new log file, and the method may be as follows:
  • the method further includes: after the recording operation of the log is performed by using the template information of the log, the method further includes:
  • the log file with the earliest creation time except the initialization log file is deleted according to the creation time of the log file.
  • the threshold of the number of pre-set files is three.
  • the existing log files include the initialization log file log_0.txt and the created log files log_1.txt, log_2.txt, and log_3.txt; wherein, log_0.txt To initialize the file, it cannot be deleted. Therefore, when a new log file is created, the name of the new log file is log_4.txt, and it is determined that the total number of current log files exceeds three, and the log file with the earliest creation time is deleted. That is, the log file whose file name is log_1.txt.
  • the method before the performing the recording operation of the log according to the template information of the log, the method further includes:
  • the new access path of the log file corresponding to the log in the storage area is obtained, and all the log files on the original access path are stored on the new access path.
  • the log file and the subsequent log recorded in the original path need to be protected. Save to the new storage path, so store all the log files on the original access path on the new access path, so that users can view all the logs.
  • the method further includes:
  • the log file in the original path may be copied to the new path, and then the log files in the original path may be deleted; or the log file in the original path may be directly moved to the new path.
  • the log file corresponding to the log on the original access path can be deleted because the log file corresponding to the log is stored on the new access path.
  • FIG. 2 is a flowchart of a method for recording logs in a network system provided by this example.
  • the log file size threshold uses the default configuration of 2M
  • the threshold for the number of log files uses the default configuration of 3.
  • the methods of this example include:
  • Step 21 The log module is initialized
  • Step 22 Real-time monitoring of the log record request, when the log is required, step 23 is performed;
  • Step 23 Insert the time information into the log_index.txt file by inserting the time information before each log according to the default configuration.
  • the log file written is the log_1.txt file.
  • Step 24 Determine the size of the log_index.txt file. If the default configuration is 2M, perform the steps. 25; if it does not exceed 2M, continue to step 22;
  • Step 25 Close the log_index.txt file, shape the variable index++, and create a new file log_index.txt in the default configuration directory /log directory;
  • step 25 When you first go to step 25, you need to create a new log file. At this time, log_1.txt is closed. The index value is 1 and the value is 2. Therefore, the newly added log file is log_2.txt, and the subsequent log is written to the log_2.txt file. in. When the next time to step 25, the index value is 3, the new log_3.txt is added, and so on.
  • Step 26 Determine the number of files, if the number of files is greater than the number of default configuration files 3, then proceed to step 27, otherwise continue to step 22;
  • the above technical solution obtains the configuration information of the log, and learns the management requirements of the external management personnel.
  • the template information of the log is generated according to the log configuration information to ensure the standardization of the log.
  • the template is directly used. Recording logs makes the recording efficient; the above-mentioned log recording method can adapt to the management requirements of the system, and the recording efficiency is high.
  • the log file can be managed to ensure the standardization of the log storage.
  • FIG. 3 is a flowchart of a method for recording logs in the network system provided in the second example.
  • the threshold for the number of log files to be modified by the user is 5, and the threshold for the log file size is 1 M.
  • Other parameters are configured by default.
  • the method of this example 2 is as follows:
  • Step 31 Initializing the log module
  • Step 32 Monitor the log record request in real time. When the log record needs to be performed, perform the steps. 33;
  • Step 33 Insert the time information into the log_index.txt file by inserting the time information before each log according to the default configuration.
  • the log file is a log_1.txt file.
  • Step 34 Determine the size of the log_index.txt file. If the size of the log file exceeds the limit (assuming that the file size threshold is 2M before the user manually modifies the parameter, the file size threshold is 1M after the user manually modifies the parameter). Step 35; if the file size is not exceeded, continue to step 32;
  • the user can manually modify the log file size and the number of log files to meet the actual needs of the user.
  • the user can dynamically modify the threshold of the file size and the number of log files according to the actual operation of the system, and the flexible configuration file parameters can be adapted to the dynamic requirements of the system or the user.
  • Step 35 Close the log_index.txt file, shape the variable index++, and create a new file log_index.txt in the default configuration directory/log directory.
  • close log_1.txt, index value After adding 1 to the value 2, the newly added log file is log_2.txt, and the subsequent log is written to the log_2.txt file.
  • the index value is 3, the new log_3.txt is added, and so on.
  • Step 36 Determine the number of files. If the number of files is greater than the maximum number of log files (the default is 3 before the user configures the parameter and 5 after the user configures the parameter), go to step 37, otherwise return to the step. 32;
  • the method provided in the second embodiment obtains the configuration information of the log, learns the management requirements of the external management personnel, and generates the template information of the log according to the log configuration information, so as to ensure the standardization of the log, when receiving the log request request Recording logs directly using templates makes recordings more efficient.
  • the above-mentioned log recording method can adapt to the management requirements of the system, and the recording efficiency is high.
  • the log file can be managed to ensure the standardization of the log storage.
  • FIG. 4 is a flowchart of a method for recording a log in a network system provided in the third embodiment.
  • the user saves the log file save location parameter as: /my/log, and other parameters are configured according to the default.
  • the method of the example includes:
  • Step 41 The log module is initialized
  • Step 42 Real-time monitoring of the log record request, when the log is required, step 43 is performed;
  • Step 43 Insert the time information into the log_index.txt file by inserting the time information before each log according to the default configuration.
  • the log file is a log_1.txt file.
  • Step 44 Determine the size of the log_index.txt file. If the default value of the log file is 2M, the process proceeds to step 45. If the file size is not exceeded, proceed to step 42;
  • Step 45 Close the log_index.txt file and shape the variable index++;
  • log_1.txt is closed, and the index value is increased by 1 and the value is 2.
  • Step 46 Determine whether the file path changes, if there is no change, step 47 is performed; if the change occurs, step 48 is performed;
  • Step 47 Create a new file log_index.txt in the current file path, and perform step 49;
  • step 47 When it is first executed to step 47, the log file log_2.txt is created.
  • Step 48 Copy all the files (including log_0.txt) in the original path to the new path, and delete all the log files (including log_0.txt) in the original path. Then create a new file log_index under the new path.
  • step 45 the index value is incremented by 1 to 3, that is, waiting for the creation of log_3.txt.
  • the process proceeds to step 46, the original is judged.
  • Path A becomes path B, and log_0.txt, log_1.txt under the original path A, and Copy log_2.txt to path B, delete log_0.txt, log_1.txt, and log_2.txt under the original path A, and then create the log file log_3.txt.
  • Step 49 Determine the number of log files, if the number of log files is greater than the number of default configuration files 3, then proceed to step 50, otherwise return to step 42;
  • the method provided in the third example obtains the configuration information of the log, learns the management requirements of the external management personnel, and generates the template information of the log according to the log configuration information, so as to ensure the standardization of the log, when receiving the log request request.
  • the log is directly recorded by the template, so that the recording efficiency is high; the recording mode of the above log can adapt to the management requirements of the system, and the recording efficiency is high.
  • the log file can be managed to ensure the standardization of the log storage.
  • the log files are stored together, which facilitates subsequent user access. .
  • FIG. 5 is a structural diagram of an apparatus for recording a log in a network system according to an embodiment of the present invention.
  • the device shown in Figure 5 includes:
  • the first obtaining module 501 is configured to obtain configuration information of the log
  • the generating module 502 is configured to generate template information of the log according to the configuration information of the log.
  • the recording module 503 is configured to perform a log recording operation according to the template information of the log when receiving the log recording request.
  • the recording module 503 includes:
  • the determining unit 5031 is configured to: after adding a log in the current log file, determine whether the size of the current log file exceeds a threshold of a preset file size;
  • the creating unit 5032 is configured to create a new log file if the determining unit determines that the size of the current log file exceeds a threshold of the file size;
  • a recording unit 5033 is provided to record the log using the new log file.
  • the device further comprises:
  • the first determining module 504 is configured to determine, after the recording module 503 performs the log recording operation by using the template information of the log, if a new log file is detected, determine whether the total number of the log files exceeds the preset number of files. Threshold
  • the first deleting module 505 is configured to: if the first determining module 504 determines that the total number of the log files exceeds the threshold of the number of files, delete the log with the earliest creation time except the initializing log file according to the creation time of the log file. file.
  • the device further comprises:
  • the second judging module 506 is configured to determine whether the access path of the log file corresponding to the log in the storage area changes before the recording module 503 performs the log recording operation according to the template information of the log.
  • the second obtaining module 507 is configured to: if the second determining module 506 determines that the access path of the log file in the storage area changes, acquire a new access path of the log file corresponding to the log in the storage area;
  • the storage module 508 is configured to store all log files of the logs on the original access path on the new access path.
  • the device further comprises:
  • the second deleting module 509 is configured to delete the log file corresponding to the log on the original access path if the second determining module 506 determines that the access path of the log file in the storage area changes.
  • the device provided by the embodiment of the present invention obtains the log configuration information, obtains the management requirement of the log by the external management personnel, and generates the log template information according to the log configuration information, so as to ensure the standardization of the log, and receive the log record request.
  • the recording efficiency is high; the recording mode of the above log can adapt to the management requirements of the system, and the recording efficiency is high.
  • managing the log file can ensure the standardization of the log storage; and by determining whether the access path changes, In order to ensure that the log files are stored together, it is convenient for users to follow up.
  • the embodiment of the present invention further provides a computer readable storage medium, where the computer readable storage medium stores computer executable instructions, and when the computer executable instructions are executed, a method for recording a log in a network system is implemented.
  • all or part of the steps of the above embodiments may also be implemented by using an integrated circuit. These steps may be separately fabricated into individual integrated circuit modules, or multiple modules or steps may be fabricated into a single integrated circuit module. achieve. Thus, the application is not limited to any particular combination of hardware and software.
  • the devices/function modules/functional units in the above embodiments may be implemented by a general-purpose computing device, which may be centralized on a single computing device or distributed over a network of multiple computing devices.
  • each device/function module/functional unit in the above embodiment When each device/function module/functional unit in the above embodiment is implemented in the form of a software function module and sold or used as a stand-alone product, it can be stored in a computer readable storage medium.
  • the above mentioned computer readable storage medium may be a read only memory, a magnetic disk or an optical disk or the like.
  • the log mode of the above technical solution can adapt to the management requirements of the system, and the recording efficiency is high.

Abstract

A method for recording a log in a network system, comprising: acquiring configuration information about a log; generating template information about the log according to the configuration information about the log; and when a log request is received, conducting a recording operation on the log according to the template information about the log.

Description

网络系统中记录日志的方法和装置Method and device for recording logs in network system 技术领域Technical field
本文涉及但不限于通信领域,涉及一种网络系统中记录日志的方法和装置。This document relates to, but is not limited to, the field of communications, and relates to a method and apparatus for recording logs in a network system.
背景技术Background technique
日志是设备或系统用于记录运行信息的文件,可以用于故障分析。相关的日志记录系统中,普遍的做法是直接将日志写入内存或文件中,由于日志写入不具有规范性,在后续对日志进行管理分析时效率低。虽然也有按照预先设置的日志规范进行格式化日志,但是由于不同系统对日志的管理需求不同,按照相同的方式对日志进行记录,不能满足不同系统对日志的管理需求。A log is a file that a device or system uses to log operational information and can be used for fault analysis. In the related logging system, the common practice is to write the log directly into the memory or file. Since the log writing is not standardized, it is inefficient in the subsequent management analysis of the log. Although the formatted log is also configured according to the preset log specification, because different systems have different management requirements for the log, the log is recorded in the same manner, which cannot meet the management requirements of different systems for the log.
因此相关技术中的日志管理方式不能适应系统的管理需求,日志管理效率低。Therefore, the log management mode in the related art cannot meet the management requirements of the system, and the log management efficiency is low.
发明内容Summary of the invention
以下是对本文详细描述的主题的概述。本概述并非是为了限制权利要求的保护范围。The following is an overview of the topics detailed in this document. This Summary is not intended to limit the scope of the claims.
本发明实施例提供一种网络系统中记录日志的方法和装置,解决了日志管理方式不能适应系统的管理需求,日志管理效率低的问题。The embodiment of the invention provides a method and a device for recording logs in a network system, which solves the problem that the log management mode cannot meet the management requirements of the system and the log management efficiency is low.
本发明实施例提供了一种网络系统中记录日志的方法,包括:The embodiment of the invention provides a method for recording logs in a network system, including:
获取日志的配置信息;Obtain the configuration information of the log;
根据所述日志的配置信息,生成日志的模板信息;Generating template information of the log according to the configuration information of the log;
在接收到日志记录请求时,根据所述日志的模板信息进行日志的记录操作。When receiving the log record request, the log record operation is performed according to the template information of the log.
可选地,所述根据所述日志的模板信息进行日志的记录操作,包括:Optionally, the performing the log recording operation according to the template information of the log includes:
在当前日志文件中添加日志后,判断当前日志文件的大小是否超过预先 设置的文件大小的阈值;After adding a log to the current log file, determine whether the current log file size exceeds the advance. The threshold of the set file size;
如果当前日志文件的大小超过所述文件大小的阈值,则创建新的日志文件,并使用所述新的日志文件记录所述日志。If the size of the current log file exceeds the threshold of the file size, a new log file is created and the log is recorded using the new log file.
可选地,所述根据所述日志的模板信息进行日志的记录操作之后,所述方法还包括:Optionally, after the performing the recording operation of the log according to the template information of the log, the method further includes:
在检测到有新的日志文件后,判断日志文件的总数是否超过预先设置的文件个数的阈值;After detecting a new log file, determining whether the total number of log files exceeds a threshold of a preset number of files;
如果日志文件的总数超过所述文件个数的阈值,则根据日志文件的创建时间,删除除初始化日志文件外的创建时间最早的日志文件。If the total number of log files exceeds the threshold of the number of files, the log file with the earliest creation time except the initialization log file is deleted according to the creation time of the log file.
可选地,所述根据所述日志的模板信息进行日志的记录操作之前,所述方法还包括:Optionally, before the performing the recording operation of the log according to the template information of the log, the method further includes:
判断日志对应的日志文件在存储区的访问路径是否发生变化;Determine whether the access path of the log file corresponding to the log changes in the storage area;
如果日志对应的日志文件在存储区的访问路径发生变化,则获取所述日志对应的日志文件在存储区的新的访问路径,并在新的访问路径上存储原访问路径上的全部日志文件。If the log file corresponding to the log file changes in the storage area, the new access path of the log file corresponding to the log in the storage area is obtained, and all the log files on the original access path are stored on the new access path.
可选地,所述方法还包括:Optionally, the method further includes:
如果日志对应的日志文件在存储区的访问路径发生变化,则删除原访问路径上所述日志对应的日志文件。If the log file corresponding to the log changes in the storage path, delete the log file corresponding to the log on the original access path.
本发明实施例还提供一种网络系统中记录日志的装置,包括:An embodiment of the present invention further provides an apparatus for recording a log in a network system, including:
第一获取模块,设置为获取日志的配置信息;The first obtaining module is configured to obtain configuration information of the log;
生成模块,设置为根据所述日志的配置信息,生成日志的模板信息;Generating a module, configured to generate template information of the log according to the configuration information of the log;
记录模块,设置为在接收到日志记录请求时,根据所述日志的模板信息进行日志的记录操作。The recording module is configured to perform a log recording operation according to the template information of the log when receiving the log record request.
可选地,所述记录模块包括:Optionally, the recording module includes:
判断单元,设置为在当前日志文件中添加日志后,判断当前日志文件的大小是否超过预先设置的文件大小的阈值; The determining unit is configured to determine whether the size of the current log file exceeds a threshold of a preset file size after adding a log in the current log file;
创建单元,设置为如果所述判断单元判断当前日志文件的大小超过所述文件大小的阈值,则创建新的日志文件;Creating a unit, configured to create a new log file if the determining unit determines that the size of the current log file exceeds a threshold of the file size;
记录单元,设置为使用所述新的日志文件记录所述日志。A recording unit configured to record the log using the new log file.
可选地,所述装置还包括:Optionally, the device further includes:
第一判断模块,设置为在所述记录模块根据所述日志的模板信息进行日志的记录操作之后,如果检测到有新的日志文件,判断日志文件的总数是否超过预先设置的文件个数的阈值;The first determining module is configured to determine, after the recording module performs a log recording operation according to the template information of the log, if a new log file is detected, determine whether the total number of the log files exceeds a threshold of a preset number of files. ;
第一删除模块,设置为如果所述第一判断模块判断日志文件的总数超过所述文件个数的阈值,则根据日志文件的创建时间,删除除初始化日志文件外的创建时间最早的日志文件。The first deletion module is configured to delete the log file with the earliest creation time except the initialization log file according to the creation time of the log file, if the first determination module determines that the total number of the log files exceeds the threshold of the number of the files.
可选地,所述装置还包括:Optionally, the device further includes:
第二判断模块,设置为在所述记录模块根据所述日志的模板信息进行日志的记录操作之前,判断日志对应的日志文件在存储区的访问路径是否发生变化;The second judging module is configured to determine whether the access path of the log file corresponding to the log in the storage area changes before the recording module performs the log recording operation according to the template information of the log;
第二获取模块,设置为如果所述第二判断模块判断日志文件在存储区的访问路径发生变化,则获取所述日志对应的日志文件在存储区的新的访问路径;a second obtaining module, configured to: if the second determining module determines that the access path of the log file in the storage area changes, acquiring a new access path of the log file corresponding to the log in the storage area;
存储模块,设置为在新的访问路径上存储原访问路径上的全部日志文件。A storage module that is set to store all log files on the original access path on the new access path.
可选地,所述装置还包括:Optionally, the device further includes:
第二删除模块,设置为如果所述第二判断模块判断日志文件在存储区的访问路径发生变化,则删除原访问路径上所述日志对应的日志文件。The second deleting module is configured to delete the log file corresponding to the log on the original access path if the second determining module determines that the access path of the log file in the storage area changes.
本发明实施例还提供一种计算机可读存储介质,所述计算机可读存储介质中存储有计算机可执行指令,所述计算机可执行指令被执行时实现网络系统中记录日志的方法。The embodiment of the present invention further provides a computer readable storage medium, where the computer readable storage medium stores computer executable instructions, and when the computer executable instructions are executed, a method for recording a log in a network system is implemented.
上述技术方案通过获取日志的配置信息,获知外部管理人员对日志的管理需求,根据日志配置信息生成日志的模板信息,可以保证日志的规范性,当接收到日志的记录请求时,直接使用模板记录日志,使得记录的效率高。 本发明实施例的日志方式能够适应系统的管理需求,且记录效率高。The above technical solution obtains the configuration information of the log, and learns the management requirements of the external management personnel. The template information of the log is generated according to the log configuration information to ensure the standardization of the log. When receiving the log request, the template record is directly used. The log makes the recording efficient. The log mode of the embodiment of the present invention can adapt to the management requirements of the system, and the recording efficiency is high.
在阅读并理解了附图和详细描述后,可以明白其它方面。Other aspects will be apparent upon reading and understanding the drawings and detailed description.
附图说明DRAWINGS
图1为本发明实施例一的网络系统中记录日志的方法的流程图;1 is a flowchart of a method for recording a log in a network system according to Embodiment 1 of the present invention;
图2为本发明实施例二中示例一的网络系统中记录日志的方法的流程图;2 is a flowchart of a method for recording a log in a network system according to Example 1 in Embodiment 2 of the present invention;
图3为本发明实施例二中示例二提供的网络系统中记录日志的方法的流程图;3 is a flowchart of a method for recording a log in a network system provided by example 2 in Embodiment 2 of the present invention;
图4为本发明实施例二中示例三提供的网络系统中记录日志的方法的流程图;4 is a flowchart of a method for recording a log in a network system provided by example 3 in Embodiment 2 of the present invention;
图5为本发明实施例三的网络系统中记录日志的装置的结构示意图;5 is a schematic structural diagram of an apparatus for recording a log in a network system according to Embodiment 3 of the present invention;
图6为本发明实施例三的网络系统中记录日志的装置的另一结构示意图。FIG. 6 is another schematic structural diagram of an apparatus for recording a log in a network system according to Embodiment 3 of the present invention.
具体实施方式detailed description
下面将结合附图及具体实施例对本发明实施例的技术方案作进一步的详细描述。需要说明的是,在不冲突的情况下,本申请中的实施例及实施例中的特征可以相互任意组合。The technical solutions of the embodiments of the present invention are further described in detail below with reference to the accompanying drawings and specific embodiments. It should be noted that, in the case of no conflict, the features in the embodiments and the embodiments in the present application may be arbitrarily combined with each other.
实施例一Embodiment 1
图1为本发明实施例提供的网络系统中记录日志的方法的流程图。图1所示方法,包括:FIG. 1 is a flowchart of a method for recording a log in a network system according to an embodiment of the present invention. The method shown in Figure 1 includes:
步骤101、获取日志的配置信息;Step 101: Obtain configuration information of a log.
步骤102、根据所述日志的配置信息,生成日志的模板信息;Step 102: Generate template information of the log according to the configuration information of the log.
步骤103、在接收到日志记录请求时,根据所述日志的模板信息进行日志的记录操作。Step 103: When receiving the log record request, perform a log recording operation according to the template information of the log.
本发明实施例提供的方法,通过获取日志的配置信息,获知外部管理人 员对日志的管理需求,再根据日志配置信息生成日志的模板信息,可以保证日志的规范性,当接收到日志的记录请求时,直接使用模板记录日志,使得记录的效率高;由此可以看出,本发明实施例的日志的记录方式能够适应系统的管理需求,且记录效率高。The method provided by the embodiment of the present invention acquires the configuration information of the log, and learns the external administrator. The log management information is generated based on the log configuration information, and the log template information can be generated. When the log request is received, the template is used to record the log directly, so that the recording efficiency is high. The recording mode of the log in the embodiment of the present invention can adapt to the management requirements of the system, and the recording efficiency is high.
下面对本发明实施例提供的方法作进一步说明:The method provided by the embodiment of the present invention is further described below:
其中,日志的配置参数包括如下至少一种:日志前置(例如时间戳信息)、初始化日志文件、日志文件个数、日志文件大小、日志文件在存储区的访问路径、日志文件的名称和后续新建的日志文件的名称。The configuration parameters of the log include at least one of the following: a log preamble (such as a timestamp information), an initialization log file, a log file number, a log file size, an access path of the log file in the storage area, a name of the log file, and a subsequent The name of the newly created log file.
例如,初始化日志文件的名称为log_0.txt,相应的,后续新建的日志文件的名称可以为log_index.txt,其中,index为大于或等于1的自然数。For example, the name of the initialization log file is log_0.txt. Correspondingly, the name of the newly created log file may be log_index.txt, where index is a natural number greater than or equal to 1.
需要说明的是,实际日志文件个数会比日志配置的文件个数多一个文件log_0.txt。It should be noted that the actual number of log files will be one more log_0.txt than the number of files configured by the log.
log_0.txt一般包含系统初始化等比较重要的信息,当日志文件的个数超出日志配置的文件个数的阈值时,不会删除log_0.txt文件,这样做的好处是可以将系统初始化等比较重要的信息保留下来,所以实际的文件个数会比用户配置的文件个数多一个。比如用户为日志配置的文件个数的阈值是3个文件,则系统中最多会有4个文件log_0.txt、log_1.txt、log_2.txt、log_3.txt(此时index=3),当再创建新的文件log_4.txt时,index=4,此时,不删除log_0.txt文件,删除的文件的名称为log_idx.txt(其中,idx=index-3),所以会删除log_1.txt,删除后当前剩下的文件为:log_0.txt、log_2.txt、log_3.txt、log_4.txt。Log_0.txt generally contains more important information such as system initialization. When the number of log files exceeds the threshold of the number of files configured by the log, the log_0.txt file will not be deleted. The advantage of this is that the system initialization can be important. The information is retained, so the actual number of files will be one more than the number of files configured by the user. For example, if the threshold of the number of files configured by the user for the log is 3 files, then there are up to 4 files in the system, log_0.txt, log_1.txt, log_2.txt, log_3.txt (at this time index=3), when When creating a new file log_4.txt, index=4. At this time, the log_0.txt file is not deleted. The name of the deleted file is log_idx.txt (where idx=index-3), so log_1.txt will be deleted and deleted. The remaining files are: log_0.txt, log_2.txt, log_3.txt, log_4.txt.
在日志文件中写入新的日志后,可能会出现日志文件大小过大的问题,因此为了保证日志文件的规范性,提出如下解决方案:After writing a new log in the log file, the log file size may be too large. Therefore, in order to ensure the standardization of the log file, the following solutions are proposed:
可选地,在本发明实施例中,所述根据所述日志的模板信息进行日志的记录操作,包括:Optionally, in the embodiment of the present invention, the performing the log recording operation according to the template information of the log includes:
在当前日志文件中添加日志后,判断当前日志文件的大小是否超过预先设置的文件大小的阈值;After the log is added to the current log file, it is determined whether the size of the current log file exceeds a preset threshold of the file size;
如果当前日志文件的大小超过所述文件大小的阈值,则创建新的日志文 件,并使用所述新的日志文件记录所述日志。Create a new log file if the size of the current log file exceeds the threshold of the file size And use the new log file to record the log.
举例来说,预先设置的文件大小的阈值为2M(兆);在添加日志后,如果日志文件的大小大于2M,则新建一个日志文件,在新的日志文件中记录日志。For example, the preset file size threshold is 2M (megabytes); after the log is added, if the log file size is greater than 2M, a new log file is created, and the log is recorded in the new log file.
在本实施例中,使用所述新的日志文件记录所述日志,可以有如下方式:In this embodiment, the log is recorded by using the new log file, and the method may be as follows:
将全部日志记录在新的日志文件中;或者,Record all logs in a new log file; or,
将一部分日志记录在原日志文件中,将剩余部分日志记录在新的日志文件中,使得原日志文件的大小和新的日志文件的大小都小于2M。Record a part of the log in the original log file, and record the remaining part of the log in the new log file, so that the size of the original log file and the size of the new log file are both less than 2M.
随着时间的推移,日志会不断增加,为了合理利用存储空间,可选地,所述利用所述日志的模板信息进行日志的记录操作之后,所述方法还包括:The log is continually increased in time. In order to utilize the storage space, the method further includes: after the recording operation of the log is performed by using the template information of the log, the method further includes:
在检测到有新的日志文件后,判断日志文件的总数是否超过预先设置的文件个数的阈值;After detecting a new log file, determining whether the total number of log files exceeds a threshold of a preset number of files;
如果日志文件的总数超过所述文件个数的阈值,则根据日志文件的创建时间,删除除初始化日志文件外的创建时间最早的日志文件。If the total number of log files exceeds the threshold of the number of files, the log file with the earliest creation time except the initialization log file is deleted according to the creation time of the log file.
举例来说,预先设置的文件个数的阈值为3个,已有的日志文件包括初始化日志文件log_0.txt和创建的日志文件log_1.txt、log_2.txt和log_3.txt;其中,log_0.txt为初始化文件,是不能删除的,因此当创建新的日志文件后,其中新的日志文件的名称为log_4.txt,确定当前的日志文件的总数超过3个,则删除创建时间最早的日志文件,即文件名称为log_1.txt的日志文件。For example, the threshold of the number of pre-set files is three. The existing log files include the initialization log file log_0.txt and the created log files log_1.txt, log_2.txt, and log_3.txt; wherein, log_0.txt To initialize the file, it cannot be deleted. Therefore, when a new log file is created, the name of the new log file is log_4.txt, and it is determined that the total number of current log files exceeds three, and the log file with the earliest creation time is deleted. That is, the log file whose file name is log_1.txt.
可选地,所述根据所述日志的模板信息进行日志的记录操作之前,所述方法还包括:Optionally, before the performing the recording operation of the log according to the template information of the log, the method further includes:
判断日志对应的日志文件在存储区的访问路径是否发生变化;Determine whether the access path of the log file corresponding to the log changes in the storage area;
如果日志对应的日志文件在存储区的访问路径发生变化,则获取所述日志对应的日志文件在存储区的新的访问路径,并在新的访问路径上存储原访问路径上的全部日志文件。If the log file corresponding to the log file changes in the storage area, the new access path of the log file corresponding to the log in the storage area is obtained, and all the log files on the original access path are stored on the new access path.
为了方便对日志的管理,当检测到日志对应的日志文件在存储区的访问路径发生变化时,需要将原路径下之前已记录的日志文件及后续的日志都保 存到新的存储路径上,因此在新的访问路径上存储原访问路径上的全部日志文件,以方便用户查阅全部日志。In order to facilitate the management of the log, when it is detected that the log file corresponding to the log changes in the storage path of the storage area, the log file and the subsequent log recorded in the original path need to be protected. Save to the new storage path, so store all the log files on the original access path on the new access path, so that users can view all the logs.
可选地,为了充分利用存储区的存储空间,所述方法还包括:Optionally, in order to fully utilize the storage space of the storage area, the method further includes:
如果日志对应的日志文件在存储区的访问路径发生变化,则删除原访问路径上所述日志对应的日志文件。If the log file corresponding to the log changes in the storage path, delete the log file corresponding to the log on the original access path.
在本实施例中,可以先将原路径下的日志文件拷贝后新路径下,然后再删除原路径下的这些日志文件;还可以直接将原先路径下的日志文件移动到新的路径下。In this embodiment, the log file in the original path may be copied to the new path, and then the log files in the original path may be deleted; or the log file in the original path may be directly moved to the new path.
由于原访问路径上所述日志对应的日志文件已经在新的访问路径上进行了存储,为了避免存储空间的浪费,可以删除原访问路径上所述日志对应的日志文件。The log file corresponding to the log on the original access path can be deleted because the log file corresponding to the log is stored on the new access path.
实施例二Embodiment 2
下面通过具体示例进一步说明本发明实时的技术方案:The real-time technical solution of the present invention is further illustrated by specific examples below:
示例一Example one
图2为本示例提供的网络系统中记录日志的方法的流程图。在本示例中,日志文件大小阈值使用默认配置2M,日志文件个数的阈值使用默认配置3个。FIG. 2 is a flowchart of a method for recording logs in a network system provided by this example. In this example, the log file size threshold uses the default configuration of 2M, and the threshold for the number of log files uses the default configuration of 3.
本示例的方法包括:The methods of this example include:
步骤21:日志模块初始化;Step 21: The log module is initialized;
该初始化过程中将按照日志配置规则在/log目录下创建文件log_index.txt(其中index=0)。During the initialization process, the file log_index.txt (where index=0) is created in the /log directory according to the log configuration rules.
步骤22:实时监控日志记录请求,当需要进行日志时,执行步骤23;Step 22: Real-time monitoring of the log record request, when the log is required, step 23 is performed;
步骤23:根据默认配置在每条日志前插入时间信息将携带时间信息的日志写入log_index.txt文件;Step 23: Insert the time information into the log_index.txt file by inserting the time information before each log according to the default configuration.
首次执行到步骤23时,写入的日志文件是log_1.txt文件。When the first step is performed to step 23, the log file written is the log_1.txt file.
步骤24:判断log_index.txt文件大小,如果超过默认配置2M,执行步骤 25;如果没有超出2M,继续执行步骤22;Step 24: Determine the size of the log_index.txt file. If the default configuration is 2M, perform the steps. 25; if it does not exceed 2M, continue to step 22;
步骤25:关闭log_index.txt文件,整形变量index++,在默认配置目录/log目录下创建新文件log_index.txt;Step 25: Close the log_index.txt file, shape the variable index++, and create a new file log_index.txt in the default configuration directory /log directory;
首次执行到步骤25时,需要创建新日志文件,此时关闭log_1.txt,index值加1后值为2,因此新增加的日志文件为log_2.txt,后续的日志是写入log_2.txt文件中。当下一次再执行到步骤25时,index值为3,新增加log_3.txt,以此类推。When you first go to step 25, you need to create a new log file. At this time, log_1.txt is closed. The index value is 1 and the value is 2. Therefore, the newly added log file is log_2.txt, and the subsequent log is written to the log_2.txt file. in. When the next time to step 25, the index value is 3, the new log_3.txt is added, and so on.
步骤26:判断文件数目,如果文件个数大于默认配置文件个数3,则执行步骤27,否则继续执行步骤22;Step 26: Determine the number of files, if the number of files is greater than the number of default configuration files 3, then proceed to step 27, otherwise continue to step 22;
步骤27:将文件log_idx.txt删除(idx=index-3,其中3是默认配置文件个数),并返回步骤26。Step 27: Delete the file log_idx.txt (idx=index-3, where 3 is the default number of configuration files) and return to step 26.
如果新增log_4.txt文件,这时文件数目大于3个,需要删除log_1.txt文件。If you add a log_4.txt file, the number of files is greater than three, you need to delete the log_1.txt file.
上述技术方案通过获取日志的配置信息,获知外部管理人员对日志的管理需求,再根据日志配置信息生成日志的模板信息,可以保证日志的规范性,当接收到日志的记录请求时,直接使用模板记录日志,使得记录的效率高;上述日志的记录方式能够适应系统的管理需求,且记录效率高。另外,通过判断日志文件的大小和日志文件的总数,对日志文件进行管理,可以保证日志存储的规范性。The above technical solution obtains the configuration information of the log, and learns the management requirements of the external management personnel. The template information of the log is generated according to the log configuration information to ensure the standardization of the log. When receiving the log request, the template is directly used. Recording logs makes the recording efficient; the above-mentioned log recording method can adapt to the management requirements of the system, and the recording efficiency is high. In addition, by judging the size of the log file and the total number of log files, the log file can be managed to ensure the standardization of the log storage.
示例二Example two
图3为本示例二提供的网络系统中记录日志的方法的流程图。在示例二中,用户修改日志文件个数的阈值为5个,日志文件大小阈值为1M,其它参数依照默认配置。本示例二的方法如下:FIG. 3 is a flowchart of a method for recording logs in the network system provided in the second example. In the second example, the threshold for the number of log files to be modified by the user is 5, and the threshold for the log file size is 1 M. Other parameters are configured by default. The method of this example 2 is as follows:
步骤31:日志模块初始化;Step 31: Initializing the log module;
该初始化过程根据默认配置在/log目录下创建log_index.txt文件(此时index=0)。The initialization process creates a log_index.txt file in the /log directory according to the default configuration (in this case, index=0).
步骤32:实时监控日志记录请求,当需要进行日志记录时,执行步骤 33;Step 32: Monitor the log record request in real time. When the log record needs to be performed, perform the steps. 33;
步骤33:根据默认配置在每条日志前插入时间信息将携带时间信息的日志写入log_index.txt文件;Step 33: Insert the time information into the log_index.txt file by inserting the time information before each log according to the default configuration.
首次执行到步骤33时,写入的日志文件是log_1.txt文件。The first time you execute step 33, the log file is a log_1.txt file.
步骤34:判断log_index.txt文件大小,如果超过日志文件大小的限制(假设在用户手动修改参数之前,文件大小阈值为默认配置2M,在用户手动修改该参数之后,文件大小阈值为1M),执行步骤35;如果没有超出上述文件大小,继续执行步骤32;Step 34: Determine the size of the log_index.txt file. If the size of the log file exceeds the limit (assuming that the file size threshold is 2M before the user manually modifies the parameter, the file size threshold is 1M after the user manually modifies the parameter). Step 35; if the file size is not exceeded, continue to step 32;
示例二中用户可以手动修改日志文件大小、日志文件个数的阀值,以便满足用户的实际需求。这样用户可以根据系统实际运行的情况动态修改文件大小及日志文件个数等阀值,通过灵活配置文件参数可以适应系统或用户的动态需求。In the second example, the user can manually modify the log file size and the number of log files to meet the actual needs of the user. In this way, the user can dynamically modify the threshold of the file size and the number of log files according to the actual operation of the system, and the flexible configuration file parameters can be adapted to the dynamic requirements of the system or the user.
步骤35:关闭log_index.txt文件,整形变量index++,在默认配置目录/log目录下创建新文件log_index.txt;首次执行到步骤35时,需要创建新日志文件,此时关闭log_1.txt,index值加1后值为2,因此新增加的日志文件为log_2.txt,后续的日志是写入log_2.txt文件中。当下一次再执行到步骤25时,index值为3,新增加log_3.txt,以此类推。Step 35: Close the log_index.txt file, shape the variable index++, and create a new file log_index.txt in the default configuration directory/log directory. When you first go to step 35, you need to create a new log file. At this time, close log_1.txt, index value. After adding 1 to the value 2, the newly added log file is log_2.txt, and the subsequent log is written to the log_2.txt file. When the next time to step 25, the index value is 3, the new log_3.txt is added, and so on.
步骤36:判断文件数目,如果文件个数大于日志文件最大个数时(在用户配置该参数之前为默认的3个,在用户配置该参数之后为5个),则执行步骤37,否则返回步骤32;Step 36: Determine the number of files. If the number of files is greater than the maximum number of log files (the default is 3 before the user configures the parameter and 5 after the user configures the parameter), go to step 37, otherwise return to the step. 32;
步骤37:将文件log_idx.txt删除(idx=index-log_num,其中log_num为配置参数中日志文件个数),并返回步骤36。Step 37: Delete the file log_idx.txt (idx=index-log_num, where log_num is the number of log files in the configuration parameter), and return to step 36.
本示二提供的方法,通过获取日志的配置信息,获知外部管理人员对日志的管理需求,再根据日志配置信息生成日志的模板信息,可以保证日志的规范性,当接收到日志的记录请求时,直接使用模板记录日志,使得记录的效率高。上述日志的记录方式能够适应系统的管理需求,且记录效率高。另外,通过判断日志文件的大小和日志文件的总数,对日志文件进行管理,可以保证日志存储的规范性。 The method provided in the second embodiment obtains the configuration information of the log, learns the management requirements of the external management personnel, and generates the template information of the log according to the log configuration information, so as to ensure the standardization of the log, when receiving the log request request Recording logs directly using templates makes recordings more efficient. The above-mentioned log recording method can adapt to the management requirements of the system, and the recording efficiency is high. In addition, by judging the size of the log file and the total number of log files, the log file can be managed to ensure the standardization of the log storage.
示例三Example three
图4为本示例三提供的网络系统中记录日志的方法的流程图。在示例三中,用户修改日志文件保存位置参数为:/my/log,其它参数依照默认配置,该示例的方法包括:FIG. 4 is a flowchart of a method for recording a log in a network system provided in the third embodiment. In the third example, the user saves the log file save location parameter as: /my/log, and other parameters are configured according to the default. The method of the example includes:
步骤41:日志模块初始化;Step 41: The log module is initialized;
该过程根据默认配置在/log目录下创建log_index.txt文件(此时index=0)。This process creates a log_index.txt file in the /log directory according to the default configuration (in this case, index=0).
步骤42:实时监控日志记录请求,当需要进行日志时,执行步骤43;Step 42: Real-time monitoring of the log record request, when the log is required, step 43 is performed;
步骤43:根据默认配置在每条日志前插入时间信息将携带时间信息的日志写入log_index.txt文件;Step 43: Insert the time information into the log_index.txt file by inserting the time information before each log according to the default configuration.
首次执行到步骤43时,写入的日志文件是log_1.txt文件。The first time you execute step 43, the log file is a log_1.txt file.
步骤44:判断log_index.txt文件大小,如果超过日志文件默认大小2M的限制,执行步骤45。如果没有超出上述文件大小,继续执行步骤42;Step 44: Determine the size of the log_index.txt file. If the default value of the log file is 2M, the process proceeds to step 45. If the file size is not exceeded, proceed to step 42;
步骤45:关闭log_index.txt文件,整形变量index++;Step 45: Close the log_index.txt file and shape the variable index++;
首次执行到步骤45时,关闭log_1.txt,index值加1后值为2。When it is first executed to step 45, log_1.txt is closed, and the index value is increased by 1 and the value is 2.
步骤46:判断文件路径是否变化,如果没有变化,执行步骤47;如果发生变化执行步骤48;Step 46: Determine whether the file path changes, if there is no change, step 47 is performed; if the change occurs, step 48 is performed;
步骤47:在当前文件路径下创建新文件log_index.txt,并执行步骤49;Step 47: Create a new file log_index.txt in the current file path, and perform step 49;
首次执行到步骤47时,创建日志文件log_2.txt。When it is first executed to step 47, the log file log_2.txt is created.
步骤48:将原先路径下的所有文件(包括log_0.txt)拷贝到新的路径下,并删除原路径下的所有日志文件(包括log_0.txt).然后在新的路径下创建新文件log_index.txt;Step 48: Copy all the files (including log_0.txt) in the original path to the new path, and delete all the log files (including log_0.txt) in the original path. Then create a new file log_index under the new path. TXT;
;
假设,原路径A有日志文件log_0.txt、log_1.txt以及log_2.txt,执行到步骤45时index值加1变为3,也就是说等待创建log_3.txt,执行到步骤46时,判断原路径A变为路径B,需要将原路径A下的log_0.txt、log_1.txt以及 log_2.txt拷贝到路径B下,同时删除原路径A下的log_0.txt、log_1.txt以及log_2.txt,然后创建日志文件log_3.txt。Assume that the original path A has log files log_0.txt, log_1.txt, and log_2.txt. When step 45 is executed, the index value is incremented by 1 to 3, that is, waiting for the creation of log_3.txt. When the process proceeds to step 46, the original is judged. Path A becomes path B, and log_0.txt, log_1.txt under the original path A, and Copy log_2.txt to path B, delete log_0.txt, log_1.txt, and log_2.txt under the original path A, and then create the log file log_3.txt.
步骤49:判断日志文件数目,如果日志文件个数大于默认配置文件个数3,则执行步骤50,否则返回步骤42;Step 49: Determine the number of log files, if the number of log files is greater than the number of default configuration files 3, then proceed to step 50, otherwise return to step 42;
步骤50:将文件log_idx.txt删除(idx=index-3,其中3是默认配置文件个数),并返回步骤49。Step 50: Delete the file log_idx.txt (idx=index-3, where 3 is the default configuration file number), and return to step 49.
本示例三提供的方法,通过获取日志的配置信息,获知外部管理人员对日志的管理需求,再根据日志配置信息生成日志的模板信息,可以保证日志的规范性,当接收到日志的记录请求时,直接使用模板记录日志,使得记录的效率高;上述日志的记录方式能够适应系统的管理需求,且记录效率高。另外,通过判断日志文件的大小和日志文件的总数,对日志文件进行管理,可以保证日志存储的规范性;并且,通过判断访问路径是否发生变化,保证日志文件存储在一起,方便用户后续的查阅。The method provided in the third example obtains the configuration information of the log, learns the management requirements of the external management personnel, and generates the template information of the log according to the log configuration information, so as to ensure the standardization of the log, when receiving the log request request. The log is directly recorded by the template, so that the recording efficiency is high; the recording mode of the above log can adapt to the management requirements of the system, and the recording efficiency is high. In addition, by judging the size of the log file and the total number of log files, the log file can be managed to ensure the standardization of the log storage. Moreover, by determining whether the access path changes, the log files are stored together, which facilitates subsequent user access. .
实施例三Embodiment 3
图5为本发明实施例提供的网络系统中记录日志的装置的结构图。图5所示装置包括:FIG. 5 is a structural diagram of an apparatus for recording a log in a network system according to an embodiment of the present invention. The device shown in Figure 5 includes:
第一获取模块501,设置为获取日志的配置信息;The first obtaining module 501 is configured to obtain configuration information of the log;
生成模块502,设置为根据所述日志的配置信息,生成日志的模板信息;The generating module 502 is configured to generate template information of the log according to the configuration information of the log.
记录模块503,设置为在接收到日志记录请求时,根据所述日志的模板信息进行日志的记录操作。The recording module 503 is configured to perform a log recording operation according to the template information of the log when receiving the log recording request.
可选地,如图6所示,所述记录模块503包括:Optionally, as shown in FIG. 6, the recording module 503 includes:
判断单元5031,设置为在当前日志文件中添加日志后,判断当前日志文件的大小是否超过预先设置的文件大小的阈值;The determining unit 5031 is configured to: after adding a log in the current log file, determine whether the size of the current log file exceeds a threshold of a preset file size;
创建单元5032,设置为如果所述判断单元判断当前日志文件的大小超过所述文件大小的阈值,则创建新的日志文件; The creating unit 5032 is configured to create a new log file if the determining unit determines that the size of the current log file exceeds a threshold of the file size;
记录单元5033,设置为使用所述新的日志文件记录所述日志。A recording unit 5033 is provided to record the log using the new log file.
其中,所述装置还包括:Wherein, the device further comprises:
第一判断模块504,设置为在所述记录模块503利用所述日志的模板信息进行日志的记录操作之后,如果检测到有新的日志文件,判断日志文件的总数是否超过预先设置的文件个数的阈值;The first determining module 504 is configured to determine, after the recording module 503 performs the log recording operation by using the template information of the log, if a new log file is detected, determine whether the total number of the log files exceeds the preset number of files. Threshold
第一删除模块505,设置为如果所述第一判断模块504判断日志文件的总数超过所述文件个数的阈值,则根据日志文件的创建时间,删除除初始化日志文件外的创建时间最早的日志文件。The first deleting module 505 is configured to: if the first determining module 504 determines that the total number of the log files exceeds the threshold of the number of files, delete the log with the earliest creation time except the initializing log file according to the creation time of the log file. file.
其中,所述装置还包括:Wherein, the device further comprises:
第二判断模块506,设置为在所述记录模块503根据所述日志的模板信息进行日志的记录操作之前,判断日志对应的日志文件在存储区的访问路径是否发生变化;The second judging module 506 is configured to determine whether the access path of the log file corresponding to the log in the storage area changes before the recording module 503 performs the log recording operation according to the template information of the log.
第二获取模块507,设置为如果所述第二判断模块506判断日志文件在存储区的访问路径发生变化,则获取所述日志对应的日志文件在存储区的新的访问路径;The second obtaining module 507 is configured to: if the second determining module 506 determines that the access path of the log file in the storage area changes, acquire a new access path of the log file corresponding to the log in the storage area;
存储模块508,设置为在新的访问路径上存储原访问路径上日志的全部日志文件。The storage module 508 is configured to store all log files of the logs on the original access path on the new access path.
其中,所述装置还包括:Wherein, the device further comprises:
第二删除模块509,设置为如果所述第二判断模块506判断日志文件在存储区的访问路径发生变化,则删除原访问路径上所述日志对应的日志文件。The second deleting module 509 is configured to delete the log file corresponding to the log on the original access path if the second determining module 506 determines that the access path of the log file in the storage area changes.
本发明实施例提供的装置,通过获取日志的配置信息,获知外部管理人员对日志的管理需求,再根据日志配置信息生成日志的模板信息,可以保证日志的规范性,当接收到日志的记录请求时,直接使用模板记录日志,使得记录的效率高;上述日志的记录方式能够适应系统的管理需求,且记录效率高。另外,通过判断日志文件的大小和日志文件的总数,对日志文件进行管理,可以保证日志存储的规范性;并且通过判断访问路径是否发生变化,可 以保证日志文件存储在一起,方便用户后续的查阅。The device provided by the embodiment of the present invention obtains the log configuration information, obtains the management requirement of the log by the external management personnel, and generates the log template information according to the log configuration information, so as to ensure the standardization of the log, and receive the log record request. When the log is directly recorded by using the template, the recording efficiency is high; the recording mode of the above log can adapt to the management requirements of the system, and the recording efficiency is high. In addition, by judging the size of the log file and the total number of log files, managing the log file can ensure the standardization of the log storage; and by determining whether the access path changes, In order to ensure that the log files are stored together, it is convenient for users to follow up.
本发明实施例还提供一种计算机可读存储介质,所述计算机可读存储介质中存储有计算机可执行指令,所述计算机可执行指令被执行时实现网络系统中记录日志的方法。The embodiment of the present invention further provides a computer readable storage medium, where the computer readable storage medium stores computer executable instructions, and when the computer executable instructions are executed, a method for recording a log in a network system is implemented.
本领域普通技术人员可以理解上述实施例的全部或部分步骤可以使用计算机程序流程来实现,所述计算机程序可以存储于一计算机可读存储介质中,所述计算机程序在相应的硬件平台上(如系统、设备、装置、器件等)执行,在执行时,包括方法实施例的步骤之一或其组合。One of ordinary skill in the art will appreciate that all or a portion of the steps of the above-described embodiments can be implemented using a computer program flow, which can be stored in a computer readable storage medium, such as on a corresponding hardware platform (eg, The system, device, device, device, etc. are executed, and when executed, include one or a combination of the steps of the method embodiments.
可选地,上述实施例的全部或部分步骤也可以使用集成电路来实现,这些步骤可以被分别制作成一个个集成电路模块,或者将它们中的多个模块或步骤制作成单个集成电路模块来实现。这样,本申请不限制于任何特定的硬件和软件结合。Alternatively, all or part of the steps of the above embodiments may also be implemented by using an integrated circuit. These steps may be separately fabricated into individual integrated circuit modules, or multiple modules or steps may be fabricated into a single integrated circuit module. achieve. Thus, the application is not limited to any particular combination of hardware and software.
上述实施例中的各装置/功能模块/功能单元可以采用通用的计算装置来实现,它们可以集中在单个的计算装置上,也可以分布在多个计算装置所组成的网络上。The devices/function modules/functional units in the above embodiments may be implemented by a general-purpose computing device, which may be centralized on a single computing device or distributed over a network of multiple computing devices.
上述实施例中的各装置/功能模块/功能单元以软件功能模块的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。上述提到的计算机可读取存储介质可以是只读存储器,磁盘或光盘等。When each device/function module/functional unit in the above embodiment is implemented in the form of a software function module and sold or used as a stand-alone product, it can be stored in a computer readable storage medium. The above mentioned computer readable storage medium may be a read only memory, a magnetic disk or an optical disk or the like.
以上所述,仅为本申请的具体实施方式,但本申请的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本申请揭露的技术范围内,可轻易想到变化或替换,都应涵盖在本申请的保护范围之内。因此,本申请的保护范围应以权利要求所述的保护范围为准。The foregoing is only a specific embodiment of the present application, but the scope of protection of the present application is not limited thereto, and any person skilled in the art can easily think of changes or substitutions within the technical scope disclosed in the present application. It should be covered by the scope of protection of this application. Therefore, the scope of protection of the application should be determined by the scope of protection described in the claims.
工业实用性Industrial applicability
上述技术方案的日志方式能够适应系统的管理需求,且记录效率高。 The log mode of the above technical solution can adapt to the management requirements of the system, and the recording efficiency is high.

Claims (10)

  1. 一种网络系统中记录日志的方法,包括:A method for recording logs in a network system, comprising:
    获取日志的配置信息;Obtain the configuration information of the log;
    根据所述日志的配置信息,生成日志的模板信息;Generating template information of the log according to the configuration information of the log;
    在接收到日志请求时,根据所述日志的模板信息进行日志的记录操作。When receiving a log request, the log recording operation is performed according to the template information of the log.
  2. 根据权利要求1所述的方法,其中,所述根据所述日志的模板信息进行日志的记录操作,包括:The method according to claim 1, wherein the performing the recording operation of the log according to the template information of the log comprises:
    在当前日志文件中添加日志后,判断当前日志文件的大小是否超过预先设置的文件大小的阈值;After the log is added to the current log file, it is determined whether the size of the current log file exceeds a preset threshold of the file size;
    如果当前日志文件的大小超过所述文件大小的阈值,则创建新的日志文件,并使用所述新的日志文件记录所述日志。If the size of the current log file exceeds the threshold of the file size, a new log file is created and the log is recorded using the new log file.
  3. 根据权利要求1或2所述的方法,所述根据所述日志的模板信息进行日志的记录操作之后,所述方法还包括:The method according to claim 1 or 2, after the performing the recording operation of the log according to the template information of the log, the method further includes:
    在检测到有新的日志文件后,判断日志文件的总数是否超过预先设置的文件个数的阈值;After detecting a new log file, determining whether the total number of log files exceeds a threshold of a preset number of files;
    如果日志文件的总数超过所述文件个数的阈值,则根据日志文件的创建时间,删除除初始化日志文件外的创建时间最早的日志文件。If the total number of log files exceeds the threshold of the number of files, the log file with the earliest creation time except the initialization log file is deleted according to the creation time of the log file.
  4. 根据权利要求1所述的方法,所述根据所述日志的模板信息进行日志的记录操作之前,所述方法还包括:The method of claim 1, before the performing the recording operation of the log according to the template information of the log, the method further includes:
    判断日志对应的日志文件在存储区的访问路径是否发生变化;Determine whether the access path of the log file corresponding to the log changes in the storage area;
    如果日志对应的日志文件在存储区的访问路径发生变化,则获取所述日志对应的日志文件在存储区的新的访问路径,并在新的访问路径上存储原访问路径上的全部日志文件。If the log file corresponding to the log file changes in the storage area, the new access path of the log file corresponding to the log in the storage area is obtained, and all the log files on the original access path are stored on the new access path.
  5. 根据权利要求4所述的方法,所述方法还包括:The method of claim 4, further comprising:
    如果日志对应的日志文件在存储区的访问路径发生变化,则删除原访问路径上所述日志对应的日志文件。If the log file corresponding to the log changes in the storage path, delete the log file corresponding to the log on the original access path.
  6. 一种网络系统中记录日志的装置,包括: A device for recording logs in a network system, comprising:
    第一获取模块,设置为获取日志的配置信息;The first obtaining module is configured to obtain configuration information of the log;
    生成模块,设置为根据所述日志的配置信息,生成日志的模板信息;Generating a module, configured to generate template information of the log according to the configuration information of the log;
    记录模块,设置为在接收到日志请求时,根据所述日志的模板信息进行日志的记录操作。The recording module is configured to perform a log recording operation according to the template information of the log when receiving the log request.
  7. 根据权利要求6所述的装置,其中,所述记录模块包括:The apparatus of claim 6 wherein said recording module comprises:
    判断单元,设置为在当前日志文件中添加日志后,判断当前日志文件的大小是否超过预先设置的文件大小的阈值;The determining unit is configured to determine whether the size of the current log file exceeds a threshold of a preset file size after adding a log in the current log file;
    创建单元,设置为如果所述判断单元判断当前日志文件的大小超过所述文件大小的阈值,则创建新的日志文件;Creating a unit, configured to create a new log file if the determining unit determines that the size of the current log file exceeds a threshold of the file size;
    记录单元,设置为使用所述新的日志文件记录所述日志。A recording unit configured to record the log using the new log file.
  8. 根据权利要求6或7所述的装置,所述装置还包括:The device according to claim 6 or 7, further comprising:
    第一判断模块,设置为在所述记录模块根据所述日志的模板信息进行日志的记录操作之后,如果检测到有新的日志文件,判断日志文件的总数是否超过预先设置的文件个数的阈值;The first determining module is configured to determine, after the recording module performs a log recording operation according to the template information of the log, if a new log file is detected, determine whether the total number of the log files exceeds a threshold of a preset number of files. ;
    第一删除模块,设置为如果所述第一判断模块判断日志文件的总数超过所述文件个数的阈值,则根据日志文件的创建时间,删除除初始化日志文件外的创建时间最早的日志文件。The first deletion module is configured to delete the log file with the earliest creation time except the initialization log file according to the creation time of the log file, if the first determination module determines that the total number of the log files exceeds the threshold of the number of the files.
  9. 根据权利要求6所述的装置,所述装置还包括:The apparatus of claim 6 further comprising:
    第二判断模块,设置为在所述记录模块根据所述日志的模板信息进行日志的记录操作之前,判断日志对应的日志文件在存储区的访问路径是否发生变化;The second judging module is configured to determine whether the access path of the log file corresponding to the log in the storage area changes before the recording module performs the log recording operation according to the template information of the log;
    第二获取模块,设置为如果所述第二判断模块判断日志文件在存储区的访问路径发生变化,则获取所述日志对应的日志文件在存储区的新的访问路径;a second obtaining module, configured to: if the second determining module determines that the access path of the log file in the storage area changes, acquiring a new access path of the log file corresponding to the log in the storage area;
    存储模块,设置为在新的访问路径上存储原访问路径上的全部日志文件。A storage module that is set to store all log files on the original access path on the new access path.
  10. 根据权利要求9所述的装置,所述装置还包括: The apparatus of claim 9 further comprising:
    第二删除模块,设置为如果所述第二判断模块判断日志文件在存储区的访问路径发生变化,则删除原访问路径上所述日志对应的日志文件。 The second deleting module is configured to delete the log file corresponding to the log on the original access path if the second determining module determines that the access path of the log file in the storage area changes.
PCT/CN2016/079204 2015-06-16 2016-04-13 Method and device for recording log in network system WO2016202070A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201510335333.4 2015-06-16
CN201510335333.4A CN106326082B (en) 2015-06-16 2015-06-16 Method and device for recording log in network system

Publications (1)

Publication Number Publication Date
WO2016202070A1 true WO2016202070A1 (en) 2016-12-22

Family

ID=57544815

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2016/079204 WO2016202070A1 (en) 2015-06-16 2016-04-13 Method and device for recording log in network system

Country Status (2)

Country Link
CN (1) CN106326082B (en)
WO (1) WO2016202070A1 (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115543949A (en) * 2022-09-27 2022-12-30 北京北方华创微电子装备有限公司 Log processing method and semiconductor process equipment

Families Citing this family (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107357686A (en) * 2017-07-20 2017-11-17 郑州云海信息技术有限公司 A kind of daily record delet method and device
CN110309035A (en) * 2018-03-20 2019-10-08 北京乐我无限科技有限责任公司 Log recording method, device, electronic equipment and storage medium
CN109062762A (en) * 2018-07-26 2018-12-21 浙江数链科技有限公司 Formatted log method for pushing and device
CN111143310B (en) * 2018-11-06 2021-05-14 海通证券股份有限公司 Log recording method and device and readable storage medium
CN111459764B (en) * 2020-04-09 2023-12-29 江苏盛海智能科技有限公司 Log management method and terminal

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5892917A (en) * 1995-09-27 1999-04-06 Microsoft Corporation System for log record and log expansion with inserted log records representing object request for specified object corresponding to cached object copies
CN101515245A (en) * 2008-02-21 2009-08-26 卓望数码技术(深圳)有限公司 Operation log recording method and system
CN103412893A (en) * 2013-07-24 2013-11-27 广东电子工业研究院有限公司 Collecting system and collecting method of logs
CN104331487A (en) * 2014-11-13 2015-02-04 携程计算机技术(上海)有限公司 Method and device for processing logs

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102467516A (en) * 2010-11-04 2012-05-23 北京北方微电子基地设备工艺研究中心有限责任公司 Method, device and system for recording logs in equipment control process
CN102799514B (en) * 2011-05-24 2017-02-15 中兴通讯股份有限公司 Method and system for managing log records
JP5946423B2 (en) * 2013-04-26 2016-07-06 インターナショナル・ビジネス・マシーンズ・コーポレーションInternational Business Machines Corporation System log classification method, program and system
CN104636242A (en) * 2015-02-06 2015-05-20 浪潮电子信息产业股份有限公司 Method for automatically deleting repeated content in system logs on basis of Linux operating system

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5892917A (en) * 1995-09-27 1999-04-06 Microsoft Corporation System for log record and log expansion with inserted log records representing object request for specified object corresponding to cached object copies
CN101515245A (en) * 2008-02-21 2009-08-26 卓望数码技术(深圳)有限公司 Operation log recording method and system
CN103412893A (en) * 2013-07-24 2013-11-27 广东电子工业研究院有限公司 Collecting system and collecting method of logs
CN104331487A (en) * 2014-11-13 2015-02-04 携程计算机技术(上海)有限公司 Method and device for processing logs

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115543949A (en) * 2022-09-27 2022-12-30 北京北方华创微电子装备有限公司 Log processing method and semiconductor process equipment
CN115543949B (en) * 2022-09-27 2023-09-08 北京北方华创微电子装备有限公司 Log processing method and semiconductor process equipment

Also Published As

Publication number Publication date
CN106326082B (en) 2020-10-16
CN106326082A (en) 2017-01-11

Similar Documents

Publication Publication Date Title
WO2016202070A1 (en) Method and device for recording log in network system
US8290994B2 (en) Obtaining file system view in block-level data storage systems
US20150006581A1 (en) Method for a Storage Device Accessing a File and Storage Device
JP6328798B2 (en) Automatic archive storage of user-generated media files
US20210133146A1 (en) Method for processing snapshots and distributed block storage system
US10168920B2 (en) Duplexing file system data
US20140101106A1 (en) Log server and log file storage method
US20140297699A1 (en) Apparatus and method for monitoring communication
CN104461380A (en) Data storage method and device
US20190310791A1 (en) Systems and methods for data management of multiple cloud services
WO2021109587A1 (en) File storage method and apparatus, and device and readable storage medium
US20120284225A1 (en) Auto-updatable document parts within content management systems
CN110008197A (en) A kind of data processing method, system and electronic equipment and storage medium
CN104461384B (en) A kind of method for writing data and storage device
CN104978241B (en) A kind of data reconstruction method and device of COW type file systems
CN114329366A (en) Network disk file control method and device, network disk and storage medium
US10102204B2 (en) Maintaining access control lists in non-identity-preserving replicated data repositories
US20190187904A1 (en) Efficient export scheduling using index and schema to determine data distribution
US8656066B2 (en) Monitoring input/output operations to specific storage locations
JP2002312210A5 (en)
CN107491363A (en) A kind of Snapshot Method and device of the storage volume based on linux kernel
WO2021057220A1 (en) Permission management method and device for blockchain ledger, and apparatus
CN109241011B (en) Virtual machine file processing method and device
WO2015196820A1 (en) Method and apparatus for creating jbod file system
US9690499B1 (en) Systems and methods for cloud-based data protection storage

Legal Events

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

Ref document number: 16810811

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 16810811

Country of ref document: EP

Kind code of ref document: A1