Summary of the invention
Owing to the log collecting method of existing intelligent robot only triggers log collection after program is run quickly and burst, cause daily record
Collect complete, simultaneously cannot the problem of on-demand active collection daily record, the present invention proposes a kind of log collecting method and device.
First aspect, the embodiment of the present invention proposes a kind of log collecting method, including:
Judge whether the corresponding daily record of terminal applies service is collected;
If desired it is collected, it is determined that the output stage of the most corresponding log collection of intended application service being collected
Not;
Send to terminal to collect and preset the log collection instruction that output level is corresponding;
Receive the corresponding daily record of the described default output level of the described intended application service that described terminal sends respectively.
Preferably, described in judge whether to terminal applies service corresponding daily record be collected, farther include:
Described server is according to current time, current location, current network conditions and server memory situation, it may be judged whether
The corresponding daily record of the application service being installed terminal is collected.
Preferably, the described output level determining the most corresponding log collection of intended application service being collected, enter one
Step includes:
According to stl status and fault restoration state, determine the output stage of the intended application service log collection of correspondence respectively
Not.
Preferably, the described default output level that the described described intended application receiving the transmission of described terminal respectively services
Corresponding daily record, farther includes:
Burst receives the corresponding daily record of the described default output level of the described intended application service that described terminal sends.
Preferably, described method also includes:
According to default file address, daily record corresponding for described default output level is stored to described default file.
Preferably, according to default file address, described method also includes:
The daily record of storage in described default file is analyzed, generates analysis result and show.
As shown from the above technical solution, the log collecting method that the embodiment of the present invention provides judges to determine by server
No carry out log collection, it is possible to realize the active collection of server, it is to avoid log collection triggers single problem;By output
Rank collects different daily records, it is possible to meets the requirement of the on-demand collection of user, avoids the problem that log collection is the most complete simultaneously.
Second aspect, the embodiment of the present invention also proposes a kind of log collection device, including:
Log collection determines module, for judging whether that the corresponding daily record servicing terminal applies is collected;
Output level determines module, for being if desired collected, it is determined that the intended application service being collected is respectively
The output level of corresponding log collection;
Instruction sending module, presets, for sending to terminal to collect, the log collection instruction that output level is corresponding;
Daily record receiver module, for receiving the described default output of the described intended application service that described terminal sends respectively
The corresponding daily record of rank.
Preferably, described log collection determines that module is further used for according to current time, current location, current network feelings
Condition and server memory situation, it may be judged whether the corresponding daily record of the application service being installed terminal is collected.
Preferably, described output level determines that module is further used for, according to stl status and fault restoration state, determining
The output level of the log collection that intended application service is the most corresponding.
Preferably, described daily record receiver module is further used for the described intended application clothes that the burst described terminal of reception sends
The corresponding daily record of the described default output level of business.
Preferably, described device also includes:
Memory module, for according to default file address, stores daily record corresponding for described default output level to described
In default file.
Preferably, described device also includes:
Log analysis module, for being analyzed the daily record of storage in described default file, generates analysis result and shows
Show.
As shown from the above technical solution, the log collection device that the embodiment of the present invention provides judges to determine by server
No carry out log collection, it is possible to realize the active collection of server, it is to avoid log collection triggers single problem;By output
Rank collects different daily records, it is possible to meets the requirement of the on-demand collection of user, avoids the problem that log collection is the most complete simultaneously.
Detailed description of the invention
Below in conjunction with the accompanying drawings, the detailed description of the invention of invention is further described.Following example are only used for more clear
Chu's ground explanation technical scheme, and can not limit the scope of the invention with this.
Fig. 1 shows the schematic flow sheet of a kind of log collecting method that one embodiment of the invention provides, including:
S101, judge whether to terminal applies service corresponding daily record be collected;
Wherein, server can be according to decision rule, and actively the corresponding daily record to terminal applies service carries out log collection;Institute
Stating decision rule can be: according to the routine work timetable of intelligent robot, select its free time to carry out log collection, with
Do not affect the routine work efficiency of intelligent robot;Or, according to the network condition that server is current, when network speed is very fast
Carry out log collection;Or, according to the internal memory situation that server is current, when free memory is more than threshold value, carry out log collection.
Or, server can also determine whether the day to each application service of terminal according to the monitoring file that terminal sends
Will is collected.Specifically, in terminal side, including the monitoring service to each application service monitoring state;Described prison
The state of control each application service of service acquisition, and upload monitoring file, described monitoring according to prefixed time interval to server
File includes the running status of each application service.Specifically, in terminal side, including multiple application services, each application
Service the most corresponding one or more journal files.
Determine whether the corresponding daily record of terminal applies service is carried out log collection by judgement, it is possible to log collection
Switch dynamically controls.So can control output and the closedown of daily record flexibly so that consume there is no extra performance
Meanwhile, complete daily record data can be collected, be analyzed for follow-up;Actively initiated by service end to collect instruction simultaneously,
Intellectual analysis judges to collect, the pattern that the passive collapse that breaks traditions is collected so that collection mode is flexible and changeable, simultaneously to intelligent machine
The fault diagnosis of device people is more comprehensively.
S102, if desired it is collected, it is determined that the most corresponding log collection of intended application service being collected defeated
Go out rank;
Specifically, judge and determine the output level of log collection corresponding to each application service according to preset rules.
For example, described preset rules can be the order of severity of fault, such as minor failure, moderate fault and severe
Fault;Or, the repair time of fault, such as 1 minute, 10 minutes, 30 minutes, 3 hours and 2 days;Or, can be according to user's
Specific requirement presets.
Wherein, described output level is the different output requirements that each journal file is corresponding, illustrates corresponding application service
The abnormal rank produced during operation.
For example, output level can be respectively set to from low to high: i (infor, notice), v (verbose, aobvious
Show details), d (debug, recoverable), w (warn, warning) and e (error, fault).Wherein, i represent only notify use
The daily record made a mistake in family, abnormal rank is minimum, and v represents the details daily record sending mistake to user, and d represents and informs user
For recoverable error log, w represents the error log that warning user should be noted, e represents and sends fault log to user, abnormal
Rank is the highest.
Or, described output level can represent with 1 grade-5 grades, and output level is the daily record of 1 grade of expression critical function module
With the daily record of the functional module broken down, the daily record that need to upload in real time;Output level is the day of 2 grades of expression secondary function modules
Will, uploads according to the instruction of server;Output level is the daily record of 3 grades of expression general function modules, according to server
Instruction is uploaded.When the output level of journal file M is 2 grades, and functional module corresponding to journal file M does not breaks down,
Then when server uploads 2 level logs to intelligent robot transmission, just upload this journal file M to server.
Or, described output level can be defined according to the specific requirement of user.
Specifically, at intelligent robot end, need to carry out following steps:
A1, creating at intelligent robot end and be installed on the monitoring service object of terminal, each application service takes in each application
At the main-inlet of business, get the example of monitoring service object according to monitoring service object respectively, and then judge whether this is answered
Log collection is carried out with service;
A2, object initialization, each application service is each called after getting this monitoring service object's example respectively initially
Change method initializes;
Wherein, in step A2, each application service have received monitoring service object's example respectively, right according to detection service
Switch LOG_ENABLED and debugflag's DEBUG attribute are collected in permission as defined in example, and the daily record controlling self record is
The no control station that should export terminal.Switch is collected in described permission and described debugflag is boolean type data, described
Allow to collect switch LOG_ENABLED and represent whether intelligent robot end allows the switch of server collector journal, default situations
It is down closed mode, to prevent the illegal collection of rogue program;When server judge determine need to carry out log collection time, described
Allow to collect switch and will change to open mode;Described debugflag is more convenient for debugging access during debugging for convenience
And the labelling arranged.Detection service object's example also have registered a self-defining radio receiver, this radio receiver simultaneously
It is responsible for response command, controls daily record and switch, and open the service of collector journal information, be used for log collection and upload.
A3, daily record output, the monitoring service object's example after each application service initializes calls output level method, past
The log information of control station output different stage;Wherein, output level method can be self-defined according to specific requirement by user.
Wherein, step A3 adds new function package, enhances the scheme of primary system so that it is during use more just
Profit, but the most do not change the Code Design style of former Google, allow routine call time accessible.And the definition in step A3
Having the daily record rank operated, respectively minimal level minLevel and maximum level maxLevel, also a pressure is defeated
Go out parameter, can restriction in break through step A2.Specifically, when step A3 arranges pressure output, the most no matter limit of step A2
Condition processed how, all exports according to minimal level in step A3 and maximum level.For example, when forcing output minimum level
It is not 2, when maximum level is 4, then the daily record that output level is 2,3,4 is uploaded onto the server.
For example,
B1, application service, at main-inlet, get this monitoring by LogCat.getInstance (String tag)
The example of service object, log collection must necessarily be placed in porch, and optimal implementation is placed on self-defining Application
In, the most forward operation of instantiation of this monitoring service object.The tag specified is had to be easy to during each LogCat instantiation
Distinguish filtering log;
B2, get this monitoring service object's example after call init (Context context) method to this object
Example initializes.Initialization of this step is in order to the LogCat object created done default configuration, internal also have control and
Revertive control mechanism, the mechanism that such encapsulation makes inside complicated is called and is become simple succinct.
B3, call logCat.i (String className, String msg) and logCat.i (String
ClassName, String msg, boolean isOut, String fileName) etc., corresponding corresponding daily record rank, meet
The daily record level rule of Android definition itself, isOut parameter can break through overall daily record switching mechanism, and fileName specifies guarantor
The local file of the daily record deposited, flexible and changeable.
By log collection is carried out rank control, it is possible to solve the analysis difficulty that huge daily record causes;By specifying
The scope of rank is uploaded, it is possible to only analyzes the daily record that user is concerned about, reduces analysis time, quickly location fault and problem.
S103, the log collection sending the default output level of collection to terminal corresponding instruct;
Wherein, described default output level can pre-set according to the requirement of user.
Specifically, server actively can control to open the service of collection by reserved backstage port;Open the service of collection
After, server sends to terminal collects the collection instruction presetting daily record corresponding to output level.
Wherein, described collection instructs the default output level including daily record.
For example, server sends the daily record collecting output level less than 3 to terminal, then terminal needs output level
Be 1 and 2 daily record upload onto the server.Wherein, described terminal can be intelligent robot.
S104, receive corresponding day of described default output level of the described intended application service that described terminal sends respectively
Will.
Specifically, after server sends the collection instruction of the corresponding daily record collecting described default output level to terminal,
Terminal side, concrete step includes:
It is first turned on allowing to collect switch;
Then according to the output level of the daily record collected in instruction, the daily record that described output level is corresponding is searched;
Finally daily record packing corresponding for described output level is uploaded to described server.
At server-side, after the daily record of packing is uploaded by terminal, receive the daily record that described default output level is corresponding.
The present embodiment judges to determine whether to carry out log collection by server, it is possible to realize the active collection of server,
Avoid log collection and trigger single problem;Different daily records is collected, it is possible to meet the on-demand collection of user by output level
Requirement, avoid the problem that log collection is the most complete simultaneously.
Further, on the basis of said method embodiment, S101 farther includes:
Described server is according to current time, current location, current network conditions and server memory situation, it may be judged whether
The corresponding daily record of the application service being installed terminal is collected.
Specifically, Chief Web Officer link keep-alive techniques, heart beating can be used to send detection technique and integrated system situation analysis
Decision-making, it is determined whether the daily record of the application service being installed terminal is collected.Wherein, described Chief Web Officer link keep-alive techniques
Represent the connection maintaining network permanent and stable;Described heart beating sends after detection technique represents interval Preset Time and sends out to server
Send notice, inform and be currently running;Described integrated system situation analysis decision-making represents that summation considers that multiple factors are analyzed, such as
Run according to current time, current location, current network conditions, current interaction scenario, server memory situation, total system
The various factors such as situation combine and judge whether to need to start smartphone daily record.
For example, server selects the triggering mode of a kind of collection, such as: call startSave method, and service end sends
Diagnostic function is opened in instruction, and the service of concrete collection order is in another independent process, and this process is responsible for log collection and beats
Wrap biography, be not involved in other business, it is ensured that safety.
Log collection is judged whether to, it is possible to combine current concrete condition and carry out daily record receipts by current design parameter
Collection, not affect the routine work of intelligent robot, and improves the efficiency of log collection.
Further, on the basis of said method embodiment, S102 farther includes:
According to stl status and fault restoration state, determine the output stage of the intended application service log collection of correspondence respectively
Not.
Specifically, described stl status refers to the mode of operation that daily record is current, for example whether update;Described fault is repaiied
Change state refer to the application program of log recording break down after state, for example whether repair.
When daily record is in more new state, rank can be output it and be set to relatively low rank, to prevent daily record renewal process
In upload the full problem of data that daily record causes.
After the application program of log recording breaks down the most repaired, then this daily record can be set to second highest rank, with
Upload server as early as possible;Do not repair after the application program of log recording breaks down, then this daily record can be set to the superlative degree
Not, with timely upload server.
Further, on the basis of said method embodiment, S104 farther includes:
Burst receives the corresponding daily record of the described default output level of the described intended application service that described terminal sends.
Use daily record allocation methods, it is possible to increase the success rate that daily record is uploaded, reduce bandwidth consumption, reduce network simultaneously and pass
Defeated pressure.
Specifically, after intelligent robot is compressible when daily record is uploaded, burst is uploaded again.
Further, on the basis of said method embodiment, as in figure 2 it is shown, described method includes:
S201, judge whether to terminal applies service corresponding daily record be collected;
S202, if desired it is collected, it is determined that the most corresponding log collection of intended application service being collected defeated
Go out rank;
S203, the log collection sending the default output level of collection to terminal corresponding instruct;
S204, receive corresponding day of described default output level of the described intended application service that described terminal sends respectively
Will.
S205, according to default file address, daily record corresponding for described default output level is stored to described default file
In.
Wherein, corresponding for S201-S204 with Fig. 1 S101-S104 in embodiment is corresponding.
Described default file address can pre-set according to the specific requirement of user.
Specifically, by arranging thread pool and file security lock control in S205, it is ensured that file is correctly, safely and efficiently
In write default file.
Further, on the basis of said method embodiment, as it is shown on figure 3, described method includes:
S301, judge whether to terminal applies service corresponding daily record be collected;
S402, if desired it is collected, it is determined that the most corresponding log collection of intended application service being collected defeated
Go out rank;
S303, the log collection sending the default output level of collection to terminal corresponding instruct;
S304, receive corresponding day of described default output level of the described intended application service that described terminal sends respectively
Will.
S305, according to default file address, daily record corresponding for described default output level is stored to described default file
In.
S306, the daily record of storage in described default file is analyzed, generates analysis result and also show.
Wherein, corresponding for S301-S205 with Fig. 2 S201-S205 in embodiment is corresponding.
Specifically, through the analysis of server in S306, different error codes can be generated, and make mark, for
The set of family these data of preview clearly on backstage.
For example, problem identification may include that and do not solves, unimportant, solves, and currently cannot solve, Retarded Solution
Certainly, special treatment.
By daily record is analyzed, it is possible to generate completely and intuitively functional diagnosis result, can be by for developer
The management of response application service need to be carried out.
The present embodiment carries out segregation of duties to overall structural framing, uses dynamical fashion to control daily record switch, and with solely
Vertical process Service logcat order collector journal information analysis diagnostic function.I.e. by the work of each system service of terminal monitoring
State, once detect that abnormality reports server, then server actively starts to add up this terminal accordingly extremely
The abnormal log that module is corresponding, and unify abnormal log is forwarded to log server generation error code, carry out merit for developer
Can diagnosis.
The present embodiment can use the Logcat command set of google android system, by combining java thread pond, many
Threading, multi-process file security Writing Technology, file fragmentation and synthetic technology so that program log collection and upload shape
Become a perfect closed loop, had that information is complete, program is stable, performance consumption is low and the advantage of smartphone, and
And also support response remote collection instruction, have that safety is high, autgmentability is strong, the simple advantage of operability and a technique extension, with
And the progressive meaning constantly brought forth new ideas.
Fig. 2 shows the structural representation of a kind of log collection device that one embodiment of the invention provides, described device bag
Include: log collection determines that module 21, output level determine module 22, instruction sending module 23 and daily record receiver module 24;Wherein,
Described log collection determines that module 21 is for judging whether that the corresponding daily record servicing terminal applies is collected;
Described output level determines that module 22 is for being if desired collected, it is determined that the intended application service being collected
The output level of the most corresponding log collection;
Described instruction sending module 23 presets, for sending to terminal to collect, the log collection instruction that output level is corresponding;
It is described pre-that the described intended application that described daily record receiver module 24 sends for receiving described terminal respectively services
If the corresponding daily record of output level.
Specifically, described log collection determines that module 21 judges whether that the corresponding daily record servicing terminal applies is received
Collection;Described output level determines that module 22 is if desired collected, it is determined that the intended application service correspondence respectively being collected
The output level of log collection;Described instruction sending module 23 sends to collect to terminal presets the log collection that output level is corresponding
Instruction;Described daily record receiver module 24 receives the described default output stage of the described intended application service that described terminal sends respectively
Other corresponding daily record..
The present embodiment judges to determine whether to carry out log collection by server, it is possible to realize the active collection of server,
Avoid log collection and trigger single problem;Different daily records is collected, it is possible to meet the on-demand collection of user by output level
Requirement, avoid the problem that log collection is the most complete simultaneously.
Further, on the basis of said apparatus embodiment, described log collection determines that module 21 is further used for root
According to current time, current location, current network conditions and server memory situation, it may be judged whether the application clothes that terminal is installed
The corresponding daily record of business is collected.
Further, on the basis of said apparatus embodiment, described output level determines that module 22 is further used for root
According to stl status and fault restoration state, determine the output level of the intended application service log collection of correspondence respectively.
Further, on the basis of said apparatus embodiment, described daily record receiver module 24 is further used for burst and connects
Receive the corresponding daily record of the described default output level of the described intended application service that described terminal sends.
Further, on the basis of said apparatus embodiment, described device also includes:
Memory module 25, for according to default file address, stores daily record corresponding for described output level to described pre-
If in file.
Further, on the basis of said apparatus embodiment, described device also includes:
Log analysis module 26, for being analyzed the daily record of storage in described default file, generates analysis result also
Display.
Log collection device described in the present embodiment may be used for performing said method embodiment, its principle and technique effect
Similar, here is omitted.
Device embodiment described above is only schematically, and the wherein said unit illustrated as separating component can
To be or to may not be physically separate, the parts shown as unit can be or may not be physics list
Unit, i.e. may be located at a place, or can also be distributed on multiple NE.Can be selected it according to the actual needs
In some or all of module realize the purpose of the present embodiment scheme.Those of ordinary skill in the art are not paying creativeness
Work in the case of, be i.e. appreciated that and implement.
Through the above description of the embodiments, those skilled in the art it can be understood that to each embodiment can
The mode adding required general hardware platform by software realizes, naturally it is also possible to pass through hardware.Based on such understanding, on
State the part that prior art contributes by technical scheme the most in other words to embody with the form of software product, should
Computer software product can store in a computer-readable storage medium, such as ROM/RAM, magnetic disc, CD etc., including some fingers
Make with so that a computer equipment (can be personal computer, server, or the network equipment etc.) performs each and implements
The method described in some part of example or embodiment.
It is noted that above example is only in order to illustrate technical scheme, it is not intended to limit;Although reference
The present invention has been described in detail by previous embodiment, it will be understood by those within the art that: it still can be right
Technical scheme described in foregoing embodiments is modified, or wherein portion of techniques feature is carried out equivalent;And this
A little amendments or replacement, do not make the essence of appropriate technical solution depart from spirit and the model of various embodiments of the present invention technical scheme
Enclose.