A kind of general-purpose system blog management method
Technical field
The present invention relates to a kind of general-purpose system blog management method, write for each module of software systems provides unified, query interface, the standard journal format.
Background technology
At present, in the software systems of a complicacy, can comprise the plurality of applications module, each module all need be write the daily record of oneself.Inquiry log for ease, the day that needs each module to write aims at will unifying on the form as far as possible, and location mode is concentrated as far as possible, and history log can be preserved for a long time.
In existing systems, generally be the mode that adopts the direct written document of each module.At first,, receive the IO of system Effect on Performance, some efficient that directly written document will inevitably loss system because operation file is slow more than the operation internal memory.Secondly, owing to there are a lot of modules in the system, they will inevitably concurrently write daily record; If adopt the mode of different journal files separately of writing; Then journal file relatively disperses, and size is inhomogeneous, also can't represent the ruuning situation of all modules at a time intuitively; If adopt the mode of writing same journal file, since concurrent, the file lock need be increased again, certainly will influence the efficient of system more.
Summary of the invention
Technical matters to be solved by this invention is a kind of general-purpose system blog management method of design; Provide unified and write the supply of daily record function with each module invokes in the system; Unified log query interface is provided simultaneously; Thereby the journal format that guarantees total system is unified and standard fully, is convenient to analyze and check.
The technical scheme that the present invention solves the problems of the technologies described above is following: a kind of general-purpose system blog management method comprises the steps:
Step 1: create three onesize daily record shared drives and three onesize journal files in advance;
Step 2: when writing daily record, search the current daily record shared drive that is using;
Step 3: judge whether current daily record shared drive is write full;
Step 4: if not, the log content current daily record shared drive that writes direct finishes then; If log content writes next daily record shared drive, and change the current memory block sequence number of using into next piece; Execution in step 5;
Step 5: if all daily record shared drives have been write full daily record; Judge whether current journal file is write completely, if not, the log content of will being correlated with automatically records in the current journal file; The content of Clear Log shared drive is prepared against when switching next time and is used then; If, execution in step 6;
Step 6: write because of current journal file and full then to automatically switch to next journal file, and change the current file sequence number of using into the next one; Execution in step 7;
Step 7: if all journal files have been write full daily record, the log content of will being correlated with automatically records in the archive file, and the Clear Log file is prepared against when switching next time and used then; Each journal file is written in the independent archive file, contains current system time in the archive file name, finishes then.
The invention has the beneficial effects as follows: all module invokes are unified writes the daily record function, guarantees that the journal format of total system is unified and standard fully, is convenient to analyze and check.Application module directly writes shared drive with log content, and than the mode of traditional written document, speed of the present invention is faster.Through recycling the mode of three shared drives, make the log management process log information in the temporary transient untapped shared drive transferred in the journal file between can be at one's leisure, avoid application modules to produce and disturb.Owing to be that three internal memories recycle, so only need taking less Installed System Memory, the present invention gets final product, can not cause waste to memory headroom.
Further, journal file also adopts the journal file of three unified sizes, recycles, and each journal file can be write log content in the archive file after writing and expiring automatically, is convenient to permanent preservation.
Further, each journal file is written in the independent archive file, contains current system time in the archive file name, searches according to the time period when being convenient to log query, and the controllable size of each archive file conveniently reads fast.
Description of drawings
Fig. 1 is a process flow diagram of writing daily record of the present invention;
Fig. 2 is the process flow diagram of log management of the present invention;
Embodiment
Below in conjunction with accompanying drawing principle of the present invention and characteristic are described, institute gives an actual example and only is used to explain the present invention, is not to be used to limit scope of the present invention.
General-purpose system blog management method of the present invention comprises the steps:
Step 1: create three onesize daily record shared drives and three onesize journal files in advance;
Step 2: when writing daily record, search the current daily record shared drive that is using;
Step 3: judge whether current daily record shared drive is write full;
Step 4: if not, the log content current daily record shared drive that writes direct finishes then; If log content writes next daily record shared drive, and change the current memory block sequence number of using into next piece; Execution in step 5;
Step 5: if all daily record shared drives have been write full daily record; Judge whether current journal file is write completely, if not, the log content of will being correlated with automatically records in the current journal file; The content of Clear Log shared drive is prepared against when switching next time and is used then; If, execution in step 6;
Step 6: write because of current journal file and full then to automatically switch to next journal file, and change the current file sequence number of using into the next one; Execution in step 7;
Step 7: if all journal files have been write full daily record, the log content of will being correlated with automatically records in the archive file, and the Clear Log file is prepared against when switching next time and used then; Each journal file is written in the independent archive file, contains current system time in the archive file name, finishes then.
In step 4, as shown in Figure 1, application module calls the following daily record function of writing and writes daily record:
void?APIWriteLog(int?log_code,long?procid,int?module,int?level,int?type,char*logbuf);
Each parameter declaration is following:
Above-mentioned function at first judge current daily record memory block whether write full, if write full, then with the log content current daily record memory block that writes direct; Otherwise, log content is write next piece internal memory, and change current daily record internal memory sequence number into next piece, realize recycling of three daily record memory blocks.
In step 4~6; As shown in Figure 2, through special log management process, the user mode of daily record memory block and journal file is monitored in real time; There is daily record data if find other two internal memories of non-current memory block; Then the log information in the memory block is write journal file, while Clear Log memory block is in order to recycle next time.In writing the process of journal file, write completely if find current journal file, then switch to next journal file, simultaneously the journal file of writing full log content is carried out archive operation, generate the permanent daily record archive file of preserving.
Below for adopting the profile information of the inventive method, the presents configuration be the process operation time essential information used, adopt the ini file form.
The above is merely preferable case study on implementation of the present invention, and is in order to restriction the present invention, not all within spirit of the present invention and principle, any modification of being done, is equal to replacement, improvement etc., all should be included within protection scope of the present invention.