Summary of the invention
Since the log collecting method of existing intelligent robot only triggers log collection after program runs quickly and bursts, lead to log
Collect it is incomplete, while can not on demand active collection log the problem of, the present invention proposes a kind of log collecting method and device.
In a first aspect, the embodiment of the present invention proposes a kind of log collecting method, comprising:
Judge whether to be collected the correspondence log of terminal applies service;
If desired it is collected, it is determined that the target application service being collected respectively corresponds the output stage of log collection
Not;
It is sent to terminal and collects the corresponding log collection instruction of default output level;
The correspondence log of the default output level for the target application service that the terminal is sent is received respectively.
Preferably, described to judge whether to be collected the correspondence log of terminal applies service, further comprise:
The server judges whether according to current time, current location, current network conditions and server memory situation
The correspondence log for the application service that terminal is installed is collected.
Preferably, the target application service that the determination is collected respectively corresponds the output level of log collection, into one
Step includes:
According to stl status and fault restoration state, determine that target application services the output stage of corresponding log collection
Not.
Preferably, the default output level for receiving the target application service that the terminal is sent respectively
Corresponding log further comprises:
Fragment receives the correspondence log of the default output level for the target application service that the terminal is sent.
Preferably, the method also includes:
According to default file address, the corresponding log of the default output level is stored into the default file.
Preferably, according to default file address, the method also includes:
The log stored in the default file is analyzed, analysis result is generated and is shown.
As shown from the above technical solution, log collecting method provided in an embodiment of the present invention judges that determination is by server
No carry out log collection, can be realized the active collection of server, avoids log collection and triggers single problem;Pass through output
Rank collects different logs, can satisfy the requirement that user collects on demand, while avoiding the infull problem of log collection.
Second aspect, the embodiment of the present invention also propose a kind of log collection device, comprising:
Log collection determining module, for judging whether that the correspondence log to terminal applies service is collected;
Output level determining module, for being if desired collected, it is determined that the target application service difference being collected
The output level of corresponding log collection;
Instruction sending module collects the corresponding log collection instruction of default output level for sending to terminal;
Log receiving module, for receiving the default output for the target application service that the terminal is sent respectively
The correspondence log of rank.
Preferably, the log collection determining module is further used for according to current time, current location, current network feelings
Condition and server memory situation judge whether that the correspondence log for the application service installed to terminal is collected.
Preferably, the output level determining module is further used for being determined according to stl status and fault restoration state
Target application services the output level of corresponding log collection.
Preferably, the log receiving module is further used for the target application clothes that fragment receives the terminal transmission
The correspondence log of the default output level of business.
Preferably, described device further include:
Memory module stores the corresponding log of the default output level to described for according to default file address
In default file.
Preferably, described device further include:
Log analysis module, for analyzing the log stored in the default file, generating analysis result and showing
Show.
As shown from the above technical solution, log collection device provided in an embodiment of the present invention judges that determination is by server
No carry out log collection, can be realized the active collection of server, avoids log collection and triggers single problem;Pass through output
Rank collects different logs, can satisfy the requirement that user collects on demand, while avoiding the infull problem of log collection.
Specific embodiment
With reference to the accompanying drawing, the specific embodiment of invention is further described.Following embodiment is only used for more clear
Illustrate to Chu technical solution of the present invention, and not intended to limit the protection scope of the present invention.
Fig. 1 shows a kind of flow diagram of log collecting method of one embodiment of the invention offer, comprising:
S101, judge whether to be collected the correspondence log of terminal applies service;
Wherein, server actively can carry out log collection to the correspondence log of terminal applies service according to decision rule;Institute
Stating decision rule can be with are as follows: and according to the routine work timetable of intelligent robot, its free time is selected to carry out log collection, with
The routine work efficiency of intelligent robot is not influenced;Alternatively, the network condition current according to server, when network speed is very fast
Carry out log collection;Alternatively, the memory situation current according to server carries out log collection when free memory is greater than threshold value.
Alternatively, server can also determine whether the day to each application service of terminal according to the monitoring file that terminal is sent
Will is collected.Specifically, in terminal side, including the monitoring service being monitored to each application service state;The prison
The state of each application service of service acquisition is controlled, and monitoring file, the monitoring are uploaded to server according to prefixed time interval
It include the operating status of each application service in file.Specifically, in terminal side, including multiple application services, each application
The all corresponding one or more journal files of service.
It, can be to log collection by judging to determine whether that the correspondence log to terminal applies service carries out log collection
Switch carries out dynamic control.The output and closing of log can be flexibly controlled in this way, so that in the consumption of no extra performance
Meanwhile complete daily record data can be collected, it is analyzed for subsequent;It actively initiates to collect instruction by server-side simultaneously,
Intellectual analysis judgement is collected, and breaks the mode that traditional passive collapse is collected, so that collection mode is flexible and changeable, while to intelligent machine
The fault diagnosis of device people is more comprehensively.
S102, it is if desired collected, it is determined that the target application service being collected respectively corresponds the defeated of log collection
Rank out;
Specifically, the output level of the corresponding log collection of each application service is judged and determined according to preset rules.
For example, the preset rules can be the severity of failure, such as minor failure, moderate failure and severe
Failure;Alternatively, the repair time of failure, such as 1 minute, 10 minutes, 30 minutes, 3 hours and 2 days;Alternatively, can be according to user's
Specific requirement is preset.
Wherein, the output level is that the corresponding different outputs of each journal file require, and illustrates corresponding application service
The abnormal rank generated when operation.
For example, output level can be respectively set from low to high are as follows: i (infor, notice), (verbose is shown v
Show details), d (debug, recoverable), w (warn, warning) and e (error, failure).Wherein, i indicates that only notice is used
The log of mistake occurs for family, and abnormal rank is minimum, and v indicates the details log that mistake is sent to user, and d indicates to inform user
For recoverable error log, w indicates the error log that warning user should be noted, e indicates to send fault log to user, abnormal
Rank highest.
Alternatively, the output level can be indicated with 1 grade -5 grades, output level is the log of 1 grade of expression critical function module
With the log of the functional module of failure, the log that need to be uploaded in real time;Output level is the day of 2 grades of expression secondary function modules
Will is uploaded according to the instruction of server;Output level is the log 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 the corresponding functional module of journal file M is without failure,
Then when server is sent to intelligent robot uploads 2 level logs, journal file M just is uploaded to server.
Alternatively, the output level can be defined according to the specific requirement of user.
Specifically, it at intelligent robot end, needs to carry out following steps:
A1, the monitoring service object that terminal is installed in the creation of intelligent robot end, each application service take in each application
At the main-inlet of business, according to the example that monitoring service object gets monitoring service object respectively, and then judge whether to answer this
Log collection is carried out with service;
A2, object initialization, each application service are respectively called initially after getting monitoring service object example respectively
Change method is initialized;
Wherein, each application service has received monitoring service object's example respectively in step A2, according to detection service pair
Allow to collect switch LOG_ENABLED as defined in example and debugflag's DEBUG attribute, the log for controlling self record are
The no console that should be output to terminal.It is described allow collect switch and the debugflag be boolean type data, it is described
Allowing to collect switch LOG_ENABLED indicates whether intelligent robot end allows the switch of server collector journal, default situations
Under be in off state, to prevent the illegal collection of rogue program;It is described when server judgement, which determines, needs to carry out log collection
Allow to collect switch to be in an open state change;The debugflag is that debugging access is more convenient for convenience in debugging process
And the label being arranged.Detection service object instance also has registered a customized radio receiver, the radio receiver simultaneously
It is responsible for response command, control log switch, and opens the service of collector journal information, for log collection and upload.
A3, log output, monitoring service object's example after each application service initialization calls output level method, past
The log information of console output different stage;Wherein, output level method can be customized according to specific requirement by user.
Wherein, step A3 increases new function package, enhances the scheme of native system, when making its use more just
Benefit, but without change original Google Code Design style, allow routine call when it is accessible.And the definition in step A3
There are the log rank of an operation, respectively minimal level minLevel and maximum level maxLevel, it is defeated there are one forcing
Parameter out, can limitation in break through step A2.Specifically, when in step A3 setting force output when, then no matter the limit of step A2
How is condition processed, is exported according to minimal level in step A3 and maximum level.For example, when pressure exports minimum level
Not Wei 2, maximum level be 4 when, then by output level be 2,3,4 log be uploaded to server.
For example,
B1, application service get the monitoring at main-inlet, through LogCat.getInstance (String tag)
The example of service object, log collection must necessarily be placed in inlet, and optimal implementation is placed on customized Application
In, the instantiation of monitoring service object operation forward as far as possible.Each LogCat has specified tag to be convenient for when instantiating
Distinguish filtering log;
B2, it gets and calls init (Context context) method to the object after monitoring service object example
Example is initialized.Initialization of this step be in order to do default configuration to the LogCat object of creation, it is internal there are also control and
Countercharge making mechanism, such encapsulation allow the mechanism calling of internal complexity to get up to become simply succinct.
B3, logCat.i (String className, String msg) and logCat.i (String are called
ClassName, String msg, boolean isOut, String fileName) etc., corresponding corresponding log rank meets
The log level rule that Android itself is defined, isOut parameter can break through whole log switching mechanism, and fileName is specified to be protected
The local file for the log deposited, it is flexible and changeable.
By carrying out rank control to log collection, it is able to solve and analyzes difficulty caused by huge log;By specified
The range of rank is uploaded, and can only be analyzed the log that user is concerned about, be reduced analysis time, quick positioning failure and problem.
S103, it is sent to terminal and collects the corresponding log collection instruction of default output level;
Wherein, the default output level can be preset acording to the requirement of user.
Specifically, server can open the service of collection by reserved backstage port, active control;Open the service of collection
Afterwards, server sends the collection instruction for collecting the default corresponding log of output level to terminal.
Wherein, the default output level collected in instruction including log.
For example, server sends to terminal and collects log of the output level less than 3, then terminal is needed output level
Log for 1 and 2 is uploaded to server.Wherein, the terminal can be intelligent robot.
S104, receive respectively the target application service that the terminal is sent the default output level correspondence day
Will.
Specifically, after server sends the collection instruction for the correspondence log for collecting the default output level to terminal,
Terminal side, specific step include:
It is first turned on to allow to collect and switch;
Then according to the output level for collecting the log in instruction, the corresponding log of the output level is searched;
The corresponding log packing of the output level is finally uploaded to the server.
In server-side, after terminal uploads the log of packing, the corresponding log of the default output level is received.
The present embodiment determines whether progress log collection by server judgement, can be realized the active collection of server,
It avoids log collection and triggers single problem;Different logs is collected by output level, be can satisfy user and is collected on demand
Requirement, while avoiding the infull problem of log collection.
Further, on the basis of above method embodiment, S101 further comprises:
The server judges whether according to current time, current location, current network conditions and server memory situation
The correspondence log for the application service that terminal is installed is collected.
Specifically, Chief Web Officer link keep-alive techniques can be used, heartbeat sends detection technique and integrated system situation analysis
Decision, it is determined whether the log for the application service that terminal is installed is collected.Wherein, the Chief Web Officer links keep-alive techniques
Indicate the connection for maintaining network permanent and stable;The heartbeat sends detection technique and indicates to send out after being spaced preset time to server
Notice is sent, informing is currently running;The integrated system situation analysis decision indicates that summation considers that Multiple factors are analyzed, such as
According to current time, current location, current network conditions, current interaction scenario, server memory situation, total system operation
The various factors such as situation, which combine, to be judged whether to need to start smartphone log.
For example, server selects a kind of triggering mode of collection, such as: calling startSave method, server-side is sent
Diagnostic function is opened in instruction, and in another independent process, which is responsible for log collection and beats for the specific service for collecting order
Biography is wrapped, other business are not involved in, guarantees safety.
Log collection is judged whether to by current design parameter, log receipts can be carried out in conjunction with current concrete condition
Collection not influence the routine work of intelligent robot, and improves the efficiency of log collection.
Further, on the basis of above method embodiment, S102 further comprises:
According to stl status and fault restoration state, determine that target application services the output stage of corresponding log collection
Not.
Specifically, the stl status refers to the current mode of operation of log, for example whether updating;The failure is repaired
Multiple state refers to the state after the application program of log recording breaks down, for example whether having repaired.
When log is in more new state, rank can be output it and be set as lower rank, to prevent log renewal process
The infull problem of data caused by middle upload log.
It is repaired after the application program of log recording breaks down, then it can set the log to secondary high-level, with
Upload server as early as possible;It is not repaired after the application program of log recording breaks down, then can set the log to highest
Not, with timely upload server.
Further, on the basis of above method embodiment, S104 further comprises:
Fragment receives the correspondence log of the default output level for the target application service that the terminal is sent.
Using log allocation methods, the success rate of log upload can be improved, reduce bandwidth consumption, while reducing network biography
Defeated pressure.
Specifically, fragment uploads again after intelligent robot is compressible when log uploads.
Further, on the basis of above method embodiment, as shown in Figure 2, which comprises
S201, judge whether to be collected the correspondence log of terminal applies service;
S202, it is if desired collected, it is determined that the target application service being collected respectively corresponds the defeated of log collection
Rank out;
S203, it is sent to terminal and collects the corresponding log collection instruction of default output level;
S204, receive respectively the target application service that the terminal is sent the default output level correspondence day
Will.
S205, according to default file address, the corresponding log of the default output level is stored to the default file
In.
Wherein, the S101-S104 in S201-S204 embodiment corresponding with Fig. 1 is corresponding.
The default file address can be preset according to the specific requirement of user.
Specifically, by setting thread pool and file security lock control in S205, guarantee that file is correct, safe and efficient
It is written in default file.
Further, on the basis of above method embodiment, as shown in Figure 3, which comprises
S301, judge whether to be collected the correspondence log of terminal applies service;
S402, it is if desired collected, it is determined that the target application service being collected respectively corresponds the defeated of log collection
Rank out;
S303, it is sent to terminal and collects the corresponding log collection instruction of default output level;
S304, receive respectively the target application service that the terminal is sent the default output level correspondence day
Will.
S305, according to default file address, the corresponding log of the default output level is stored to the default file
In.
S306, the log stored in the default file is analyzed, generate analysis result and shown.
Wherein, the S201-S205 in S301-S205 embodiment corresponding with Fig. 2 is corresponding.
Specifically, in S306 pass through server analysis, different error codes can be generated, and make mark, for
Family is in the clearly set of the preview data from the background.
For example, problem identification may include: and not solve, unimportant, solve, and can not currently solve, Retarded Solution
Certainly, special treatment.
By analyzing log, complete and intuitive functional diagnosis can be generated as a result, can be by for developer
It need to carry out the management of response application service.
The present embodiment carries out segregation of duties to whole structural framing, using dynamical fashion control log 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 is reported to server when having detected abnormality, then server actively starts to count terminal exception accordingly
The corresponding abnormal log of module, and abnormal log is uniformly forwarded to log server generation error code, function is carried out for developer
It can diagnosis.
The Logcat command set of google android system can be used in the present embodiment, by combining java thread pond, more
Threading, multi-process file security Writing Technology, file fragmentation and synthetic technology make calling program log collection and upload shape
At a perfect closed loop, there is information to collect, and complete, program is stable, performance consumption is low and the advantage of smartphone, and
And also support response remote collection instruction, with high security, scalability is strong, the simple advantage of operability and technique extension, with
And the progressive meaning constantly brought forth new ideas.
Fig. 4 shows a kind of structural schematic diagram of log collection device of one embodiment of the invention offer, described device packet
It includes: log collection determining module 41, output level determining module 42, instruction sending module 43 and log receiving module 44;Wherein,
The log collection determining module 41 is for judging whether to be collected the correspondence log of terminal applies service;
If desired the output level determining module 42 is for being collected, it is determined that the target application service being collected
Respectively correspond the output level of log collection;
Described instruction sending module 43, which is used to send to terminal, collects the corresponding log collection instruction of default output level;
The log receiving module 44 is used to receive the described pre- of the target application service that the terminal is sent respectively
If the correspondence log of output level.
Specifically, the log collection determining module 41 judges whether to receive the correspondence log of terminal applies service
Collection;If desired the output level determining module 42 is collected, it is determined that the target application service being collected respectively corresponds
The output level of log collection;Described instruction sending module 43 is sent to terminal collects the default corresponding log collection of output level
Instruction;The log receiving module 44 receives the default output stage for the target application service that the terminal is sent respectively
Other corresponding log.
The present embodiment determines whether progress log collection by server judgement, can be realized the active collection of server,
It avoids log collection and triggers single problem;Different logs is collected by output level, be can satisfy user and is collected on demand
Requirement, while avoiding the infull problem of log collection.
Further, on the basis of above-mentioned apparatus embodiment, the log collection determining module 41 is further used for root
According to current time, current location, current network conditions and server memory situation, judge whether the application clothes installed to terminal
The correspondence log of business is collected.
Further, on the basis of above-mentioned apparatus embodiment, the output level determining module 42 is further used for root
According to stl status and fault restoration state, determine that target application services the output level of corresponding log collection.
Further, on the basis of above-mentioned apparatus embodiment, the log receiving module 44 is further used for fragment and connects
Receive the correspondence log of the default output level for the target application service that the terminal is sent.
Further, on the basis of above-mentioned apparatus embodiment, described device further include:
Memory module 45, for according to default file address, the corresponding log of the output level to be stored to described pre-
If in file.
Further, on the basis of above-mentioned apparatus embodiment, described device further include:
Log analysis module 46 generates analysis result simultaneously for analyzing the log stored in the default file
Display.
Log collection device described in the present embodiment can be used for executing above method embodiment, principle and technical effect
Similar, details are not described herein again.
The apparatus embodiments described above are merely exemplary, wherein described, unit can as illustrated by the separation member
It is physically separated with being or may not be, component shown as a unit may or may not be physics list
Member, it can it is in one place, or may be distributed over multiple network units.It can be selected according to the actual needs
In some or all of the modules achieve the purpose of the solution of this embodiment.Those of ordinary skill in the art are not paying creativeness
Labour in the case where, it can understand and implement.
Through the above description of the embodiments, those skilled in the art can be understood that each embodiment can
It realizes by means of software and necessary general hardware platform, naturally it is also possible to pass through hardware.Based on this understanding, on
Stating technical solution, substantially the part that contributes to existing technology can be embodied in the form of software products in other words, should
Computer software product may be stored in a computer readable storage medium, such as ROM/RAM, magnetic disk, CD, including several fingers
It enables and using so that a computer equipment (can be personal computer, server or the network equipment etc.) executes each implementation
Method described in certain parts of example or embodiment.
It is noted that the above embodiments are merely illustrative of the technical solutions of the present invention, rather than its limitations;Although reference
Invention is explained in detail for previous embodiment, those skilled in the art should understand that: it still can be right
Technical solution documented by foregoing embodiments is modified or equivalent replacement of some of the technical features;And this
It modifies or replaces, the spirit and model of technical solution of various embodiments of the present invention that it does not separate the essence of the corresponding technical solution
It encloses.