WO2018006721A1 - Method and apparatus for storing log file - Google Patents

Method and apparatus for storing log file Download PDF

Info

Publication number
WO2018006721A1
WO2018006721A1 PCT/CN2017/090172 CN2017090172W WO2018006721A1 WO 2018006721 A1 WO2018006721 A1 WO 2018006721A1 CN 2017090172 W CN2017090172 W CN 2017090172W WO 2018006721 A1 WO2018006721 A1 WO 2018006721A1
Authority
WO
WIPO (PCT)
Prior art keywords
log file
disk space
log
determining
file
Prior art date
Application number
PCT/CN2017/090172
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 WO2018006721A1 publication Critical patent/WO2018006721A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor

Definitions

  • the present disclosure relates to the field of communications, for example, to a method and apparatus for storing log files.
  • logging is a widely used means of information logging and fault location.
  • each service module can record some important information of the running process, it can greatly help fault analysis and fault location, and the positioning fault often combines multiple information of multiple service modules. , get a comprehensive analysis.
  • multiple log files can be used to cover the loop. The capacity of each log file is fixed. However, if a service module has a large number of logs generated during a period of time, the logs that have been recorded by the service module will be covered by the loop, which is not conducive to obtaining comprehensive log information, and is not conducive to fault location.
  • a storage method and device for a log file which avoids the phenomenon that a log file of one or more service types of the related technology covers log files of other service types.
  • a method for storing log files including:
  • the method before the recording the log file to the corresponding first disk space according to the service type, the method further includes:
  • the total disk space is divided into a plurality of sub-disk spaces according to a plurality of service types, wherein each of the sub-disk spaces stores a log file of a service type.
  • determine the total disk space on the storage device for storing log files including one of the following:
  • determining the service type of the log file includes:
  • the logging the log file to the corresponding first disk space according to the service type includes:
  • the logging the log file to the corresponding first disk space according to the service type includes:
  • recording the log file to the second disk space includes:
  • the log file is recorded to the second disk space.
  • a storage device for a log file comprising:
  • a receiving module configured to receive a log file
  • a first determining module configured to determine a service type of the log file
  • the recording module is configured to record the log file to the corresponding first disk space according to the service type.
  • the device further includes:
  • a second determining module configured to determine, after the recording module records the log file to the corresponding first disk space according to the service type, total disk space for storing the log file on the storage device;
  • the partitioning module is configured to divide the total disk space into a plurality of sub-disk spaces according to a plurality of service types, wherein each of the sub-disk spaces stores a log file of a service type.
  • the recording module includes:
  • a determining unit configured to determine whether the stored capacity of the first disk space exceeds a first preset threshold
  • a processing unit configured to: when the stored capacity exceeds the preset threshold, obtain a specified log file with the earliest storage time according to a timestamp of multiple log files in the first disk space, and delete the specified log file ;as well as
  • a recording unit configured to record the log file in the first disk space.
  • a computer readable storage medium is arranged to store program code for performing the following steps:
  • An electronic device comprising:
  • At least one processor At least one processor
  • the memory stores instructions executable by the at least one processor, the instructions being executed by the at least one processor to cause the at least one processor to perform the method described above.
  • the log file is received; the service type of the log file is determined; and the log file is recorded to the corresponding first disk space according to the service type. Because the disk space of the log file is corresponding to the service type, the log files of multiple service types are stored in multiple disk spaces, and the log files of multiple service types are not covered by each other. The phenomenon that log files of multiple service types cover log files of other service types.
  • FIG. 1 is a flowchart of a method of storing a log file of Embodiment 1;
  • FIG. 2 is a block diagram showing the structure of a storage device of a log file of Embodiment 2;
  • FIG. 3 is a block diagram 1 of an optional structure of a storage device of a log file of Embodiment 2;
  • FIG. 4 is a block diagram 2 of an optional structure of a storage device of a log file of Embodiment 2;
  • FIG. 5 is a schematic diagram of a limitation of the total capacity occupied by the log of Embodiment 3;
  • FIG. 6 is a schematic diagram showing a storage layout of logs of a plurality of service modules of Embodiment 3 on a disk;
  • FIG. 7 is a schematic structural diagram of hardware of an electronic device according to an embodiment.
  • FIG. 1 is a flowchart of a method for storing a log file according to the embodiment. As shown in FIG. 1 , the process includes the following steps.
  • step 102 a log file is received.
  • step 104 the business type of the log file is determined.
  • step 106 the log file is recorded to the corresponding first disk space according to the service type.
  • the log file is received; the service type of the log file is determined; and the log file is recorded to the corresponding first disk space according to the service type. Because the disk space of the log file is corresponding to the service type, the log files of multiple service types are stored in multiple disk spaces, and the log files of multiple service types are not covered by each other. A problem with log files of multiple business types overwriting log files of other business types.
  • the execution body of the foregoing step may be at least one of a storage device and a control device of the storage device.
  • the foregoing method further includes:
  • the total disk space is divided into multiple subdisk spaces according to multiple service types, wherein each subdisk space stores a log file of a service type.
  • determining the service type of the log file includes: determining a service module for generating a log file according to a file prefix of the log file; and determining a service type according to the service module. Multiple service modules correspond to the service type of multiple generated log files.
  • the log file is recorded to the corresponding first disk space according to the service type, including:
  • the specified log file with the earliest storage time is obtained according to the timestamp of multiple log files in the first disk space, and the specified log file is deleted;
  • the log file is recorded to the corresponding first disk space according to the service type, including:
  • the index number of the second disk space is calculated according to a preset rule
  • logging the log file to the second disk space includes:
  • the log file is recorded to the second disk space.
  • the method of the foregoing embodiment may be implemented by means of software plus a general hardware platform, or may be implemented by hardware.
  • the above technical solution can be embodied in the form of a software product stored in a non-transitory storage medium (such as a read-only memory (ROM), a random access memory (RAM),
  • ROM read-only memory
  • RAM random access memory
  • the magnetic disk or the optical disk may also be stored in a temporary storage medium, and the storage medium includes one or more instructions for causing a terminal device (which may be a mobile phone, a computer, a server, a network device, etc.) to execute the above embodiment.
  • a terminal device which may be a mobile phone, a computer, a server, a network device, etc.
  • a storage device for a log file is provided, and the device can implement the foregoing embodiments and optional embodiments.
  • the term "module” may implement software, hardware, or a combination of software and hardware for a predetermined function.
  • the apparatus described in the following embodiments may be implemented in software, hardware, or a combination of software and hardware.
  • the device includes: a receiving module 20, a first determining module 22, and a recording module 24.
  • the receiving module 20 is arranged to receive a log file.
  • the first determining module 22 is arranged to determine the type of service of the log file.
  • the recording module 24 is arranged to record the log file to the corresponding first disk space according to the type of service.
  • FIG. 3 is a block diagram of an optional structure of a storage device for a log file according to the embodiment. As shown in FIG. 3, the device may include: a second determining module 30 and a dividing module, in addition to all the modules shown in FIG. 32.
  • the second determining module 30 is configured to determine the total disk space on the storage device for storing the log file before the recording module records the log file to the corresponding first disk space according to the service type.
  • the partitioning module 32 is configured to divide the total disk space into a plurality of sub-disk spaces according to a plurality of service types, wherein each sub-disk space stores a log file of a service type.
  • the recording module 24 may include: a determining unit 40, a processing unit 42, and a recording unit 44.
  • the determining unit 40 is configured to determine whether the stored capacity of the first disk space exceeds a first preset threshold.
  • the processing unit 42 is configured to: when the stored capacity exceeds the first preset threshold, obtain the specified log file with the earliest storage time according to the time stamp of the plurality of log files in the first disk space, and delete the specified log file.
  • the recording unit 44 is arranged to record a log file in the first disk space.
  • the foregoing multiple modules may be implemented by software or hardware.
  • the foregoing modules may be implemented by: the foregoing modules are all located in the same processor; or, the multiple modules are respectively located in different combinations in different combinations. In the device.
  • This embodiment provides a method for preventing a log file of a service module from overwriting an important log file of another service module when a log file of a service module increases linearly in a limited disk space.
  • This embodiment can avoid the problem that a service module log existing in the related art covers the logs recorded by the remaining service modules, and provides a method and apparatus for adaptively dividing the log files.
  • the embodiment provides a method and a device for automatically splitting a log file, and can set a preset condition, for example, importing a configuration file, where the disk space occupied by the log file can be configured in the configuration file.
  • the disk space occupied by the service modules of the log file can make each service module occupy a fixed disk space, and the disk space between multiple service modules does not affect each other.
  • the storage space of multiple storage devices may be different. You can also configure the storage space of the log file in the configuration file to take up the percentage of the remaining space of the storage device and the percentage of the storage space occupied by each service module.
  • FIG. 5 is a schematic diagram of the limitation of the total capacity occupied by the log in the embodiment
  • FIG. 6 is a schematic diagram of the storage layout of the logs of the plurality of service modules (module 1, module 2, ..., module n) of the embodiment on the disk.
  • a plurality of files (file-1, file-2, ..., file-x) are logs recorded in the service module (may correspond to the log files in Embodiment 1).
  • n and x are positive integers, respectively.
  • the “capacity” element can store the total capacity S occupied by the positioning log, and the “modules/module” element can store the module that needs to record the log.
  • “Single file size (per- The file-size) element can store the size of a single file. You can obtain the number of service modules M and the name of each service module by reading the configuration file. The file name prefix of the log file generated by each service module can be the service. The name of the module, the file name can contain a timestamp accurate to the second. Each service module can generate multiple files. The disk space occupied by each service module is S/M, and the number of generated files is S/M/size.
  • the total remaining space of the disk can be calculated, and the total capacity S that can be occupied is calculated according to the total proportion of the preset.
  • the percentage occupied by the configuration (percent)
  • the number of generated files is: S1/size.
  • S1 is the total disk space occupied by the service module M1
  • the size is a single file size
  • * is a multiplication operator
  • / is a division operator.
  • log file the file that stores the log is equivalent to disk space or storage.
  • the space number can be in the range of [0, N-1].
  • the method that the log file of a service module does not cover the log files of other service modules may include the following steps.
  • step 2 after a period of time, for example, when the service module p logs, it is detected that the size of the currently recorded file CIndex(p) has exceeded the size defined by the configuration file, and the current log file may be ended and the file may be switched.
  • CIndex'(p) (CIndex(p)+1)%(N)
  • the sequence number (index number) of the log file to be switched to is CIndex'(p), where % is the remainder operator.
  • p is an integer
  • the value of p is [0, N-1]. It is determined whether there is a log file with the sequence number CIndex'(p). If there is a log file with the sequence number CIndex'(p), the sequence number can be deleted.
  • the service module q logs, it is found that the size of the currently recorded file CIndex(q) has exceeded the size defined by the configuration file, and the current log file record can be ended, and the file is switched.
  • the files recorded by the business module p and the business module q are in the same directory (the same type of log is recorded in Under the same directory), but do not affect each other.
  • step three repeat step two until the system starts the mth day and restart the system.
  • m can be a positive integer.
  • step four step one to step three are repeated, and the service module records the log and the loop coverage without affecting each other.
  • This embodiment provides a storage medium.
  • the foregoing storage medium may be configured to store program code for performing the following steps:
  • the log file is recorded to the corresponding first disk space according to the type of the service.
  • the foregoing storage medium may include a USB flash drive, a Read-Only Memory (ROM), a Random Access Memory (RAM), a mobile hard disk, a magnetic disk, or an optical disk.
  • ROM Read-Only Memory
  • RAM Random Access Memory
  • mobile hard disk a magnetic disk
  • optical disk a variety of non-transitory storage media that can store program code, and can also be transitory storage media.
  • the processor executes the receiving log file according to the stored program code in the storage medium.
  • the processor performs a service type determining the log file according to the stored program code in the storage medium.
  • the processor records, according to the stored program code in the storage medium, the log file to the corresponding first disk space according to the service type.
  • the processor may also perform the method in the above embodiments in accordance with stored program code in the storage medium.
  • the plurality of modules or steps described above 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, optionally using computing devices
  • Executable program code is implemented, which may be stored in a storage device for execution by a computing device, and in some cases, may be performed in a different order than that illustrated herein or
  • the steps described are either made separately into a plurality of integrated circuit modules, or a plurality of modules or steps are fabricated as a single integrated circuit module.
  • This embodiment provides a hardware structure diagram of an electronic device.
  • the electronic device includes:
  • At least one processor 70 is exemplified by a processor 70 in FIG. 7; a memory 71; and a communication interface 72 and a bus 73. Among them, the processor 70, the memory 71, and the communication interface 72 can complete communication with each other through the bus 73. Communication interface 72 can carry signals and data. The processor 70 can call the logic instructions in the memory 71 to perform the methods in the above embodiments.
  • logic instructions in the memory 71 described above may be implemented in the form of a software functional unit and sold or used as a stand-alone product, and may be stored in a computer readable storage medium.
  • the memory 71 is a computer readable storage medium and can be used to store software programs, computer executable programs, such as program instructions or modules corresponding to the methods in the above embodiments.
  • the processor 70 executes the functional application and the data processing by executing a software program, an instruction or a module stored in the memory 71, that is, implementing the method in the above embodiment.
  • the memory 71 may include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application required for at least one function; the storage data area may store data created according to usage of the terminal device, and the like. Further, the memory 71 may include a high speed random access memory, and may also include a nonvolatile memory.
  • the storage method and device of the log file are used to avoid the phenomenon that the log files of one or more service types of the related technology cover the log files of other service types.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Debugging And Monitoring (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

A method and apparatus for storing a log file. The method comprises: receiving a log file (102); determining a service type of the log file (104); and according to the service type, recording the log file to a corresponding first disk space (106).

Description

日志文件的存储方法及装置Log file storage method and device 技术领域Technical field
本公开涉及通信领域,例如,涉及一种日志文件的存储方法及装置。The present disclosure relates to the field of communications, for example, to a method and apparatus for storing log files.
背景技术Background technique
在多种系统中,记录日志是一种广泛使用的信息记录、故障定位的手段。例如在定位故障过程中,如果每个业务模块可以将运行过程的一些重要信息记录下来,可以给故障分析及故障定位带来极大帮助,而定位故障往往要结合多个业务模块的多种信息,得到全面的分析。记录同一种日志文件时,可以采用多个日志文件循环覆盖的方式,每个日志文件的容量是固定的。但是如果一个业务模块在一时间段有大量日志产生,则该业务模块已经记录下来的日志会被循环覆盖,不利于获取全面的日志信息,也不利于故障定位。In a variety of systems, logging is a widely used means of information logging and fault location. For example, in the process of locating faults, if each service module can record some important information of the running process, it can greatly help fault analysis and fault location, and the positioning fault often combines multiple information of multiple service modules. , get a comprehensive analysis. When the same log file is recorded, multiple log files can be used to cover the loop. The capacity of each log file is fixed. However, if a service module has a large number of logs generated during a period of time, the logs that have been recorded by the service module will be covered by the loop, which is not conducive to obtaining comprehensive log information, and is not conducive to fault location.
针对相关技术中存在的上述问题,尚未发现相关的解决方案。Regarding the above problems existing in the related art, no related solutions have been found.
发明内容Summary of the invention
一种日志文件的存储方法及装置,避免相关技术中一种或多种业务类型的日志文件覆盖其他业务类型的日志文件的现象。A storage method and device for a log file, which avoids the phenomenon that a log file of one or more service types of the related technology covers log files of other service types.
一种日志文件的存储方法,包括:A method for storing log files, including:
接收日志文件;Receive log files;
确定所述日志文件的业务类型;以及Determining the type of business of the log file;
根据所述业务类型将所述日志文件记录到对应的第一磁盘空间。Recording the log file to the corresponding first disk space according to the service type.
可选的,在根据所述业务类型将所述日志文件记录到对应的第一磁盘空间之前,所述方法还包括:Optionally, before the recording the log file to the corresponding first disk space according to the service type, the method further includes:
确定存储设备上用于存储日志文件的总磁盘空间;以及Determine the total disk space on the storage device used to store log files;
根据多个业务类型将所述总磁盘空间划分为多个子磁盘空间,其中,每个所述子磁盘空间存放一种业务类型的日志文件。 The total disk space is divided into a plurality of sub-disk spaces according to a plurality of service types, wherein each of the sub-disk spaces stores a log file of a service type.
可选的,确定存储设备上用于存储日志文件的总磁盘空间包括以下之一:Optionally, determine the total disk space on the storage device for storing log files, including one of the following:
确定存储设备上预设的用于存储日志文件的所述总磁盘空间;以及Determining the total disk space preset on the storage device for storing log files;
确定所述存储设备的剩余容量,以及所述总磁盘空间占所述剩余容量的预设百分比,并根据所述剩余容量和所述预设百分比确定所述总磁盘空间。Determining a remaining capacity of the storage device, and the total disk space occupies a preset percentage of the remaining capacity, and determining the total disk space according to the remaining capacity and the preset percentage.
可选的,确定所述日志文件的业务类型包括:Optionally, determining the service type of the log file includes:
根据所述日志文件的文件前缀确定生成所述日志文件的业务模块;以及Determining, according to a file prefix of the log file, a service module that generates the log file;
根据所述业务模块确定所述业务类型。Determining the service type according to the service module.
可选的,根据所述业务类型将所述日志文件记录到对应的第一磁盘空间包括:Optionally, the logging the log file to the corresponding first disk space according to the service type includes:
判断所述第一磁盘空间的已存储容量是否超过预设阈值;Determining whether the stored capacity of the first disk space exceeds a preset threshold;
在所述已存储容量超过所述预设阈值时,根据所述第一磁盘空间内多个日志文件的时间戳得到存储时间最早的指定日志文件,并删除所述指定日志文件;以及And when the stored capacity exceeds the preset threshold, obtaining a specified log file with the earliest storage time according to a timestamp of multiple log files in the first disk space, and deleting the specified log file;
在所述第一磁盘空间内记录所述日志文件。Recording the log file in the first disk space.
可选的,根据所述业务类型将所述日志文件记录到对应的第一磁盘空间包括:Optionally, the logging the log file to the corresponding first disk space according to the service type includes:
判断所述第一磁盘空间的已存储容量是否超过第二预设阈值;Determining whether the stored capacity of the first disk space exceeds a second preset threshold;
在所述第一磁盘空间的已存储容量超过第二预设阈值时,根据预设规则计算得到第二磁盘空间的索引号;以及When the stored capacity of the first disk space exceeds a second preset threshold, calculating an index number of the second disk space according to a preset rule;
将所述日志文件记录到所述第二磁盘空间。Recording the log file to the second disk space.
可选的,将所述日志文件记录到所述第二磁盘空间包括:Optionally, recording the log file to the second disk space includes:
在已经存在所述第二磁盘空间的情况下,删除所述第二磁盘空间原存储的数据后,将所述日志文件记录到所述第二磁盘空间;After the second disk space already exists, after the data originally stored in the second disk space is deleted, the log file is recorded to the second disk space;
在不存在所述第二磁盘空间的情况下,创建所述第二磁盘空间后,将所述日志文件记录到所述第二磁盘空间。In the case where the second disk space does not exist, after the second disk space is created, the log file is recorded to the second disk space.
一种日志文件的存储装置,包括: A storage device for a log file, comprising:
接收模块,设置为接收日志文件;a receiving module, configured to receive a log file;
第一确定模块,设置为确定所述日志文件的业务类型;以及a first determining module, configured to determine a service type of the log file;
记录模块,设置为根据所述业务类型将所述日志文件记录到对应的第一磁盘空间。The recording module is configured to record the log file to the corresponding first disk space according to the service type.
可选的,所述装置还包括:Optionally, the device further includes:
第二确定模块,设置为在所述记录模块根据所述业务类型将所述日志文件记录到对应的第一磁盘空间之前,确定存储设备上用于存储日志文件的总磁盘空间;以及a second determining module, configured to determine, after the recording module records the log file to the corresponding first disk space according to the service type, total disk space for storing the log file on the storage device;
划分模块,设置为根据多个业务类型将所述总磁盘空间划分为多个子磁盘空间,其中,每个所述子磁盘空间存储一种业务类型的日志文件。The partitioning module is configured to divide the total disk space into a plurality of sub-disk spaces according to a plurality of service types, wherein each of the sub-disk spaces stores a log file of a service type.
可选的,所述记录模块包括:Optionally, the recording module includes:
判断单元,设置为判断所述第一磁盘空间的已存储容量是否超过第一预设阈值;a determining unit, configured to determine whether the stored capacity of the first disk space exceeds a first preset threshold;
处理单元,设置为在所述已存储容量超过所述预设阈值时,根据所述第一磁盘空间内多个日志文件的时间戳得到存储时间最早的指定日志文件,并删除所述指定日志文件;以及a processing unit, configured to: when the stored capacity exceeds the preset threshold, obtain a specified log file with the earliest storage time according to a timestamp of multiple log files in the first disk space, and delete the specified log file ;as well as
记录单元,设置为在所述第一磁盘空间内记录所述日志文件。a recording unit configured to record the log file in the first disk space.
一种计算机可读存储介质。该存储介质设置为存储用于执行以下步骤的程序代码:A computer readable storage medium. The storage medium is arranged to store program code for performing the following steps:
接收日志文件;Receive log files;
确定所述日志文件的业务类型;以及Determining the type of business of the log file;
根据所述业务类型将所述日志文件记录到对应的第一磁盘空间。Recording the log file to the corresponding first disk space according to the service type.
一种电子设备,包括:An electronic device comprising:
至少一个处理器;以及At least one processor;
与所述至少一个处理器通信连接的存储器;其中,a memory communicatively coupled to the at least one processor; wherein
所述存储器存储有可被所述至少一个处理器执行的指令,所述指令被所述至少一个处理器执行,以使所述至少一个处理器执行上述的方法。 The memory stores instructions executable by the at least one processor, the instructions being executed by the at least one processor to cause the at least one processor to perform the method described above.
以上方案中,接收日志文件;确定所述日志文件的业务类型;根据所述业务类型将所述日志文件记录到对应的第一磁盘空间。由于记录日志文件的磁盘空间是与业务类型对应的,多个业务类型的日志文件分别存放在多个磁盘空间中,多种业务类型的日志文件不会相互覆盖,可以避免相关技术中一种或多种业务类型的日志文件覆盖其他业务类型的日志文件的现象。In the above solution, the log file is received; the service type of the log file is determined; and the log file is recorded to the corresponding first disk space according to the service type. Because the disk space of the log file is corresponding to the service type, the log files of multiple service types are stored in multiple disk spaces, and the log files of multiple service types are not covered by each other. The phenomenon that log files of multiple service types cover log files of other service types.
附图说明DRAWINGS
此处所说明的附图用来提供对以下实施例的理解。在附图中:The drawings illustrated herein are provided to provide an understanding of the following embodiments. In the drawing:
图1是实施例1的日志文件的存储方法的流程图;1 is a flowchart of a method of storing a log file of Embodiment 1;
图2是实施例2的日志文件的存储装置的结构框图;2 is a block diagram showing the structure of a storage device of a log file of Embodiment 2;
图3是实施例2的日志文件的存储装置的可选结构框图一;3 is a block diagram 1 of an optional structure of a storage device of a log file of Embodiment 2;
图4是实施例2的日志文件的存储装置的可选结构框图二;4 is a block diagram 2 of an optional structure of a storage device of a log file of Embodiment 2;
图5是实施例3的日志占用的总容量的限制的示意图;5 is a schematic diagram of a limitation of the total capacity occupied by the log of Embodiment 3;
图6是实施例3的多个业务模块的日志在磁盘上的存储布局示意图;以及6 is a schematic diagram showing a storage layout of logs of a plurality of service modules of Embodiment 3 on a disk;
图7是一实施例提供的电子设备的硬件结构示意图。FIG. 7 is a schematic structural diagram of hardware of an electronic device according to an embodiment.
具体实施方式detailed description
下文中将参考附图并结合实施例来详细说明技术方案。在不冲突的情况下,以下实施例及实施例中的特征可以相互组合。The technical solutions will be described in detail below with reference to the accompanying drawings in conjunction with the embodiments. The features of the following embodiments and examples may be combined with each other without conflict.
说明书和权利要求书及上述附图中的术语“第一”、“第二”等是用于区别类似的对象,而不必用于描述特定的顺序或先后次序。The terms "first", "second" and the like in the specification and claims and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a particular order or order.
实施例1Example 1
本实施例提供了一种日志文件的存储方法,图1是本实施例的日志文件的存储方法的流程图,如图1所示,该流程包括如下步骤。This embodiment provides a method for storing a log file. FIG. 1 is a flowchart of a method for storing a log file according to the embodiment. As shown in FIG. 1 , the process includes the following steps.
在步骤102中,接收日志文件。In step 102, a log file is received.
在步骤104中,确定日志文件的业务类型。In step 104, the business type of the log file is determined.
在步骤106中,根据业务类型将日志文件记录到对应的第一磁盘空间。 In step 106, the log file is recorded to the corresponding first disk space according to the service type.
通过上述步骤,接收日志文件;确定日志文件的业务类型;根据业务类型将日志文件记录到对应的第一磁盘空间。由于记录日志文件的磁盘空间是与业务类型对应的,多个业务类型的日志文件分别存放在多个磁盘空间中,多种业务类型的日志文件不会相互覆盖,可以避免相关技术中一种或多种业务类型的日志文件覆盖其他业务类型的日志文件的问题。Through the above steps, the log file is received; the service type of the log file is determined; and the log file is recorded to the corresponding first disk space according to the service type. Because the disk space of the log file is corresponding to the service type, the log files of multiple service types are stored in multiple disk spaces, and the log files of multiple service types are not covered by each other. A problem with log files of multiple business types overwriting log files of other business types.
可选地,上述步骤的执行主体可以为存储设备和存储设备的控制设备中的至少之一。Optionally, the execution body of the foregoing step may be at least one of a storage device and a control device of the storage device.
可选的,在根据业务类型将日志文件记录到对应的第一磁盘空间之前,上述方法还包括:Optionally, before the log file is recorded to the corresponding first disk space according to the service type, the foregoing method further includes:
确定存储设备上用于存储日志文件的总磁盘空间;以及Determine the total disk space on the storage device used to store log files;
根据多个业务类型将总磁盘空间划分为多个子磁盘空间,其中,每个子磁盘空间存放一种业务类型的日志文件。The total disk space is divided into multiple subdisk spaces according to multiple service types, wherein each subdisk space stores a log file of a service type.
可选的,使用以下两种方式之一确定存储设备上用于存储日志文件的总磁盘空间:Optionally, use one of the following two methods to determine the total disk space on the storage device for storing log files:
确定存储设备上预设的用于存储日志文件的总磁盘空间;以及Determine the total disk space preset on the storage device for storing log files;
确定存储设备的剩余容量,以及总磁盘空间占剩余容量的预设百分比,并根据剩余容量和预设百分比确定总磁盘空间。Determine the remaining capacity of the storage device, and the total disk space as a percentage of the remaining capacity, and determine the total disk space based on the remaining capacity and the preset percentage.
可选的,确定日志文件的业务类型包括:根据日志文件的文件前缀确定生成日志文件的业务模块;以及根据业务模块确定业务类型。多个业务模块对应多个生成的日志文件的业务类型。Optionally, determining the service type of the log file includes: determining a service module for generating a log file according to a file prefix of the log file; and determining a service type according to the service module. Multiple service modules correspond to the service type of multiple generated log files.
可选的,根据业务类型将日志文件记录到对应的第一磁盘空间包括:Optionally, the log file is recorded to the corresponding first disk space according to the service type, including:
判断第一磁盘空间的已存储容量是否超过第一预设阈值;Determining whether the stored capacity of the first disk space exceeds a first preset threshold;
在所述已存储容量超过所述第一预设阈值时,根据第一磁盘空间内多个日志文件的时间戳得到存储时间最早的指定日志文件,并删除指定日志文件;以及When the stored capacity exceeds the first preset threshold, the specified log file with the earliest storage time is obtained according to the timestamp of multiple log files in the first disk space, and the specified log file is deleted;
在第一磁盘空间内记录日志文件。Log files are recorded in the first disk space.
可选的,根据业务类型将日志文件记录到对应的第一磁盘空间包括: Optionally, the log file is recorded to the corresponding first disk space according to the service type, including:
判断第一磁盘空间的已存储容量是否超过第二预设阈值;Determining whether the stored capacity of the first disk space exceeds a second preset threshold;
在第一磁盘空间的已存储容量超过第二预设阈值时,根据预设规则计算得到第二磁盘空间的索引号;以及When the stored capacity of the first disk space exceeds a second preset threshold, the index number of the second disk space is calculated according to a preset rule;
将日志文件记录到第二磁盘空间。Log the log file to the second disk space.
若第一磁盘的索引号为A,在第一磁盘空间的已存储容量超过第二预设阈值时,可以通过公式得到第二磁盘的索引号B=A+a,a可以为用户设置的自然数。If the index of the first disk is A, when the stored capacity of the first disk space exceeds the second preset threshold, the index number of the second disk B=A+a can be obtained by the formula, and a can be a natural number set by the user. .
可选的,将日志文件记录到第二磁盘空间包括:Optionally, logging the log file to the second disk space includes:
在已经存在第二磁盘空间的情况下,删除第二磁盘空间原存储的数据后,将日志文件记录到第二磁盘空间;After the second disk space already exists, after the data originally stored in the second disk space is deleted, the log file is recorded to the second disk space;
在不存在第二磁盘空间的情况下,创建第二磁盘空间后,将日志文件记录到第二磁盘空间。In the case where the second disk space does not exist, after the second disk space is created, the log file is recorded to the second disk space.
通过以上的实施方式的描述,上述实施例的方法可借助软件加通用硬件平台的方式来实现,也可以通过硬件的方式实现。以上技术方案可以以软件产品的形式体现出来,该计算机软件产品存储在一个非暂态存储介质(如只读存储器(Read-Only Memory,ROM)、随机存取存储器(Random Access Memory,RAM)、磁碟、光盘)中,也可以存储在暂态存储介质中,存储介质包括一个或多个指令用以使得一台终端设备(可以是手机,计算机,服务器,或者网络设备等)执行上述实施例的方法。Through the description of the foregoing embodiments, the method of the foregoing embodiment may be implemented by means of software plus a general hardware platform, or may be implemented by hardware. The above technical solution can be embodied in the form of a software product stored in a non-transitory storage medium (such as a read-only memory (ROM), a random access memory (RAM), The magnetic disk or the optical disk may also be stored in a temporary storage medium, and the storage medium includes one or more instructions for causing a terminal device (which may be a mobile phone, a computer, a server, a network device, etc.) to execute the above embodiment. Methods.
实施例2Example 2
在本实施例中提供了一种日志文件的存储装置,该装置可以实现上述实施例及可选实施方式。如以下所使用的,术语“模块”可以实现预定功能的软件,硬件,或软件和硬件的组合。以下实施例所描述的装置可以以软件,硬件,或者软件和硬件的组合来实现。In this embodiment, a storage device for a log file is provided, and the device can implement the foregoing embodiments and optional embodiments. As used hereinafter, the term "module" may implement software, hardware, or a combination of software and hardware for a predetermined function. The apparatus described in the following embodiments may be implemented in software, hardware, or a combination of software and hardware.
图2是本实施例的日志文件的存储装置的结构框图,如图2所示,该装置包括;接收模块20、第一确定模块22以及记录模块24。2 is a structural block diagram of a storage device of a log file according to the embodiment. As shown in FIG. 2, the device includes: a receiving module 20, a first determining module 22, and a recording module 24.
接收模块20设置为接收日志文件。The receiving module 20 is arranged to receive a log file.
第一确定模块22设置为确定日志文件的业务类型。 The first determining module 22 is arranged to determine the type of service of the log file.
记录模块24设置为根据业务类型将日志文件记录到对应的第一磁盘空间。The recording module 24 is arranged to record the log file to the corresponding first disk space according to the type of service.
图3是本实施例的日志文件的存储装置的可选结构框图一,如图3所示,该装置除包括图2所示的所有模块外,还可以包括:第二确定模块30和划分模块32。3 is a block diagram of an optional structure of a storage device for a log file according to the embodiment. As shown in FIG. 3, the device may include: a second determining module 30 and a dividing module, in addition to all the modules shown in FIG. 32.
第二确定模块30设置为在记录模块根据业务类型将日志文件记录到对应的第一磁盘空间之前,确定存储设备上用于存储日志文件的总磁盘空间。The second determining module 30 is configured to determine the total disk space on the storage device for storing the log file before the recording module records the log file to the corresponding first disk space according to the service type.
划分模块32设置为根据多个业务类型将总磁盘空间划分为多个子磁盘空间,其中,每个子磁盘空间存储一种业务类型的日志文件。The partitioning module 32 is configured to divide the total disk space into a plurality of sub-disk spaces according to a plurality of service types, wherein each sub-disk space stores a log file of a service type.
图4是本实施例的日志文件的存储装置的可选结构框图二,在上述实施例的基础上,记录模块24可以包括:判断单元40、处理单元42和记录单元44。4 is a block diagram 2 of an optional structure of a storage device for a log file according to the embodiment. On the basis of the foregoing embodiment, the recording module 24 may include: a determining unit 40, a processing unit 42, and a recording unit 44.
判断单元40设置为判断第一磁盘空间的已存储容量是否超过第一预设阈值。The determining unit 40 is configured to determine whether the stored capacity of the first disk space exceeds a first preset threshold.
处理单元42设置为在已存储容量超过第一预设阈值时,根据第一磁盘空间内多个日志文件的时间戳得到存储时间最早的指定日志文件,并删除指定日志文件。The processing unit 42 is configured to: when the stored capacity exceeds the first preset threshold, obtain the specified log file with the earliest storage time according to the time stamp of the plurality of log files in the first disk space, and delete the specified log file.
记录单元44设置为在第一磁盘空间内记录日志文件。The recording unit 44 is arranged to record a log file in the first disk space.
上述多个模块是可以通过软件或硬件来实现的,对于硬件实现方式,可以通过以下方式实现:上述模块均位于同一处理器中;或者,上述多个模块以任意组合的形式分别位于不同的处理器中。The foregoing multiple modules may be implemented by software or hardware. For the hardware implementation, the foregoing modules may be implemented by: the foregoing modules are all located in the same processor; or, the multiple modules are respectively located in different combinations in different combinations. In the device.
实施例3Example 3
本实施例提供了一种在有限的磁盘空间内一个业务模块的日志文件线性增长过快时,防止该业务模块的日志文件覆盖其他业务模块的重要日志文件的方法。This embodiment provides a method for preventing a log file of a service module from overwriting an important log file of another service module when a log file of a service module increases linearly in a limited disk space.
本实施例可以避免相关技术中存在的一种业务模块日志覆盖其余业务模块记录的日志的问题,并提供一种自适应分割日志文件的方法和装置。This embodiment can avoid the problem that a service module log existing in the related art covers the logs recorded by the remaining service modules, and provides a method and apparatus for adaptively dividing the log files.
本实施例提供了一种自适应分割日志文件的方法和装置,可以设置预设条件,比如引入一个配置文件,在配置文件中可以配置日志文件占用的磁盘空间 以及日志文件的业务模块占用的磁盘空间,可以使得每个业务模块占用固定的磁盘空间,多个业务模块之间的磁盘空间互不影响。由于多个存储设备的存储空间可能不同,也可以在配置文件中配置日志文件的存储空间占用存储设备的磁盘剩余空间的百分比以及每个业务模块的存储空间占用磁盘剩余空间的百分比。The embodiment provides a method and a device for automatically splitting a log file, and can set a preset condition, for example, importing a configuration file, where the disk space occupied by the log file can be configured in the configuration file. The disk space occupied by the service modules of the log file can make each service module occupy a fixed disk space, and the disk space between multiple service modules does not affect each other. The storage space of multiple storage devices may be different. You can also configure the storage space of the log file in the configuration file to take up the percentage of the remaining space of the storage device and the percentage of the storage space occupied by each service module.
采用本实施例,能够解决一个业务模块的日志文件的线性增长过快时,该业务模块的日志文件覆盖其他业务模块的重要日志文件的问题。与相关技术相比,即使一业务模块的日志文件的数量在短时间内线性爆发式增长,仍然可以保证其它业务模块记录的重要日志文件不会被循环覆盖,可以获取全面的故障信息。With this embodiment, it is possible to solve the problem that the log file of the service module covers important log files of other service modules when the linear growth of the log file of one service module is too fast. Compared with the related technology, even if the number of log files of a service module increases linearly in a short time, it can be ensured that important log files recorded by other service modules are not covered by the loop, and comprehensive fault information can be obtained.
图5是本实施例的日志占用的总容量的限制的示意图,图6是本实施例的多个业务模块(模块1、模块2、…、模块n)的日志在磁盘上的存储布局示意图,图6中,多个文件(file)(file-1、file-2、…、file-x)为业务模块内记录的日志(可以相当于实施例1中的日志文件)。其中,n、x分别为正整数。5 is a schematic diagram of the limitation of the total capacity occupied by the log in the embodiment, and FIG. 6 is a schematic diagram of the storage layout of the logs of the plurality of service modules (module 1, module 2, ..., module n) of the embodiment on the disk. In FIG. 6, a plurality of files (file-1, file-2, ..., file-x) are logs recorded in the service module (may correspond to the log files in Embodiment 1). Where n and x are positive integers, respectively.
预设条件的配置文件中,“容量(capacity)”元素可以存储定位日志占用的总容量S,“模块(modules/module)”元素可以存储需要记录本日志的模块,“单个文件大小(per-file-size)”元素可以存储单个文件的大小(size),通过读取配置文件可以获取业务模块数M以及每个业务模块的名称,每个业务模块生成的日志文件的文件名前缀可以为业务模块的名称,文件名可以包含精确到秒的时间戳。每个业务模块可以分别生成多个文件,每个业务模块占用的磁盘空间为:S/M,生成的文件个数为:S/M/size。其中,S为定位日志占用的磁盘总容量;M为业务模块数,size为单个文件大小,/为除法运算符。当一个业务模块的文件个数被写满且需要生成新文件时,时间戳最早的文件被自动删除。In the configuration file of the preset condition, the “capacity” element can store the total capacity S occupied by the positioning log, and the “modules/module” element can store the module that needs to record the log. “Single file size (per- The file-size) element can store the size of a single file. You can obtain the number of service modules M and the name of each service module by reading the configuration file. The file name prefix of the log file generated by each service module can be the service. The name of the module, the file name can contain a timestamp accurate to the second. Each service module can generate multiple files. The disk space occupied by each service module is S/M, and the number of generated files is S/M/size. S is the total disk capacity occupied by the location log; M is the number of service modules, size is a single file size, and / is a division operator. When the number of files in a business module is full and a new file needs to be generated, the file with the oldest timestamp is automatically deleted.
为了适应多个存储设备的存储空间不同的情况,可以计算出磁盘剩余总空间,根据预先设置的总占比计算出可占用的总容量S,对于业务模块M1,根据配置占用的百分比(percent)计算出业务模块M1占用的总空间S1=S*percent,生成的文件个数为:S1/size。其中,S1为业务模块M1可占用的磁盘总空间,size为单个文件大小,*为乘法运算符,/为除法运算符。当业务模块M1的文件个数被写满且需要生成新文件时,时间戳最早的文件被自动删除。 In order to adapt to the storage space of multiple storage devices, the total remaining space of the disk can be calculated, and the total capacity S that can be occupied is calculated according to the total proportion of the preset. For the service module M1, the percentage occupied by the configuration (percent) The total space occupied by the service module M1 is calculated as S1=S*percent, and the number of generated files is: S1/size. S1 is the total disk space occupied by the service module M1, the size is a single file size, * is a multiplication operator, and / is a division operator. When the number of files of the service module M1 is full and a new file needs to be generated, the file with the oldest timestamp is automatically deleted.
假设系统的配置文件计算出来的每个业务模块可以生成的文件个数为N(N=S/M/size或者N=S1/size),日志文件(存储日志的文件,相当于磁盘空间或存储空间)序号取值范围可以为[0,N-1]。Assume that the number of files that can be generated by each service module calculated by the system configuration file is N (N=S/M/size or N=S1/size), and the log file (the file that stores the log is equivalent to disk space or storage). The space number can be in the range of [0, N-1].
本实施例中,一业务模块的日志文件不覆盖其它业务模块的日志文件的方法可以包括以下步骤。In this embodiment, the method that the log file of a service module does not cover the log files of other service modules may include the following steps.
在步骤一中,启动系统,确定每个业务模块的日志文件的序号,日志目录下没有任何日志文件时,得到的所有业务模块的日志文件的序号CIndex(1)=0,CIndex(2)=0,…CIndex(N-1)=0;若是重启系统,则根据文件名中含有的时间戳来获取到最后记录的文件,获取到最后记录的文件的序号,查找到CIndex(1),CIndex(2),…CIndex(N-1),系统开始运行并往序号为CIndex(1),CIndex(2),…CIndex(N-1)的日志文件中记录日志。In step 1, start the system, determine the serial number of the log file of each service module, and if there is no log file in the log directory, the serial number of the log file of all service modules obtained is CIndex(1)=0, CIndex(2)= 0,...CIndex(N-1)=0; If the system is restarted, the last recorded file is obtained according to the timestamp contained in the file name, and the serial number of the last recorded file is obtained, and CIndex(1), CIndex is found. (2), ... CIndex(N-1), the system starts running and logs to the log file with the sequence number CIndex(1), CIndex(2),...CIndex(N-1).
在步骤二中,经过一段时间,比如业务模块p日志记录时检测到当前记录的文件CIndex(p)大小已经超过配置文件定义的大小(size),可以结束当前日志文件的记录,切换文件。可以根据公式CIndex’(p)=(CIndex(p)+1)%(N)计算出需要切换到的日志文件的序号(索引号)为CIndex’(p),其中,%是取余运算符,p为整数,且p的取值为[0,N-1],判断是否存在序号为CIndex’(p)的日志文件,如果存在序号为CIndex’(p)的日志文件,则可以删除序号为CIndex’(p)的日志文件,将序号为CIndex(p)的日志文件中超过配置文件定义的大小(size)的部分存储到序号为CIndex’(p)的日志文件所在的存储空间中,即日志文件序号为CIndex’(p)的日志文件被循环覆盖。In step 2, after a period of time, for example, when the service module p logs, it is detected that the size of the currently recorded file CIndex(p) has exceeded the size defined by the configuration file, and the current log file may be ended and the file may be switched. According to the formula CIndex'(p)=(CIndex(p)+1)%(N), the sequence number (index number) of the log file to be switched to is CIndex'(p), where % is the remainder operator. , p is an integer, and the value of p is [0, N-1]. It is determined whether there is a log file with the sequence number CIndex'(p). If there is a log file with the sequence number CIndex'(p), the sequence number can be deleted. For the log file of CIndex'(p), store the part of the log file with the serial number CIndex(p) that exceeds the size defined by the configuration file in the storage space where the log file with the serial number CIndex'(p) is located. That is, the log file whose log file number is CIndex'(p) is overwritten by the loop.
可选的,业务模块q日志记录时发现当前记录的文件CIndex(q)大小已经超过配置文件定义的大小(size),可以结束当前日志文件的记录,切换文件。根据公式CIndex’(q)=(CIndex(q)+1)%(N)计算出需要切换到的日志文件的序号为CIndex’(q),判断是否存在序号为CIndex’(q)的日志文件,如果存在序号为CIndex’(q)的日志文件,则可以删除序号为CIndex’(q)的日志文件,将序号为CIndex(q)的日志文件中超过配置文件定义的大小(size)的部分存储到序号为CIndex’(q)的日志文件所在的存储空间中,即日志文件序号为CIndex’(q)的日志文件被循环覆盖,其中,q为整数,q的取值为[0,N-1],且q不等于p。Optionally, when the service module q logs, it is found that the size of the currently recorded file CIndex(q) has exceeded the size defined by the configuration file, and the current log file record can be ended, and the file is switched. Calculate the sequence number of the log file to be switched to CIndex'(q) according to the formula CIndex'(q)=(CIndex(q)+1)%(N), and determine whether there is a log file with the sequence number CIndex'(q). If there is a log file with the sequence number CIndex'(q), you can delete the log file with the sequence number CIndex'(q), and the part of the log file with the sequence number CIndex(q) that exceeds the size defined by the configuration file. Stored in the storage space where the log file with the sequence number CIndex'(q) is located, that is, the log file whose log file number is CIndex'(q) is covered by the loop. Where q is an integer, and the value of q is [0, N). -1], and q is not equal to p.
业务模块p和业务模块q记录的文件虽然在同一个目录(同一类日志记录在 同一个目录)下,但是互不影响。The files recorded by the business module p and the business module q are in the same directory (the same type of log is recorded in Under the same directory), but do not affect each other.
在步骤三中,不断重复步骤二,直到系统启动第m天,重启系统,m可以为正整数。In step three, repeat step two until the system starts the mth day and restart the system. m can be a positive integer.
在步骤四中,不断重复步骤一至步骤三,业务模块记录日志和循环覆盖,互不影响。In step four, step one to step three are repeated, and the service module records the log and the loop coverage without affecting each other.
实施例4Example 4
本实施例提供了一种存储介质。可选地,在本实施例中,上述存储介质可以被设置为存储用于执行以下步骤的程序代码:This embodiment provides a storage medium. Optionally, in the embodiment, the foregoing storage medium may be configured to store program code for performing the following steps:
接收日志文件;Receive log files;
确定日志文件的业务类型;以及Determine the business type of the log file;
根据业务类型将日志文件记录到对应的第一磁盘空间。The log file is recorded to the corresponding first disk space according to the type of the service.
可选地,在本实施例中,上述存储介质可以包括U盘、只读存储器(ROM,Read-Only Memory)、随机存取存储器(RAM,Random Access Memory)、移动硬盘、磁碟或者光盘等多种可以存储程序代码的非暂态存储介质,还可以是暂态存储介质。Optionally, in this embodiment, the foregoing storage medium may include a USB flash drive, a Read-Only Memory (ROM), a Random Access Memory (RAM), a mobile hard disk, a magnetic disk, or an optical disk. A variety of non-transitory storage media that can store program code, and can also be transitory storage media.
可选地,处理器根据存储介质中已存储的程序代码执行接收日志文件。Optionally, the processor executes the receiving log file according to the stored program code in the storage medium.
可选地,处理器根据存储介质中已存储的程序代码执行确定日志文件的业务类型。Optionally, the processor performs a service type determining the log file according to the stored program code in the storage medium.
可选地,处理器根据存储介质中已存储的程序代码执行根据业务类型将日志文件记录到对应的第一磁盘空间。Optionally, the processor records, according to the stored program code in the storage medium, the log file to the corresponding first disk space according to the service type.
处理器还可以根据存储介质中已存储的程序代码执行上述实施例中的方法。The processor may also perform the method in the above embodiments in accordance with stored program code in the storage medium.
本实施例中的示例可以参考上述实施例及可选实施方式中所描述的示例。For examples in this embodiment, reference may be made to the examples described in the above embodiments and alternative embodiments.
上述的多个模块或多个步骤可以用通用的计算装置来实现,它们可以集中在单个的计算装置上,或者分布在多个计算装置所组成的网络上,可选地,它们可以用计算装置可执行的程序代码来实现,可以将它们存储在存储装置中由计算装置来执行,并且在一些情况下,可以以不同于此处的顺序执行所示出或 描述的步骤,或者将它们分别制作成多个集成电路模块,或者将它们中的多个模块或步骤制作成单个集成电路模块来实现。The plurality of modules or steps described above 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, optionally using computing devices Executable program code is implemented, which may be stored in a storage device for execution by a computing device, and in some cases, may be performed in a different order than that illustrated herein or The steps described are either made separately into a plurality of integrated circuit modules, or a plurality of modules or steps are fabricated as a single integrated circuit module.
本实施例提供了一种电子设备的硬件结构示意图。参见图7,该电子设备包括:This embodiment provides a hardware structure diagram of an electronic device. Referring to FIG. 7, the electronic device includes:
至少一个处理器(processor)70,图7中以一个处理器70为例;存储器(memory)71;还可以包括通信接口(Communications Interface)72和总线73。其中,处理器70、存储器71和通信接口72可以通过总线73完成相互间的通信。通信接口72可以传输信号和数据。处理器70可以调用存储器71中的逻辑指令,以执行上述实施例中的方法。At least one processor 70 is exemplified by a processor 70 in FIG. 7; a memory 71; and a communication interface 72 and a bus 73. Among them, the processor 70, the memory 71, and the communication interface 72 can complete communication with each other through the bus 73. Communication interface 72 can carry signals and data. The processor 70 can call the logic instructions in the memory 71 to perform the methods in the above embodiments.
此外,上述的存储器71中的逻辑指令可以通过软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。In addition, the logic instructions in the memory 71 described above may be implemented in the form of a software functional unit and sold or used as a stand-alone product, and may be stored in a computer readable storage medium.
存储器71作为一种计算机可读存储介质,可用于存储软件程序、计算机可执行程序,如上述实施例中的方法对应的程序指令或模块。处理器70通过运行存储在存储器71中的软件程序、指令或模块,从而执行功能应用以及数据处理,即实现上述实施例中的方法。The memory 71 is a computer readable storage medium and can be used to store software programs, computer executable programs, such as program instructions or modules corresponding to the methods in the above embodiments. The processor 70 executes the functional application and the data processing by executing a software program, an instruction or a module stored in the memory 71, that is, implementing the method in the above embodiment.
存储器71可包括存储程序区和存储数据区,其中,存储程序区可存储操作系统、至少一个功能所需的应用程序;存储数据区可存储根据终端设备的使用所创建的数据等。此外,存储器71可以包括高速随机存取存储器,还可以包括非易失性存储器。The memory 71 may include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application required for at least one function; the storage data area may store data created according to usage of the terminal device, and the like. Further, the memory 71 may include a high speed random access memory, and may also include a nonvolatile memory.
工业实用性Industrial applicability
日志文件的存储方法及装置,避免相关技术中一种或多种业务类型的日志文件覆盖其他业务类型的日志文件的现象。 The storage method and device of the log file are used to avoid the phenomenon that the log files of one or more service types of the related technology cover the log files of other service types.

Claims (11)

  1. 一种日志文件的存储方法,包括:A method for storing log files, including:
    接收日志文件;Receive log files;
    确定所述日志文件的业务类型;以及Determining the type of business of the log file;
    根据所述业务类型将所述日志文件记录到对应的第一磁盘空间。Recording the log file to the corresponding first disk space according to the service type.
  2. 根据权利要求1所述的方法,在根据所述业务类型将所述日志文件记录到对应的第一磁盘空间之前,所述方法还包括:The method according to claim 1, before the recording of the log file to the corresponding first disk space according to the service type, the method further includes:
    确定存储设备上用于存储日志文件的总磁盘空间;以及Determine the total disk space on the storage device used to store log files;
    根据多个业务类型将所述总磁盘空间划分为多个子磁盘空间,其中,每个所述子磁盘空间存放一种业务类型的日志文件。The total disk space is divided into a plurality of sub-disk spaces according to a plurality of service types, wherein each of the sub-disk spaces stores a log file of a service type.
  3. 根据权利要求2所述的方法,其中,确定存储设备上用于存储日志文件的总磁盘空间包括以下之一:The method of claim 2 wherein determining the total disk space on the storage device for storing log files comprises one of the following:
    确定存储设备上预设的用于存储日志文件的所述总磁盘空间;以及Determining the total disk space preset on the storage device for storing log files;
    确定所述存储设备的剩余容量,以及所述总磁盘空间占所述剩余容量的预设百分比,并根据所述剩余容量和所述预设百分比确定所述总磁盘空间。Determining a remaining capacity of the storage device, and the total disk space occupies a preset percentage of the remaining capacity, and determining the total disk space according to the remaining capacity and the preset percentage.
  4. 根据权利要求1所述的方法,其中,确定所述日志文件的业务类型包括:The method of claim 1, wherein determining the service type of the log file comprises:
    根据所述日志文件的文件前缀确定生成所述日志文件的业务模块;以及Determining, according to a file prefix of the log file, a service module that generates the log file;
    根据所述业务模块确定所述业务类型。Determining the service type according to the service module.
  5. 根据权利要求1所述的方法,其中,根据所述业务类型将所述日志文件记录到对应的第一磁盘空间包括:The method of claim 1, wherein the recording the log file to the corresponding first disk space according to the service type comprises:
    判断所述第一磁盘空间的已存储容量是否超过预设阈值;Determining whether the stored capacity of the first disk space exceeds a preset threshold;
    在所述已存储容量超过所述预设阈值时,根据所述第一磁盘空间内多个日志文件的时间戳得到存储时间最早的指定日志文件,并删除所述指定日志文件; 以及When the stored capacity exceeds the preset threshold, the specified log file with the earliest storage time is obtained according to the timestamp of multiple log files in the first disk space, and the specified log file is deleted; as well as
    在所述第一磁盘空间内记录所述日志文件。Recording the log file in the first disk space.
  6. 根据权利要求1所述的方法,其中,根据所述业务类型将所述日志文件记录到对应的第一磁盘空间包括:The method of claim 1, wherein the recording the log file to the corresponding first disk space according to the service type comprises:
    判断所述第一磁盘空间的已存储容量是否超过第二预设阈值;Determining whether the stored capacity of the first disk space exceeds a second preset threshold;
    在所述第一磁盘空间的已存储容量超过第二预设阈值时,根据预设规则计算得到第二磁盘空间的索引号;以及When the stored capacity of the first disk space exceeds a second preset threshold, calculating an index number of the second disk space according to a preset rule;
    将所述日志文件记录到所述第二磁盘空间。Recording the log file to the second disk space.
  7. 根据权利要求6所述的方法,其中,将所述日志文件记录到所述第二磁盘空间包括:The method of claim 6 wherein recording the log file to the second disk space comprises:
    在已经存在所述第二磁盘空间的情况下,删除所述第二磁盘空间原存储的数据后,将所述日志文件记录到所述第二磁盘空间;After the second disk space already exists, after the data originally stored in the second disk space is deleted, the log file is recorded to the second disk space;
    在不存在所述第二磁盘空间的情况下,创建所述第二磁盘空间后,将所述日志文件记录到所述第二磁盘空间。In the case where the second disk space does not exist, after the second disk space is created, the log file is recorded to the second disk space.
  8. 一种日志文件的存储装置,包括:A storage device for a log file, comprising:
    接收模块,设置为接收日志文件;a receiving module, configured to receive a log file;
    第一确定模块,设置为确定所述日志文件的业务类型;以及a first determining module, configured to determine a service type of the log file;
    记录模块,设置为根据所述业务类型将所述日志文件记录到对应的第一磁盘空间。The recording module is configured to record the log file to the corresponding first disk space according to the service type.
  9. 根据权利要求8所述的装置,还包括:The apparatus of claim 8 further comprising:
    第二确定模块,设置为在所述记录模块根据所述业务类型将所述日志文件记录到对应的第一磁盘空间之前,确定存储设备上用于存储日志文件的总磁盘 空间;以及a second determining module, configured to determine a total disk for storing the log file on the storage device before the recording module records the log file to the corresponding first disk space according to the service type Space;
    划分模块,设置为根据多个业务类型将所述总磁盘空间划分为多个子磁盘空间,其中,每个所述子磁盘空间存储一种业务类型的日志文件。The partitioning module is configured to divide the total disk space into a plurality of sub-disk spaces according to a plurality of service types, wherein each of the sub-disk spaces stores a log file of a service type.
  10. 根据权利要求8所述的装置,其中,所述记录模块包括:The apparatus of claim 8 wherein said recording module comprises:
    判断单元,设置为判断所述第一磁盘空间的已存储容量是否超过第一预设阈值;a determining unit, configured to determine whether the stored capacity of the first disk space exceeds a first preset threshold;
    处理单元,设置为在所述已存储容量超过所述预设阈值时,根据所述第一磁盘空间内多个日志文件的时间戳得到存储时间最早的指定日志文件,并删除所述指定日志文件;以及a processing unit, configured to: when the stored capacity exceeds the preset threshold, obtain a specified log file with the earliest storage time according to a timestamp of multiple log files in the first disk space, and delete the specified log file ;as well as
    记录单元,设置为在所述第一磁盘空间内记录所述日志文件。a recording unit configured to record the log file in the first disk space.
  11. 一种计算机可读存储介质,存储有计算机可执行指令,所述计算机可执行指令设置为执行权利要求1-7中任一项的方法。 A computer readable storage medium storing computer executable instructions arranged to perform the method of any of claims 1-7.
PCT/CN2017/090172 2016-07-08 2017-06-27 Method and apparatus for storing log file WO2018006721A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201610539599.5 2016-07-08
CN201610539599.5A CN107590162A (en) 2016-07-08 2016-07-08 The storage method and device of journal file

Publications (1)

Publication Number Publication Date
WO2018006721A1 true WO2018006721A1 (en) 2018-01-11

Family

ID=60921578

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2017/090172 WO2018006721A1 (en) 2016-07-08 2017-06-27 Method and apparatus for storing log file

Country Status (2)

Country Link
CN (1) CN107590162A (en)
WO (1) WO2018006721A1 (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111309696A (en) * 2020-03-20 2020-06-19 中电长城网际系统应用有限公司 Log processing method and device, electronic equipment and readable medium

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108595367B (en) * 2018-04-25 2021-12-10 广州高专资讯科技有限公司 Server system based on computer cluster in local area network
CN110716908A (en) * 2019-09-29 2020-01-21 捷开通讯(深圳)有限公司 Log information writing method, system, storage medium and mobile terminal
CN112860636A (en) * 2021-01-18 2021-05-28 北京金山云网络技术有限公司 Storage method and device of operation data, electronic equipment and storage medium
CN113177033B (en) * 2021-03-31 2022-12-16 新华三信息安全技术有限公司 Log data storage method and device, electronic equipment and medium

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20080155545A1 (en) * 2006-12-20 2008-06-26 Laurent Sebastien Mignet Method and system for scheduling workload in databases
CN102541908A (en) * 2010-12-27 2012-07-04 沈阳中科博微自动化技术有限公司 Log database system sub-volume management method
CN102637142A (en) * 2012-04-13 2012-08-15 浪潮(北京)电子信息产业有限公司 Computer system and method for realizing log management
CN104572413A (en) * 2013-10-29 2015-04-29 上海斐讯数据通信技术有限公司 Method for storing system logs by electronic equipment and electronic equipment
CN105868340A (en) * 2016-03-28 2016-08-17 乐视控股(北京)有限公司 Log storage method and device

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7062516B2 (en) * 2001-09-18 2006-06-13 Sun Microsystems, Inc. Methods, systems, and articles of manufacture for implementing a runtime logging service storage infrastructure
JP2003099295A (en) * 2001-09-21 2003-04-04 Teamgia:Kk Processing method for communication log, computer software program for implementing the same method on computer system and communication log processing system
JP2004185189A (en) * 2002-12-02 2004-07-02 Sankyo Seiki Mfg Co Ltd Log record data management method
KR101469771B1 (en) * 2008-12-03 2014-12-08 삼성전자주식회사 Semiconductor device comprising flash memory and address mapping method thereof
CN104301360B (en) * 2013-07-19 2019-03-12 阿里巴巴集团控股有限公司 A kind of method of logdata record, log server and system

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20080155545A1 (en) * 2006-12-20 2008-06-26 Laurent Sebastien Mignet Method and system for scheduling workload in databases
CN102541908A (en) * 2010-12-27 2012-07-04 沈阳中科博微自动化技术有限公司 Log database system sub-volume management method
CN102637142A (en) * 2012-04-13 2012-08-15 浪潮(北京)电子信息产业有限公司 Computer system and method for realizing log management
CN104572413A (en) * 2013-10-29 2015-04-29 上海斐讯数据通信技术有限公司 Method for storing system logs by electronic equipment and electronic equipment
CN105868340A (en) * 2016-03-28 2016-08-17 乐视控股(北京)有限公司 Log storage method and device

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111309696A (en) * 2020-03-20 2020-06-19 中电长城网际系统应用有限公司 Log processing method and device, electronic equipment and readable medium

Also Published As

Publication number Publication date
CN107590162A (en) 2018-01-16

Similar Documents

Publication Publication Date Title
WO2018006721A1 (en) Method and apparatus for storing log file
US20210133146A1 (en) Method for processing snapshots and distributed block storage system
CN105095300A (en) Method and system for database backup
WO2018214905A1 (en) Data storage method, apparatus, medium and device
CN107402870B (en) Method and device for processing log segment in metadata server
CN112182010B (en) Dirty page refreshing method and device, storage medium and electronic equipment
CN110879687B (en) Data reading method, device and equipment based on disk storage
US9104567B2 (en) Memory-leak identification
CN108446110B (en) Lua script generation method, Lua script generation device, Lua script generation terminal and computer readable medium
CN110019063B (en) Method for computing node data disaster recovery playback, terminal device and storage medium
CN109189343B (en) Metadata disk-dropping method, device, equipment and computer-readable storage medium
CN110955639A (en) Data processing method and device
CN112860412B (en) Service data processing method and device, electronic equipment and storage medium
CN111221790A (en) Log file processing method and device and computer readable storage medium
CN107315806B (en) Embedded storage method and device based on file system
CN115373609A (en) Task processing method and related equipment
CN115756955A (en) Data backup and data recovery method and device and computer equipment
CN113821193B (en) Information generation method, device and storage medium
CN112328363B (en) Cloud hard disk mounting method and device
CN112632266B (en) Data writing method and device, computer equipment and readable storage medium
CN107844491B (en) Method and equipment for realizing strong consistency read operation in distributed system
CN108415814B (en) Method for automatically recording field change, application server and computer readable storage medium
CN111858487A (en) Data updating method and device
CN110688258A (en) Snapshot creating method and device
CN110837345A (en) Bad block table storage method and device

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: 17823533

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: 17823533

Country of ref document: EP

Kind code of ref document: A1