Embodiment
Below in conjunction with the accompanying drawings, embodiments of the invention are described.
The recording method for the log information that the embodiment of the present application is provided and device, it is adaptable to which service end is in response
During to the call request of service interface, the field that the implementing result to the logical code of service interface is recorded
Scape, is particularly suitable for use in and the implementing result of multiple branch codes in the logical code of service interface is recorded
Scene.Wherein, service interface refers to the entrance that service end is supplied to client to use its function, i.e., every
Individual service interface can correspond to One function, namely client calling by the service interface to service end,
A business operation can be performed.Multiple branch codes herein can be identified by default numbering,
Wherein, default numbering can any can embody the information of its uniqueness.In one example, this is pre-
If numbering can be made up of letter and number, and with succession.Such as, the default numbering can be:
"-BK-1 ", "-BK-2 ", "-BK-3 " etc..
It should be noted that above-mentioned default numbering can write patrolling for service interface by developer
It is arranged on when collecting code in each branch code.Set in the logical code of service interface for branch code
After default numbering, when calling service interface, namely in the corresponding function of execution service interface, just
Relevant information during response call request can be output in journal file, related letter herein
Breath can include numbering, implementing result and interface parameters of branch code etc..Journal file herein can
Be can be with recording responses service interface in journal file corresponding with service interface, the i.e. journal file
Relevant information during multiple call request, wherein, the branch's generation being performed in each call request
Code can be identified by tracking identification number.
The recording method flow chart for the log information that Fig. 1 provides for a kind of embodiment of the application, methods described
Executive agent can be the equipment with disposal ability:Server or system or device, such as Fig. 1
Shown, methods described can specifically include:
Step 110, when service end receives the call request to service interface, generation please with described call
Corresponding tracking identification number is sought, the tracking identification number is used to uniquely identify a call request.
Call request herein can be sent by client.Specifically, service end is being received to clothes
Be engaged in interface call request when, corresponding thread can be started, the thread after startup is to above-mentioned service interface
Call request is sent, to complete the execution to the logical code of service interface.
In one example, tracking identification number corresponding with the call request, tool are generated in step 110
Body can be:
Obtain Internet protocol (Internet Protocol, the IP) address of the service end and current
Temporal information;
According to the IP address, current time information and predetermined threshold value, generation and the call request pair
The tracking identification number answered.
For example, when the logical code of service interface is write by Java language, then letter can be passed through
Number:InetAddress.getHostAddress () obtains the IP address of service end;Afterwards can be to clothes
It is engaged in handling below the IP address progress at end:The period in IP address is removed, four numerals are obtained;For
Each numeral in four numerals, can convert thereof into corresponding hexadecimal data, wherein per number
The transfer process of word can be:The numeral is assigned to variable i pNum, afterwards finally by using function:
Integer.toHexString (ipNum), it is possible to obtain corresponding two hexadecimal datas;Herein,
If the hexadecimal data that any numeral is converted to is less than two, it can be supplemented with 0 prefix.Can be with
Understand, each numeral in four numerals is converted into after corresponding hexadecimal data, just
The hexadecimal data of eight can be obtained.As an example it is assumed that the IP address of the service end obtained is:
1.1.1.1, remove after the period in IP address, obtain four numerals:1st, 1,1 and 1;Should
Four numerals are converted to after corresponding hexadecimal data, still for:1st, 1,1 and 1, because not
Two, foot, then 0 prefix is supplemented, namely the hexadecimal data of eight finally given is:01010101.
Furthermore, it is possible to pass through function:System.currentTimeMillis () obtains current time
Millisecond number;In addition, because multiple call requests may be received simultaneously in one millisecond of a server,
In order to be that each call request generates different tracking identification numbers, the application can with preset threshold value,
It should be 1 from increasing train value when initial e.g. from increasing train value that the predetermined threshold value, which can be one eight, when
When receiving next call request in same millisecond, then it is changed into 2 from increasing train value, by that analogy, directly
To when should reach 9999999 from increasing train value, then restart from 1 to add up, you can reuse.It is logical
Cross the IP address of service end, the millisecond number of current time and combined from increasing train value, so that it may
To generate tracking identification number.Because instruction request amount is estimated according to business processing amount, one in same millisecond
The call request of platform server can not possibly be more than 9999999, therefore, the generation method of above-mentioned tracking identification number
It may insure its uniqueness.In one example, the tracking identification number of generation can be:
0a0d87d114544049250931001。
Certainly, in actual applications, can also be by other methods generation tracking identification number, as long as can
Ensure its uniqueness, the application is not construed as limiting to this.
It is understood that a call request of service interface is responded by a thread, therefore can
So that unique tracking identification number of generation is set into response thread context.Passed through with logical code
Exemplified by Java language is realized, when tracking identification number is expressed as traceId, tracking identification number setting is arrived
Responding the code of realizing of thread context can be:ThreadLocal.set(traceId).
Step 120, the logical code of the service interface is performed, wherein, the logical code is comprising multiple
Branch code, each branch code is identified by numbering.
Specifically, after the call request that response thread is sent is received, it is possible to perform service interface
Logical code, the logical code can include multiple branch codes.In one example, each branch
Code is determined by the different values of the interface parameters of the service interface.For example, service connects
The logical code of mouth is as follows, wherein, a is the interface parameters of service interface.
…
If(a≤1){…};
Else if(1<a≤2){…};
Else{…};
…
In the examples described above, every a line is a branch code in logical code, i.e., as interface parameters a
Value when being not more than 1, perform first branch code;When interface parameters a value is more than 1 and not
During more than 2, second branch code is performed;Otherwise when interface parameters a value is more than 2, then hold
The 3rd branch code of row.
Illustrate herein, be limited to only list in length, example service interface an interface parameters and
Three branch codes, may include tens interface parameters of service interface actually in logical code,
And up to a hundred branch codes may be included.
It should also be noted that, multiple branch codes in logical code can be carried out by default numbering
Mark, wherein, default numbering can any can embody the information of its uniqueness.In one example,
The default numbering can be made up of letter and number, and with succession.Such as, the default numbering can
Think:"-BK-1 ", "-BK-2 ", "-BK-3 " etc..
Above-mentioned default numbering can be arranged on by developer when writing the logical code of service interface
In each branch code;In addition, developer can also set tracking in the logical code of service interface
Identification number."-BK-1 ", "-BK-2 " in logical code schematic diagram shown in Figure 2, Fig. 2,
"-BK-3 " ..., "-BK-7 " be branch code that developer is set in advance in logical code
Numbering;Further, it is also possible to currently be called by function ThreadLocal.get () to obtain response in real time
The tracking identification number generated during request, to export this tune in the journal file of service interface
With the corresponding relation for the numbering for asking corresponding tracking identification number and branch code.
Step 130, if the first branch code in the multiple branch code is performed, by the tracking
The corresponding relation of identification number, the numbering of first branch code and implementing result is output to journal file
In.
Journal file herein can be can in journal file corresponding with service interface, the i.e. journal file
With the relevant information during the multiple call request of recording responses service interface, wherein, call every time
The branch code being performed in request can be identified by tracking identification number.In addition, above-mentioned first point
Branch code can be the either branch code in multiple branch codes.
Although it is understood that in the logical code of service interface include multiple branch codes,
During a call request for responding service interface, namely during a business operation is performed,
May only have element branches code to be performed, therefore, only need recording responses once to call in journal file
The branch code being performed during request.
In one example, the log information recorded in journal file can be with as shown in figure 3, from Fig. 3
As can be seen that the corresponding identification number that tracks of current call request is:0a0d87d114544049250931001,
And the numbering for the branch code being performed during responding current call request is respectively:P-B-1、
P-B-3, P-B-6, P-B-14, P-B-15 and P-B-18.In addition, log information in Fig. 3 can be with
The implementing result of suction parameter and each branch code including service interface.Thus, it is possible to find out,
In the journal file of the application while the suction parameter and implementing result of branch code is recorded, also remember
The tracking identification number that is generated during having recorded the current call request of response and the volume for being performed branch code
Number, so as to facilitate developer when it is determined that the request results of this call request do not meet expected,
By numbering the analysis of corresponding branch code and its implementing result to what is recorded in journal file come to occurring
The problem of be tracked.
It should be noted that in journal file shown in Fig. 3, to each branch code, can all record phase
The tracking identification number answered, so as to which response tracking identification number mark according to tracking identification number, can be read
Call request during the branch code that performs;Namely have recorded in the journal file shown in Fig. 3 point
Branch matches summary info.
It is understood that because service end (service cluster) can be to the multiple tune of same service interface
Carried out responding simultaneously with request, therefore, in the journal file shown in Fig. 3 can also include other tracking marks
The numbering of the branch code performed during knowledge number, the corresponding call request of the other tracking identification numbers of response
And the corresponding relation of implementing result;The recording method of its branch matching summary info is with the record in Fig. 3
Method is similar, does not repeat again herein.It is understood that repeatedly branch's matching summary of call request is believed
Breath is spaced, namely branch's match information during call request of response is then recorded in not
Continuous row.Specifically, reference can be made to following example:
Track the implementing result 1 of 1 branch of identification number 1;
Track the implementing result 2 of 2 branch of identification number 1;
Track the implementing result 3 of 1 branch of identification number 3;
…
After the logical code for completing service interface is performed, namely perform complete business operation it
Afterwards, service end can just return to the implementing result of business operation to client;The implementing result can be industry
The correct result or business operation that business operation is returned when being executed correctly perform what is returned during failure
Error result.
It should be noted that after implementing result is returned to client, can also be by this call request
Corresponding tracking identification number is output in another journal file, as shown in figure 4, another journal file can
Summary info during being for this call request of recording responses, e.g., title, the parameter of service interface
Information and tracking identification number etc..Certainly, in actual applications, can also be direct by above-mentioned summary info
It is output in the journal file shown in Fig. 3, the application is not construed as limiting to this.
It is understood that when a call request of service interface starts, the tracking of generation is identified
Number set to response thread context in;After this call request accordingly terminates, then need to line
The context of journey is cleared up, e.g., tracking identification number etc. is removed, so that the thread can be reused.
Generation the application Fig. 3 and Fig. 4 shown in journal file after, when service interface once
When the request results of call request are error result, namely when not meeting expected, the application can also be provided
The method of reading journal file shown in Fig. 5 is come dividing for being performed during reading this call request of response
Branch code, so that by the analysis to these branch codes and its implementing result, to be called to responding this
The problem of during request, is tracked;As shown in figure 5, the embodiment of the present application comprises the following steps:
Step 510, receive the query statement of user's input, in the query statement comprising tracking identification number with
And the title of journal file.
Herein, tracking identification number can be according to the title of service interface, the title of journal file and connect
Mouth parameter, reads from the journal file shown in Fig. 4, wherein, the title of service interface, daily record
The title and interface parameters of file can all be known in advance, e.g., can be read by following order line
Take:
$grep CustomerSearchFacade/opt/logs/rpc-server-digest.log|grep
Zhang San | grep 33010;
Wherein, " CustomerSearchFacade " is the title of service interface,
" rpc-server-digest.log " be Fig. 4 shown in journal file title, " Zhang San " and
" 33010 " etc. are interface parameters;By mentioned order read from the journal file shown in Fig. 4 with
Track identification number can be:0a0d87d114544049250931001.
Step 520, according to the title of the journal file, corresponding journal file is obtained.
Step 530, according to the tracking identification number, read and identified with the tracking from the journal file
The numbering and implementing result of number corresponding the multiple branch code.
After read above-mentioned tracking identification number, it is possible to according to tracking identification number and journal file
Title, reads each point performed during responding this call request from the journal file shown in Fig. 3
The numbering of branch code.Such as, it can be read by following order line:
$grep 0a0d87d114544049250931001search-digest.7dt.log
Wherein, " search-digest.7dt.log " is the title of the journal file shown in Fig. 3;It is i.e. first
First according to " search-digest.7dt.log ", the journal file shown in Fig. 3 is obtained;Afterwards, from this
The numbering of the branch code corresponding with " 0a0d87d114544049250931001 " is read in journal file:
P-B-1, P-B-3, P-B-6, P-B-14, P-B-15 and P-B-18 and implementing result, in addition, also
The interface parameters of each branch code can be read.It is understood that because of the daily record shown in Fig. 3
The volume of each branch code of the execution recorded during call request of response is only have recorded in file
Number, therefore, the result read in the step is the content shown in Fig. 3.
Developer passes through each branch code performed during to responding this call request and its execution
As a result analyzed, you can rapidly produced problem is tracked, asked so as to quick navigate to
Reason is inscribed, and then solves the problem of client request is less than correct result, it is to avoid influence expands.
To sum up, due to have recorded the corresponding tracking identification number of call request in the journal file of the application, together
When have recorded call request of response during the numbering of branch code that performs;Thus, when once
, can be according to the branch code recorded in journal file when the request results of call request do not meet expected
Numbering, the branch code performed during quickly determining out the current call request of response, by holding
The analysis of the implementing result of capable branch code, it is possible to quickly positioned to problem.
Accordingly, a kind of daily record that the embodiment of the present application is also provided is believed for recording method with above-mentioned log information
The tape deck of breath, as shown in fig. 6, the device includes:Generation unit 601, execution unit 602 and defeated
Go out unit 603.
Generation unit 601, for being received when service end during the call request to service interface, generation and institute
The corresponding tracking identification number of call request is stated, the tracking identification number is used to uniquely identify once to call to ask
Ask.
Wherein, generation unit 601 specifically for:
Obtain the internet protocol address and current time information of the service end;
According to the IP address, current time information and predetermined threshold value, generation and the call request pair
The tracking identification number answered.
Execution unit 602, the logical code for performing the service interface, wherein, the logical code
Comprising multiple branch codes, each branch code is identified by numbering.
Wherein, the multiple branch code can be the different values of the interface parameters by the service interface
Determine.
Output unit 603, will if being performed for the first branch code in the multiple branch code
The tracking identification number, the numbering of first branch code and the corresponding relation of implementing result are output to
In journal file.
Alternatively, described device also includes:Receiving unit 604 and reading unit 605.
Comprising described in receiving unit 604, the query statement for receiving user's input, the query statement
Track the title of identification number and the journal file.
Reading unit 605, for the title according to the journal file, obtains the journal file, and from
The volume of the multiple branch codes that are performed corresponding with the tracking identification number is read in the journal file
Number and implementing result.
Alternatively, output unit 603 is additionally operable to the title of the service interface, parameter information and described
Tracking identification number is output in another journal file.
The function of each functional module of the embodiment of the present application device, can pass through each of above method embodiment
Step realizes that therefore, the specific work process for the device that the application is provided herein is not repeated again.
The tape deck for the log information that the application is provided, is asked when service end is received to calling for service interface
When asking, generation unit 601 generates tracking identification number corresponding with the call request;Execution unit 602
The logical code of the service interface is performed, wherein, the logical code includes multiple branch codes, often
Individual branch code is identified by numbering;If the first branch code in the multiple branch code is held
OK, output unit 603 is by tracking identification number, the numbering of first branch code and performs knot
The corresponding relation of fruit is output in journal file.Thus, it is possible to effectively please to once calling for service interface
The log information asked is recorded, so as to effectively to the logical code of service interface the problem of carry out with
Track.
Professional should further appreciate that, be described with reference to the embodiments described herein
The object and algorithm steps of each example, can be come with electronic hardware, computer software or the combination of the two
Realize, in order to clearly demonstrate the interchangeability of hardware and software, in the above description according to function
Generally describe the composition and step of each example.These functions are come with hardware or software mode actually
Perform, depending on the application-specific and design constraint of technical scheme.Professional and technical personnel can be to every
Described function is realized in individual specific application using distinct methods, but it is this realize it is not considered that
Beyond scope of the present application.
The step of method or algorithm for being described with reference to the embodiments described herein, can use hardware, processing
The software module that device is performed, or the two combination are implemented.Software module can be placed in random access memory
(RAM), internal memory, read-only storage (ROM), electrically programmable ROM, electrically erasable ROM,
Any other form well known in register, hard disk, moveable magnetic disc, CD-ROM or technical field
Storage medium in.
Above-described embodiment, purpose, technical scheme and beneficial effect to the application are carried out
Be further described, should be understood that the embodiment that the foregoing is only the application and
, it is not used to limit the protection domain of the application, it is all within spirit herein and principle, done
Any modification, equivalent substitution and improvements etc., should be included within the protection domain of the application.