The content of the invention
The present invention provides a kind of method and device of log information storage, is inconvenient to look into solve to exist in the prior art
Log information is ask, the efficiency of diagnosis investigation problem is reduced, and then reduce the performance issue of system.
On the one hand, the embodiment of the present invention provides a kind of method of log information storage, including:
The parameter of journal file is obtained, parameter includes the cursor position of journal file, and cursor position is used to indicate that daily record is believed
The storage location of breath;
It is from cursor position to judge whether the size L of log information to be stored is more than the first storage value X, the first storage value X
Put to the memory space for not storing log information of log file trailer;
If so, the then afterbody by the preceding X data of log information to be stored since being stored cursor position to journal file,
And store the rear L-X data of log information to be stored to L-X sizes since the stem of journal file;
It is since the stem of journal file at L-X sizes to update cursor position.
Alternatively, in addition to:
If the size L of log information to be stored is not more than the first storage value X, storage is to be stored since the cursor position
Log information;
It is since cursor position at L sizes to update cursor position.
Alternatively, parameter also includes the daily record rank of journal file;
Judge whether the size L of log information to be stored is more than before the first storage value X, in addition to:
Judge whether log information to be stored meets the other requirement of journal stage;
If meeting, judge whether the size L of log information to be stored is more than the first storage value X.
Alternatively, before the parameter for obtaining journal file, in addition to:
Judge whether it is to first switch on journal file;
If so, then setting the parameter of journal file, and parameter is preserved into journal file;
If it is not, then reading the parameter of journal file from journal file.
Alternatively, before the parameter for obtaining journal file, in addition to:
It is journal file to judge whether the current stored value N of journal file is more than the second storage value M, the second storage value M
Maximum storage value;
If so, then deleting in journal file the earliest log information of storage time until the current stored value N of journal file
Less than or equal to the second storage value M and Update log file cursor position.
Second aspect, the embodiment of the present invention also provides a kind of device of log information storage, including:
Acquiring unit is used for:The parameter of journal file is obtained, parameter includes the cursor position of journal file, and cursor position is used
In the storage location for indicating log information;
Judging unit is used for:Judge whether the size L of log information to be stored is more than the first storage value X, the first storage
Value X is the memory space for not storing log information from cursor position to log file trailer;
If so, the then afterbody by the preceding X data of log information to be stored since being stored cursor position to journal file,
And store the rear L-X data of log information to be stored to L-X sizes since the stem of journal file;
Updating block is used for:It is since the stem of journal file at L-X sizes to update cursor position.
Alternatively, judging unit is additionally operable to:
If the size L of log information to be stored is not more than the first storage value X, storage is to be stored since the cursor position
Log information;
Updating block is additionally operable to:
It is since cursor position at L sizes to update cursor position.
Alternatively, parameter also includes the daily record rank of journal file;
Judging unit specifically for:Judge whether log information to be stored meets the other requirement of journal stage;
If meeting, judge whether the size L of log information to be stored is more than the first storage value X.
Alternatively, judging unit is specifically additionally operable to:
Judge whether it is to first switch on journal file;
If so, then setting the parameter of journal file, and parameter is preserved into journal file;
If it is not, then reading the parameter of journal file from journal file.
Alternatively, judging unit is specifically additionally operable to:
It is journal file to judge whether the current stored value N of journal file is more than the second storage value M, the second storage value M
Maximum storage value;
If so, then deleting in journal file the earliest log information of storage time until the current stored value N of journal file
Less than or equal to the second storage value M and Update log file cursor position.
The embodiments of the invention provide a kind of method and device of log information storage, the parameter of journal file, ginseng are obtained
Number includes the cursor position of journal file, and cursor position is used for the storage location for indicating log information;Judge daily record to be stored
It is not storing from cursor position to log file trailer that whether the size L of information, which is more than the first storage value X, the first storage value X,
The memory space of log information;If so, then by the preceding X data of log information to be stored since being stored cursor position to daily record
The afterbody of file, and by the rear L-X data of log information to be stored since being stored the stem of journal file to L-X sizes
Place;It is since the stem of journal file at L-X sizes to update cursor position.The embodiment of the present invention obtains the ginseng of journal file
After number, if the size L of log information to be stored is more than the first storage value X, by the preceding X numbers of log information to be stored
According to the afterbody since being stored cursor position to journal file, and the rear L-X data of log information to be stored are literary from daily record
The stem of part starts to store to L-X sizes, so as to realize that automatic cycle stores log information in same journal file, has
Effect control disk storage space, improves the performance of system, due to being to store log information in same journal file, if after
It is continuous to need to be also convenient for inquiry when inquiry log information, be not in as being stored in the prior art in multiple journal files
Each journal file, is also stitched together and inquires about and occur being inconvenient to inquire about day by log information when inquiry log information
The problem of will information, in addition, when also updating cursor position after same journal file has stored log information, can conveniently under
The position that log information to be stored is stored in journal file is found according to the position of cursor during secondary storage log information.
Embodiment
In order that the object, technical solutions and advantages of the present invention are clearer, below in conjunction with accompanying drawing the present invention is made into
One step it is described in detail, it is clear that described embodiment is only a part of embodiment of the invention, rather than whole implementation
Example.Based on the embodiment in the present invention, what those of ordinary skill in the art were obtained under the premise of creative work is not made
All other embodiment, belongs to the scope of protection of the invention.
It should be understood that present invention may apply to the journal file in the software systems of various equipment, such as the daily record of base station
Journal file of file, various terminals such as mobile phone etc..
The embodiment of the present invention is described in further detail with reference to Figure of description.
Fig. 1 illustrates a kind of method schematic diagram of log information storage provided in an embodiment of the present invention, such as Fig. 1 institutes
Show, this method comprises the following steps:
S101:The parameter of journal file is obtained, parameter includes the cursor position of journal file, and cursor position is used to indicate day
The storage location of will information;
S102:It is from light to judge whether the size L of log information to be stored is more than the first storage value X, the first storage value X
Cursor position to log file trailer the memory space for not storing log information;
S103:If so, then by the preceding X data of log information to be stored since being stored cursor position to journal file
Afterbody, and the rear L-X data of log information to be stored are stored to L-X sizes since the stem of journal file;
S104:It is since the stem of journal file at L-X sizes to update cursor position.
Before above-mentioned S101, that is, before the parameter of journal file is obtained, in addition to the initial of journal file
The process of change, be in particular:Alternatively, before the parameter for obtaining journal file, in addition to:Judge whether it is to first switch on day
Will file;If so, then setting the parameter of journal file, and parameter is preserved into journal file;If it is not, then from journal file
Read the parameter of journal file.
Alternatively, before the parameter for obtaining journal file, in addition to:Judge whether the current stored value N of journal file is big
In maximum storage values of second the storage value M, the second storage value M for journal file;If so, then deleting storage time in journal file
Earliest log information is less than or equal to the light of the second storage value M and Update log file until the current stored value N of journal file
Cursor position.
Specifically, the process initialized to journal file is as shown in Fig. 2 Fig. 2 schematically illustrates a kind of daily record text
The schematic flow sheet of part initialization procedure, in specific implementation, in being software systems to the process that journal file is initialized
Log management module is carried out, and the schematic flow sheet comprises the following steps:
S201:Start;
S202:Judge whether it is to first switch on journal file, if so, then performing S203, otherwise, then perform S204;
S203:The parameter of journal file is set, and parameter is preserved into journal file;S204:Read from journal file
Take the parameter of journal file;
S205:Judge whether the current stored value N of journal file is more than the second storage value M, if so, S206 is then performed, it is no
Then, then S208 is performed;
S206:The earliest log information of storage time is deleted in journal file until the current stored value N of journal file is small
In equal to the second storage value M;
S207:The cursor position of Update log file;
S208:Terminate.
In above-mentioned S202, in specific implementation, judge whether it is that the standard for first switching on journal file can be:When
When opening the journal file, if not having the parameter information of log file in journal file, then, the journal file is
It is opened for the first time;When opening journal file, if the parameter information of journal file has been have recorded in journal file, but day
Parameter information in will file is not parameter set in advance, at this moment, and the parameter information of the journal file, which is likely to be, to be hacked
Visitor attacked, and was provided with the parameter of journal file by hacker, at this moment also it is also possible to the journal file is by hacker
It has recorded junk information.
If not having the parameter information of log file in the journal file, it is first time quilt to illustrate the journal file
Open, then, it is necessary to which to the journal file arrange parameter, the parameter set in specific implementation can include in S203:Daily record
The cursor position of file, daily record rank, the second storage value M of journal file, and by the daily record rank and journal file in parameter
The second storage value M be saved in the journal file;If system opens journal file, but the journal file is protected by hacker
Parameter has been deposited, and parameter information is not parameter set in advance, is at this moment considered to first switch on, this is accomplished by hacker
The journal file parameter of setting is deleted, and log management module protects the parameter of setting again to the journal file arrange parameter
It is stored in journal file.
Wherein, in specific implementation, the second storage value M of daily record rank and journal file in the parameter of setting can be protected
It is that the preceding several character positions most started that parameter storage is specially reserved can also be that journal file is parameter to be stored to journal file
The parameter of several character positions at ending that storage is specially reserved, specific save location and preservation needs to take daily record text
How many characters of part can be set depending on specific implementation situation.The other log information of journal stage is only met to be possible to be deposited
Store up in journal file.In addition, set parameter recorded in journal file, without again into database individually
The parameter of journal file is stored, the step of can so saving the resource of network, reduce operation can also be because of conveniently seeing day
The parameter of will file and the memory space for efficiently controlling journal file immediately, and then improve the reliability of system.
If not journal file is first switched on, because being already provided with this when journal file is first switched on
The parameter of journal file, so in S204, it is only necessary to which the parameter that journal file is directly read from journal file just can be with.
In S205, it is day to judge whether the current stored value N of journal file is more than the second storage value M, the second storage value M
The maximum storage value of will file, in specific implementation, if the newly-built journal file of system, then, at this moment daily record text
Part is probably an empty journal file, that is, does not store the journal file of any log information, although being also possible to just
Individual journal file has been built, but junk information is stored by hacker, so, no matter journal file is empty still to have rubbish
Whether information, will be more than the second storage value M judgement to the current stored value N of journal file, wherein the second storage value M is pair
The maximum storage value that journal file is set.
In S206, if so, then deleting the earliest log information of storage time working as until journal file in journal file
Preceding storage value N is less than or equal to the second storage value M, specifically, if whether the current stored value N of journal file deposits more than second
Stored Value M, such as, the second storage value M are 20G, and hacker stores 25G junk information in journal file, then, it is necessary to delete
Except the earliest log information of storage time in journal file until journal file current stored value 25G be less than or equal to 20G, this
Outside, in specific implementation, as such case, directly junk information all can also be deleted, and not necessarily only by storage time
Earliest junk information is deleted.
In S207, the cursor position of Update log file, specifically, if junk information all deleted, then,
The cursor position of journal file is the stem of journal file, certainly, if the stem position of journal file stores journal file
Parameter information, cursor position is exactly the latter one character position of parameter information, if storage parameter information not in stem,
The cursor position so updated is exactly the stem of journal file;If junk information is deleted to making the memory space of journal file
Equal to 20G, then cursor position is the afterbody of journal file;If junk information is deleted to making the memory space of journal file
Less than 20G, then cursor position is at last junk information.
It should be noted is that, in specific implementation, although judged that the current stored value N of journal file is less than second
Storage value M, still, at this moment has the assault journal file again, some junk information is have recorded in journal file, this is just
Need to delete some or all of junk information, the cursor position of Update log file, then, based on this point, flow signal
In Fig. 2, if the current stored value N of journal file is no more than the second storage value M, the cursor position of Update log file,
As shown in Figure 3.Fig. 3 schematically illustrates the schematic flow sheet of another journal file initialization procedure.
In S102, S103 and S104, judge whether the size L of log information to be stored is more than the first storage value X, the
One storage value X is the memory space for not storing log information from cursor position to log file trailer;If so, then will be to be stored
Log information afterbody of the preceding X data since being stored cursor position to journal file, and by log information to be stored
L-X data are stored to L-X sizes since the stem of journal file afterwards, and it is to be opened from the stem of journal file to update cursor position
Begin to L-X sizes, specifically, such as, the size L of log information to be stored is 9G, from cursor position to journal file
The memory space for not storing log information of afterbody is 8G, then opens the preceding 8G data of log information to be stored from cursor position
Beginning store to the afterbody of journal file, by the rear 1G data of log information to be stored since stored the stem of journal file to
At 1G sizes, and by the data since before being stored the stem of journal file to 1G sizes by log information to be stored
1G data covers fall afterwards, thus complete the storage of this log information, and cursor position is updated into the head from journal file
Portion starts to 1G sizes.S103 and S104 ensure that the log information of storage is the Jin Erke in same journal file
Inquiry log information is needed in the future to facilitate, without being also needed to as prior art by the log information splicing of multiple journal files
Get up to check, and log information is that automatic cycle storage does not need manual maintenance, can effectively control the storage of disk empty
Between.
Alternatively, in addition to:If the size L of log information to be stored is not more than the first storage value X, from cursor position
Start to store log information to be stored;It is since cursor position at L sizes to update cursor position.Specifically, such as,
If the size L of log information to be stored is 7G, the first storage value X is 9G, then storage is to be stored since the cursor position
Log information until by log information to be stored stored and update cursor position be since cursor position to 7G sizes
Place.
Before S102, alternatively, parameter also includes the daily record rank of journal file;Judge log information to be stored
Whether size L is more than before the first storage value X, in addition to:Judge log information to be stored whether meet journal stage it is other will
Ask;If meeting, judge whether the size L of log information to be stored is more than the first storage value X.Specifically, such as daily record
The daily record rank of file have typically, it is warning, serious, when setting the daily record rank of journal file for warning, judge to be stored
Whether log information meets requirement of the daily record rank for warning, if log information to be stored is alert level, then performs
S102.First, set the need for the logging level of journal file is according to equipment, secondly, according to the logging level of setting
To judge whether log information to be stored also meets the other requirement of journal stage, if met, be subsequently possible to wait to deposit
The log information of storage is stored into journal file, is so on the one hand avoided unnecessary log information and is also stored on daily record text
In part, and then the log information of journal file is more simplified, on the other hand can also improve the efficiency diagnosed to system problem, enter
And improve the performance of system.
In order to more fully understand this programme, a kind of the overall of log information storage provided in an embodiment of the present invention is thought below
Road is described in detail, and a kind of general thought of log information storage provided in an embodiment of the present invention includes two large divisions, first
It is divided into the initialization procedure to journal file, Part II is the method for the log information storage to journal file, wherein first
Part is having been described above, namely such as Fig. 2 and 3, then, the overall think of of the log information storage of journal file is described below
Road, Fig. 4 schematically illustrates a kind of holistic approach flow chart of log information storage, as shown in figure 4, comprising the following steps:
S301:Start;
S302:The parameter of journal file is obtained, parameter includes the cursor position, daily record rank, the first storage of journal file
Value X;
S303:Judge whether log information to be stored meets the other requirement of journal stage, if so, S304 is then performed, otherwise,
Then perform S309;
S304:Judge whether the size L of log information to be stored is more than the first storage value X, if so, S305 is then performed,
Otherwise, then S306 is performed;
S305:Afterbody by the preceding X data of log information to be stored since being stored cursor position to journal file, and
The rear L-X data of log information to be stored are stored to L-X sizes since the stem of journal file;
S306:Log information to be stored is stored since the cursor position;
S307:It is since the stem of journal file at L-X sizes to update cursor position;
S308:It is since cursor position at L sizes to update cursor position;
S309:Terminate.
The embodiments of the invention provide a kind of method and device of log information storage, the parameter of journal file, ginseng are obtained
Number includes the cursor position of journal file, and cursor position is used for the storage location for indicating log information;Judge daily record to be stored
It is not storing from cursor position to log file trailer that whether the size L of information, which is more than the first storage value X, the first storage value X,
The memory space of log information;If so, then by the preceding X data of log information to be stored since being stored cursor position to daily record
The afterbody of file, and by the rear L-X data of log information to be stored since being stored the stem of journal file to L-X sizes
Place;It is since the stem of journal file at L-X sizes to update cursor position.The embodiment of the present invention obtains the ginseng of journal file
After number, if the size L of log information to be stored is more than the first storage value X, by the preceding X numbers of log information to be stored
According to the afterbody since being stored cursor position to journal file, and the rear L-X data of log information to be stored are literary from daily record
The stem of part starts to store to L-X sizes, so as to realize that automatic cycle stores log information in same journal file, has
Effect control disk storage space, improves the performance of system, due to being to store log information in same journal file, if after
It is continuous to need to be also convenient for inquiry when inquiry log information, be not in as being stored in the prior art in multiple journal files
Each journal file, is also stitched together and inquires about and occur being inconvenient to inquire about day by log information when inquiry log information
The problem of will information, in addition, when also updating cursor position after same journal file has stored log information, can conveniently under
The position that log information to be stored is stored in journal file is found according to the position of cursor during secondary storage log information.
Based on identical technical concept, the embodiment of the present invention also provides a kind of device of log information storage, and Fig. 5 is exemplary
Ground shows a kind of schematic device of log information storage, as shown in figure 5, including:Acquiring unit 401, judging unit 402,
Updating block 403.Wherein,
Acquiring unit 401 is used for:The parameter of journal file is obtained, parameter includes the cursor position of journal file, cursor position
Put the storage location for indicating log information;
Judging unit 402 is used for:Judge whether the size L of log information to be stored is more than the first storage value X, first deposits
Stored Value X is the memory space for not storing log information from cursor position to log file trailer;
If so, the then afterbody by the preceding X data of log information to be stored since being stored cursor position to journal file,
And store the rear L-X data of log information to be stored to L-X sizes since the stem of journal file;
Updating block 403 is used for:It is since the stem of journal file at L-X sizes to update cursor position.
Alternatively, judging unit 402 is additionally operable to:
If the size L of log information to be stored is not more than the first storage value X, storage is to be stored since the cursor position
Log information;
Updating block 403 is additionally operable to:
It is since cursor position at L sizes to update cursor position.
Alternatively, parameter also includes the daily record rank of journal file;
Judging unit 402 specifically for:Judge whether log information to be stored meets the other requirement of journal stage;
If meeting, judge whether the size L of log information to be stored is more than the first storage value X.
Alternatively, judging unit 402 is specifically additionally operable to:
Judge whether it is to first switch on journal file;
If so, then setting the parameter of journal file, and parameter is preserved into journal file;
If it is not, then reading the parameter of journal file from journal file.
Alternatively, judging unit 402 is specifically additionally operable to:
It is journal file to judge whether the current stored value N of journal file is more than the second storage value M, the second storage value M
Maximum storage value;
If so, then deleting in journal file the earliest log information of storage time until the current stored value N of journal file
Less than or equal to the second storage value M and Update log file cursor position.
The embodiments of the invention provide a kind of device of log information storage, the parameter of journal file is obtained, parameter includes
The cursor position of journal file, cursor position is used for the storage location for indicating log information;Judge log information to be stored
Whether size L is more than the first storage value X, the first storage value X not store daily record letter from cursor position to log file trailer
The memory space of breath;If so, then by the preceding X data of log information to be stored since being stored cursor position to journal file
Afterbody, and the rear L-X data of log information to be stored are stored to L-X sizes since the stem of journal file;Update
Cursor position is since the stem of journal file at L-X sizes.The embodiment of the present invention is obtained after the parameter of journal file,
If the size L of log information to be stored is more than the first storage value X, by the preceding X data of log information to be stored from light
Cursor position starts to store to the afterbody of journal file, and by the rear L-X data of log information to be stored from the head of journal file
Portion starts to store to L-X sizes, so as to realize that automatic cycle stores log information, effectively control in same journal file
Disk storage space, improves the performance of system, due to being to store log information in same journal file, if follow-up need
Inquiry is also convenient for when inquiry log information, is not in as storing daily record letter in multiple journal files in the prior art
Each journal file, is also stitched together and inquires about and inconvenient inquiry log information occur by breath when inquiry log information
The problem of, in addition, when also to update cursor position after same journal file has stored log information, can conveniently storage next time
The position that log information to be stored is stored in journal file is found according to the position of cursor during log information.
The present invention is the flow with reference to method according to embodiments of the present invention, equipment (system) and computer program product
Figure and/or block diagram are described.It should be understood that can be by every first-class in computer program instructions implementation process figure and/or block diagram
Journey and/or the flow in square frame and flow chart and/or block diagram and/or the combination of square frame.These computer programs can be provided
The processor of all-purpose computer, special-purpose computer, Embedded Processor or other programmable data processing devices is instructed to produce
A raw machine so that produced by the instruction of computer or the computing device of other programmable data processing devices for real
The device for the function of being specified in present one flow of flow chart or one square frame of multiple flows and/or block diagram or multiple square frames.
These computer program instructions, which may be alternatively stored in, can guide computer or other programmable data processing devices with spy
Determine in the computer-readable memory that mode works so that the instruction being stored in the computer-readable memory, which is produced, to be included referring to
Make the manufacture of device, the command device realize in one flow of flow chart or multiple flows and/or one square frame of block diagram or
The function of being specified in multiple square frames.
These computer program instructions can be also loaded into computer or other programmable data processing devices so that in meter
Series of operation steps is performed on calculation machine or other programmable devices to produce computer implemented processing, thus in computer or
The instruction performed on other programmable devices is provided for realizing in one flow of flow chart or multiple flows and/or block diagram one
The step of function of being specified in individual square frame or multiple square frames.
, but those skilled in the art once know basic creation although preferred embodiments of the present invention have been described
Property concept, then can make other change and modification to these embodiments.So, appended claims are intended to be construed to include excellent
Select embodiment and fall into having altered and changing for the scope of the invention.
Obviously, those skilled in the art can carry out the essence of various changes and modification without departing from the present invention to the present invention
God and scope.So, if these modifications and variations of the present invention belong to the scope of the claims in the present invention and its equivalent technologies
Within, then the present invention is also intended to comprising including these changes and modification.