CN107463485B - Method stack-based log acquisition method and device and terminal - Google Patents

Method stack-based log acquisition method and device and terminal Download PDF

Info

Publication number
CN107463485B
CN107463485B CN201710496952.0A CN201710496952A CN107463485B CN 107463485 B CN107463485 B CN 107463485B CN 201710496952 A CN201710496952 A CN 201710496952A CN 107463485 B CN107463485 B CN 107463485B
Authority
CN
China
Prior art keywords
log
parameter
target information
output
program statement
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201710496952.0A
Other languages
Chinese (zh)
Other versions
CN107463485A (en
Inventor
孟敬楠
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing 58 Information Technology Co Ltd
Original Assignee
Beijing 58 Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing 58 Information Technology Co Ltd filed Critical Beijing 58 Information Technology Co Ltd
Priority to CN201710496952.0A priority Critical patent/CN107463485B/en
Publication of CN107463485A publication Critical patent/CN107463485A/en
Application granted granted Critical
Publication of CN107463485B publication Critical patent/CN107463485B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/30Monitoring
    • G06F11/34Recording or statistical evaluation of computer activity, e.g. of down time, of input/output operation ; Recording or statistical evaluation of user activity, e.g. usability assessment
    • G06F11/3466Performance evaluation by tracing or monitoring
    • G06F11/3471Address tracing
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/362Software debugging
    • G06F11/3636Software debugging by tracing the execution of the program

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The invention provides a method stack-based log acquisition method, a device and a terminal. The log obtaining method based on the method stack comprises the following steps: acquiring at least one parameter in a program statement of a log to be output; acquiring the name of a Java file in which a program statement is located and the line number of the program statement in the Java file at a preset position of a method stack corresponding to an application program; obtaining target information containing each parameter according to each parameter in the obtained program statement of the log to be output; and obtaining a target log corresponding to the program statement according to the target information, the name and the line number of the Java file. According to the log obtaining method, device and terminal based on the method stack, the speed of searching program statements corresponding to the log by a user is increased, and therefore the speed of searching error codes in the source codes is increased.

Description

Method stack-based log acquisition method and device and terminal
Technical Field
The invention relates to a software engineering technology, in particular to a method stack-based log acquisition method, a device and a terminal.
Background
With the rapid development of mobile phone applications, the functions of mobile phone Application programs (APPs) are increasing continuously, the Android project engineering is getting bigger and bigger, and meanwhile, APP developers are increasing year by year. Therefore, development efficiency is becoming a considerable problem. The Log is extremely important debugging information for developers, and a Log can be output for each program statement of the source code of the application program, so that finding the problem of the source code according to parameters in the Log has important significance for developing the application program.
When a log is obtained in the prior art, different marks are set for different Java files, the marks appear in the content of the output log, and the Java files to which program statements corresponding to the log belong can be quickly known by checking the log. However, when seeking to search for a program statement for which the log is specific according to the content of the log, a user needs to manually search for the program statement in a Java file corresponding to a mark in the log according to a parameter in the log; in addition, the method needs to add a unique mark for each Java file when the log is output, and the process is complicated. Therefore, when the log is obtained according to the method in the prior art and the program statement corresponding to the log is searched, the process is complicated, the searching efficiency is low, and the development efficiency is influenced.
Invention information
The invention provides a method stack-based log obtaining method, a device and a terminal, which aim to solve the technical problems of complex process and low efficiency when a log searches program statements aimed at by the log in the prior art.
The invention provides a method stack-based log acquisition method, which comprises the following steps:
acquiring at least one parameter in a program statement of a log to be output;
acquiring the name of a Java file in which the program statement is located and the line number of the program statement in the Java file at a preset position of a method stack corresponding to the application program;
obtaining target information containing each parameter according to each parameter;
and obtaining a target log corresponding to the program statement of the log to be output according to the target information, the name of the Java file and the line number.
The method as described above, after obtaining at least one parameter in a program statement of a log to be output, further includes:
and storing each parameter into a memory of the terminal.
The method for obtaining target information according to the at least one parameter includes:
and splicing the parameters by creating a character string construction object to obtain target information containing the parameters.
The method for splicing the parameters by creating a character string building object to obtain target information containing the parameters includes:
creating a character string construction object;
constructing an object by the character string and taking a first parameter as 1 st pre-fetching target information; the first parameter is a first parameter obtained from a memory, and the first parameter is a parameter of the at least one parameter;
judging whether the number of the parameters included in the 1 st prefetching target information is equal to the total number of the parameters;
if yes, taking the 1 st prefetching target information as the target information;
if not, adding a second parameter to the 1 st pre-fetching target information through the character string construction object to obtain 2 nd pre-fetching target information; the second parameter is two parameters obtained from the memory, and the second parameter is a parameter in the at least one parameter;
and repeatedly executing the process of comparing the number of the parameters included in the prefetch target information with the total number until the number of the parameters included in the prefetch target information is equal to the total number, and taking the corresponding prefetch target information as the target information.
The method as described above, further comprising: after obtaining the target log corresponding to the program statement according to the target information, the name of the Java file, and the line number, the method further includes:
and establishing a hyperlink between the name and the line number of the Java file in the target log and the program statement of the log to be output so that a user can input a viewing instruction through the name and the line number of the Java file, wherein the viewing instruction is used for instructing a terminal to acquire the program statement of the log to be output and display the program statement of the log to be output.
The method as described above, before the obtaining at least one parameter in the program statement of the log to be output, further includes:
and judging whether the running environment of the application program is a test environment or not, wherein the obtained judgment result is yes.
The invention also provides a log acquisition device based on the method stack, which comprises the following steps:
the parameter acquisition module is used for acquiring at least one parameter in a program statement of the log to be output;
the position information acquisition module is used for acquiring the name of a Java file in which the program statement is located and the line number of the program statement in the Java file at a preset position of a method stack corresponding to the application program;
the target information acquisition module is used for acquiring target information containing each parameter according to each parameter;
and the target log obtaining module is used for obtaining a target log corresponding to the program statement of the log to be output according to the target information, the name of the Java file and the line number.
In the above apparatus, the target information obtaining module is specifically configured to:
creating a character string construction object;
constructing an object by the character string and taking a first parameter as 1 st pre-fetching target information; the first parameter is a first parameter obtained from a memory, and the first parameter is a parameter of the at least one parameter;
judging whether the number of the parameters included in the 1 st prefetching target information is equal to the total number of the parameters;
if yes, taking the 1 st prefetching target information as the target information;
if not, adding a second parameter to the 1 st pre-fetching target information through the character string construction object to obtain 2 nd pre-fetching target information; the second parameter is two parameters obtained from the memory, and the second parameter is a parameter in the at least one parameter;
and repeatedly executing the process of comparing the number of the parameters included in the prefetch target information with the total number until the number of the parameters included in the prefetch target information is equal to the total number, and taking the corresponding prefetch target information as the target information.
The apparatus as described above, further comprising: a hyperlink establishing module;
the hyperlink establishing module is used for establishing a hyperlink between the name and the line number of the Java file in the target log and the program statement of the log to be output so that a user can input a viewing instruction through the name and the line number of the Java file, and the viewing instruction is used for indicating a terminal to acquire the program statement of the log to be output and display the program statement of the log to be output.
The invention also provides a terminal which comprises the log acquisition device based on the method stack.
The log obtaining method based on the method stack can comprise the following steps: acquiring at least one parameter in a program statement of a log to be output; acquiring the name of a Java file in which a program statement is located and the line number of the program statement in the Java file at a preset position of a method stack corresponding to an application program; obtaining target information containing each parameter according to each parameter in the obtained program statement of the log to be output; and obtaining a target log corresponding to the program statement according to the target information, the name and the line number of the Java file. The user can quickly find the program statements corresponding to the logs through the logs obtained by the log obtaining method based on the method stack, so that the wrong codes in the source codes can be quickly found, and the development efficiency is high.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings needed to be used in the description of the embodiments or the prior art will be briefly introduced below, and it is obvious that the drawings in the following description are some embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to these drawings without creative efforts.
Fig. 1 is a first schematic flowchart of a method stack-based log obtaining method according to the present invention;
FIG. 2 is a schematic diagram of a method stack according to the present invention;
FIG. 3 is a second flowchart illustrating a method for acquiring logs based on a method stack according to the present invention;
fig. 4 is a schematic structural diagram of a first embodiment of a method stack-based log obtaining apparatus provided in the present invention;
fig. 5 is a schematic structural diagram of a second embodiment of a method stack-based log obtaining apparatus provided in the present invention;
fig. 6 is a schematic structural diagram of a terminal provided in the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, but not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Fig. 1 is a first schematic flowchart of a method for acquiring a log based on a method stack according to the present invention, as shown in fig. 1, the method of this embodiment may include:
s101, acquiring at least one parameter in a program statement of a log to be output;
step S102, acquiring the name of a Java file where a program statement is located and the line number of the program statement in the Java file at a preset position of a method stack corresponding to an application program;
step S103, obtaining target information containing each parameter according to each parameter in the acquired program statement of the log to be output;
and step S104, obtaining a target log corresponding to the program statement according to the target information, the name and the line number of the Java file.
Specifically, the execution body of the embodiment may be a terminal, and the terminal may be a computer, for example.
When a user develops an application program, the application program needs to be tested to determine whether the source code of the application program has a problem. Each program statement in the source code can output a log by adding a corresponding log output statement after the program statement in the source code. The log comprises parameters in the running process of corresponding program statements, and a user can judge whether the program statements are correctly executed through the parameters in the log so as to judge whether the source codes of the application programs have problems.
It should be understood by those skilled in the art that, although each program statement may output a log by adding a corresponding log output statement after the program statement in the source code, according to the actual situation, not every program statement needs to output a log, so that only the program statement that needs to output a log is provided with a corresponding log output statement, and therefore, the program statement that is provided with the log output statement later is the program statement that is to output a log.
Those skilled in the art will appreciate that the log output statement may be multi-line code.
If the current running environment of the application program is a test environment (namely the environment for debugging the application program) and is not running at the terminal of a user who is not a developer, the user assigns the variable in the control log output condition statement in the source code to the future so that the program statement of the log to be output can output the corresponding log through the log output statement. I.e. assignment of variables in the control log output conditional statement, determines whether to output a log of program statements with log output statements.
Therefore, the process of determining the current operating environment of the application program specifically includes: in the running process of the application program, the terminal obtains the current assignment of the variable in the control log output condition statement in the source code, if the current assignment is the first assignment, the current running environment is determined to be the test environment, and if the current assignment is the second assignment, the current environment is determined to be the non-test environment. The first assignment is used to indicate that the current environment is a test environment and the second assignment is used to indicate that the current operating environment is determined to be a non-test environment.
After the current running environment of the application program is determined to be the test environment, the log of the program statement of the log to be output can be obtained.
The following describes a log output method of a program statement of a log to be output.
For step S101, at least one parameter in a program statement of a log to be output is acquired.
Specifically, the parameters in the obtained program statements of the log to be output need to satisfy the following conditions: whether the program statement of the log to be output is executed correctly or not can be reflected. And storing at least one parameter in the acquired program statement for acquiring the log to be output into a memory of the terminal.
At least one parameter in a program statement of a log to be output can be acquired in a self-defined static variable mode, namely, each parameter can be acquired by executing a static variable self-defined statement of an application program source code including an identifier of at least one parameter. For example: the code corresponding to obtaining at least one parameter in a program statement of the log to be output may be in the form of:
private static void k (string.. args), such as when the identity of a parameter in the program statement to be logged output is a, b, then the code may be: private static void k (a, b).
Wherein the code is one line of code in the log output statement. In this embodiment, a form of self-defining the number of parameters (i.e., through a self-defining static variable statement) is adopted, and any number of parameters are allowed to be acquired.
For step S102, the name of the Java file where the program statement of the log to be output is located and the line number of the program statement of the log to be output in the Java file are obtained at the preset position of the method stack corresponding to the application program.
Specifically, the preset position may be pre-stored in the terminal, and the name of the Java file where the obtained program statement of the log to be output is located and the line number of the program statement of the log to be output in the Java file are also stored in the memory of the terminal.
The method stack is a stack structure and is used for storing calling information of a method when an application program is executed, wherein the calling information comprises a method name of a calling method, a Java file name of a program statement calling the method, a line number of the program statement in the Java file and other information.
For example, in the running process of an application program, when the program statement of the log to be output is run, the program statement of the log to be output is executed, and an execution method needs to be called when the program statement of the log to be output is executed, then the calling information of the execution method is stored in a preset position in a method stack corresponding to the application program, and a method name of the execution method, a Java file name where the program statement of the log to be output is located, and a row number of the program statement of the log to be output in the Java file are stored in the preset position.
And storing the calling information of the execution methods of all program statements of the log to be output in the source code at the same position of the method stack corresponding to the application program. So for any program statement in the source code of the application that is to be logged for output: the name of the Java file where the method stack is located and the line number of the program statement of the log to be output in the Java file can be obtained at the same position of the method stack.
For example, the name of the Java file where the program statement of the log to be output is obtained at the preset position of the method stack corresponding to the application program, and the code corresponding to the line number of the program statement of the log to be output in the Java file may be in the following form:
Stack Trace Element this Method Stack=Thread.current Thread().get Stack Trace()[5];
thus, the Java file name and the line number can be obtained through the StackTraceElement, wherein the number 5 is used for indicating that the Java file name and the line number are obtained from the 5 th position away from the stack top.
In addition, in addition to the name of the Java file where the program statement of the log to be output is located and the line number of the program statement of the log to be output in the Java file, the name of the method called by executing the program statement of the log to be output may also be obtained at a preset position of the method stack corresponding to the application program.
For step S103, according to each parameter in the acquired program statement of the log to be output, target information including each parameter is obtained.
Specifically, the step is a process of splicing each parameter in the acquired program statement of the log to be output to obtain target information including each parameter.
The obtaining of target information including each parameter according to each parameter in the obtained program statement of the log to be output specifically includes: and splicing the parameters by creating a character string construction object to obtain target information containing the parameters.
Since at least one parameter in the program sentence of the log to be output is obtained in advance through the custom static variable, in this embodiment, only one string building object needs to be created to splice the parameters, the consumption of the memory and the performance of the terminal is relatively small, and the formats of the parameters after splicing are consistent, for example, the parameter a is 1, the parameter b is 1, the parameter c is 2, the parameter a may be 1, the parameter b may be 1, the parameter c may be 2, or the parameter a may be 1| b | c | -2, and the format of the target information may be a ═ 1, b ═ 1, c ═ 2, or a 1| b | c | 2.
The method for acquiring the target information in this embodiment does not have the problem that in the prior art, because the parameters of the program statements of the log to be output are not acquired in advance, the memory and the performance of the terminal are greatly consumed because the parameters can only be spliced in the + mode (multiple character string building objects need to be created when splicing is performed in the + mode).
For step S104, after obtaining the target information, the name of the Java file where the program statement of the log to be output is located, and the line number of the program statement of the log to be output in the Java file, the log of the program statement of the log to be output is obtained according to the target information, the name of the Java file where the program statement of the log to be output is located, and the line number of the program statement of the log to be output in the Java file.
Specifically, "obtaining the log of the program statement of the log to be output according to the target information, the name of the Java file where the program statement of the log to be output is located, and the line number of the program statement of the log to be output in the Java file" means "splicing at least the target information corresponding to the program statement of the log to be output, the name of the Java file where the program statement of the log to be output is located, and the line number of the program statement of the log to be output in the Java file" to obtain the target log.
If the method name of the method called when the program statement of the log to be output is executed is acquired in step S102, the method name is also included in the log.
Wherein, the output log can be in the following form:
first log: 11-1816: 36:39: 4973729-3729/com.example.mjn.myapplication D/onCreate (MainActivity, java:19): version 2.5;
the MainActivity is the name of a java file where the program statement of the log is to be output, java:19 is a row number, and version ═ 2.5 is a parameter in the program statement of the log to be output, namely the target information. onCreate is the method name of the method called by the program statement executing the log to be output.
And a second log: 11-1816: 36:39: 5903729-3729/com. example. mjn. myapplication D/onCreate (Activity, java:16): value ═ 1, };
activity is the name of a java file where the program statement of the log to be output is located, java:16 is a line number, and value 1 is a parameter in the program statement of the log to be output, namely target information.
And (3) log three: 11-1816: 36:39: 5923729-3729/com. example. mjn. vitality. java. 17 { index ═ 5, number ═ 6, };
activity is the name of a java file where the program statement of the log to be output is located, java:17 is a row number, index is 5, and number is 6, which is the parameter in the program statement of the log to be output, and is the target information.
The output log comprises target information, the name of the Java file where the program statement of the log to be output is located and the line number of the program statement of the log to be output in the Java file. Therefore, after seeing the log, the user can immediately know that the log is the log corresponding to the program statement of which line in which Java file, so as to quickly find the program statement. For example, by looking up parameters in the log, it is found that the program statement corresponding to the log is not executed correctly, and then the user can know the position of the program statement (the Java file where the program statement is located and the line number of the Java file) according to the content of the log, so as to quickly find the program statement in the position, determine the problem of the program statement, and then solve the problem. That is, the user can quickly find the program statement corresponding to the log according to the log obtained in this embodiment, so that the wrong code in the source code can be quickly found, and the development efficiency is high.
After the target log is obtained, establishing a hyperlink between the name and the line number of the Java file in the target log and the program statement of the log to be output, so that a user can input a viewing instruction through the name and the line number of the Java file, and the viewing instruction is used for instructing a terminal to acquire the program statement of the log to be output and display the program statement of the log to be output.
For example, when the user clicks MainActivity, java, 19 in the log I, the terminal can display the program statement of the log to be output corresponding to the log to the user. The speed of searching the program statement of the log to be output corresponding to the log is further improved.
After the description of the method stack-based log obtaining method in this embodiment is completed, the method stack related to this embodiment is described in detail below.
For each method invoked by the application's code, the data associated with that method is pushed onto the method stack. The distance from the relevant data of the called method to the top of the stack is larger than the distance from the relevant data of the called method to the top of the stack.
Fig. 2 is a schematic structural diagram of a method stack provided in the present invention.
For the method for obtaining a log based on a method stack in this embodiment, before obtaining the log, the program statement of the log to be output is executed first, so that the method name of the method called when executing the program statement of the log to be output, the Java file name where the program statement of the log to be output calling the method is located, and information such as the line number of the program statement of the log to be output in the Java file are pushed into the first position 21 of the corresponding method stack.
Then, at least one parameter in the program statement of the log to be output is obtained, where the obtained method is a user-defined method, and information such as the method name of the user-defined method, the Java file name of the code (private static void k (string.. args)) calling the user-defined method, and the line number of the code in the Java file is pushed to the second position 22 of the corresponding method stack.
Then, the name of the Java file where the program statement of the log to be output is obtained at the preset position of the method stack corresponding to the application program and the line number of the program statement of the log to be output in the Java file are obtained, the method called by obtaining the name and the line number may be called as an obtaining method stack method, and information such as the method name of the obtaining method stack method, the Java file name of the code calling the method, and the line number of the code in the Java file are pushed into the third position 23 of the corresponding method stack.
Then, obtaining target information containing each parameter according to each parameter in the obtained program statement of the log to be output, and a method called by splicing each parameter to obtain the target information can be called as a parameter splicing method; the method name of the splicing parameter method, the name of the Java file where the code calling the method is located, and the line number of the code in the Java file, etc. are pushed to the fourth location 24 of the corresponding method stack.
And finally, obtaining the log of the program statement of the log to be output according to the target information, the name of the Java file where the program statement of the log to be output is located and the line number of the program statement of the log to be output in the Java file, wherein the method called by the process can be called as a log output method. The method name of the log output method, the name of the Java file where the code calling the method is located, and the line number of the code in the Java file are pushed to the fifth location 25 of the corresponding method stack.
By using the characteristics of the method stack, the name of the Java file where the program statement of the log to be output is located and the line number of the program statement of the log to be output in the Java file are obtained at the preset position of the method stack, and the information is used as a part of the content in the log, so that the user can know the position of the program statement corresponding to the log by looking up the log, and the quick positioning of the program statement corresponding to the log is realized.
The method for acquiring the log based on the method stack in the embodiment may include: acquiring at least one parameter in a program statement of a log to be output; acquiring the name of a Java file in which a program statement is located and the line number of the program statement in the Java file at a preset position of a method stack corresponding to an application program; obtaining target information containing each parameter according to each parameter in the obtained program statement of the log to be output; and obtaining a target log corresponding to the program statement according to the target information, the name and the line number of the Java file. According to the log obtaining method based on the method stack, the speed of searching program statements corresponding to the log by a user is increased, so that the speed of searching wrong codes in the source codes is increased, and finally the development efficiency is increased.
A detailed description is given below by using a specific embodiment on the step "splicing each parameter by creating a character string construction object to obtain target information including each parameter" in the previous embodiment.
Fig. 3 is a second schematic flowchart of a method for acquiring a log based on a method stack according to the present invention, and as shown in fig. 3, the method of this embodiment may include:
s301, creating a character string building object;
step S302, constructing an object through a character string and taking a first parameter as the 1 st pre-fetching target information; the first parameter is a first parameter obtained from a memory, and the first parameter is a parameter in the obtained log statement to be output;
step S303, judging whether the number of the parameters included in the 1 st prefetching target information is equal to the total number of the parameters in the acquired to-be-output log statement; if yes, go to step S304, if no, go to step S305E
Step S304, the 1 st prefetching target information is used as the target information;
step S305, adding a second parameter to the 1 st pre-fetching target information through a character string construction object to obtain 2 nd pre-fetching target information; the second parameter is two parameters obtained from the memory, and the second parameter is the obtained parameter in the log statement to be output;
step S306, repeatedly executing the process of comparing the number of parameters included in the prefetch target information with the total number of parameters in the acquired to-be-output log statement until the number of parameters included in the prefetch target information is equal to the total number of parameters in the acquired to-be-output log statement, and taking the corresponding prefetch target information as the target information.
Specifically, the code corresponding to steps S301 to S306 may be in the form of:
Figure BDA0001331934370000111
the parameters of the program statements of the log to be output, which are obtained through the custom variables, are stored in the memory after being obtained, when the parameters are used as the content of the log, the parameters need to be read from the memory, and then the target information including the parameters is obtained through splicing the character string construction objects together.
Firstly, a first parameter-a first parameter acquired from a memory forms 1 st prefetch target information through a character string construction object; and then judging whether the number of the parameters included in the 1 st pre-fetching target information is equal to the total number of the parameters in the acquired log statement to be output.
If not, acquiring a parameter, namely a second parameter, from the memory, and adding the second parameter to the 1 st pre-fetch target information through the character string construction object to obtain the 2 nd pre-fetch target information; and then judging whether the number of the parameters included in the 2 nd pre-fetching target information is equal to the total number of the parameters in the acquired log statement to be output.
If not, a parameter, namely a third parameter, is obtained from the memory, and the third parameter is added to the 2 nd pre-fetching target information through the character string construction object, so that the 3 rd pre-fetching target information is obtained.
Repeating the circulation process until the number of the parameters included in the pre-fetching target information is equal to the total number of the parameters in the acquired to-be-output log statement; the prefetch target information at this time is used as final target information.
According to the log obtaining method based on the method stack, the parameters are spliced through the character string construction object, so that the consumption of the memory and the performance of the terminal is relatively low, and the formats of the spliced parameters are consistent.
Fig. 4 is a schematic structural diagram of a first embodiment of a log obtaining apparatus based on a method stack provided in the present invention, and as shown in fig. 4, the apparatus of this embodiment may include: a parameter obtaining module 11, a position information obtaining module 12, a target information obtaining module 13 and a target log obtaining module 14.
The parameter obtaining module 11 is configured to obtain at least one parameter in a program statement of a log to be output;
a position information obtaining module 12, configured to obtain, at a preset position of a method stack corresponding to an application program, a name of a Java file in which a program statement is located and a line number of the program statement in the Java file;
a target information obtaining module 13, configured to obtain target information including each parameter according to each parameter;
and the target log obtaining module 14 is configured to obtain a target log corresponding to a program statement of the log to be output according to the target information, the name and the line number of the Java file.
The parameter obtaining module 11 is further configured to store each parameter of the obtained program statement of the log to be output in a memory of the terminal.
The target information obtaining module 13 is further specifically configured to: creating a character string construction object; constructing an object by using the character string and taking the first parameter as the 1 st pre-fetching target information; the first parameter is a first parameter obtained from a memory, and the first parameter is a parameter in a program statement of an obtained log to be output; judging whether the number of the parameters included in the 1 st pre-fetching target information is equal to the total number of the parameters in the acquired program statement of the log to be output or not; if yes, taking the 1 st pre-fetching target information as target information; if not, adding a second parameter to the 1 st pre-fetching target information through the character string construction object to obtain the 2 nd pre-fetching target information; the second parameter is two parameters obtained from the memory, and the second parameter is a parameter in the obtained program statement of the log to be output; and repeatedly executing the process of comparing the number of the parameters in the pre-fetching target information with the total number of the parameters in the acquired program statements of the log to be output until the number of the parameters in the pre-fetching target information is equal to the total number of the parameters in the acquired program statements of the log to be output, and taking the corresponding pre-fetching target information as target information.
The apparatus of this embodiment may be configured to implement the technical solutions of the above method embodiments, and the implementation principles and technical effects are similar, which are not described herein again.
Fig. 5 is a schematic structural diagram of a second embodiment of a log obtaining apparatus based on a method stack according to the present invention, and as shown in fig. 5, the apparatus of this embodiment may further include, on the basis of the apparatus structure shown in fig. 4: a judging module 15 and a hyperlink establishing module 16.
The judging module 15 is used for judging whether the running environment of the application program is a test environment.
And a hyperlink establishing module 16, configured to establish a hyperlink between the name and the line number of the Java file in the target log and the program statement of the log to be output, so that a user can input a viewing instruction through the name and the line number of the Java file, where the viewing instruction is used to instruct the terminal to obtain the program statement of the log to be output and display the program statement of the log to be output.
The apparatus of this embodiment may be used to implement the technical solution of the method embodiment shown in fig. 1, and the implementation principle and the technical effect are similar, which are not described herein again.
Fig. 6 is a schematic structural diagram of a terminal provided by the present invention, and as shown in fig. 6, a terminal 31 of this embodiment includes a method stack-based log obtaining device 32 shown in fig. 4 or fig. 5, and the method stack-based log obtaining device 32 may execute the technical solution of any one of the method embodiments in fig. 1 to fig. 3, which has similar implementation principles and technical effects and is not described herein again.
Those of ordinary skill in the art will understand that: all or a portion of the steps of implementing the above-described method embodiments may be performed by hardware associated with program instructions. The program may be stored in a computer-readable storage medium. When executed, the program performs steps comprising the method embodiments described above; and the aforementioned storage medium includes: various media that can store program codes, such as ROM, RAM, magnetic or optical disks.
Finally, it should be noted that: the above embodiments are only used to illustrate the technical solution of the present invention, and not to limit the same; while the invention has been described in detail and with reference to the foregoing embodiments, it will be understood by those skilled in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some or all of the technical features may be equivalently replaced; and the modifications or the substitutions do not make the essence of the corresponding technical solutions depart from the scope of the technical solutions of the embodiments of the present invention.

Claims (10)

1. A log obtaining method based on a method stack is characterized by comprising the following steps:
acquiring at least one parameter in a program statement of a log to be output;
acquiring the name of a Java file in which the program statement is located and the line number of the program statement in the Java file at a preset position of a method stack corresponding to an application program;
obtaining target information containing each parameter according to each parameter;
and obtaining a target log corresponding to the program statement of the log to be output according to the target information, the name of the Java file and the line number.
2. The method of claim 1, after obtaining at least one parameter in a program statement of the log to be output, further comprising:
and storing each parameter into a memory of the terminal.
3. The method of claim 2, wherein obtaining target information according to the at least one parameter comprises:
and splicing the parameters by creating a character string construction object to obtain target information containing the parameters.
4. The method of claim 3, wherein concatenating the parameters by creating a string building object to obtain target information including the parameters comprises:
creating a character string construction object;
constructing an object by the character string and taking a first parameter as 1 st pre-fetching target information; the first parameter is a first parameter obtained from a memory, and the first parameter is a parameter of the at least one parameter;
judging whether the number of the parameters included in the 1 st prefetching target information is equal to the total number of the parameters;
if yes, taking the 1 st prefetching target information as the target information;
if not, adding a second parameter to the 1 st pre-fetching target information through the character string construction object to obtain 2 nd pre-fetching target information; the second parameter is a second parameter obtained from the memory, and the second parameter is a parameter of the at least one parameter;
and repeatedly executing the process of comparing the number of the parameters included in the prefetch target information with the total number until the number of the parameters included in the prefetch target information is equal to the total number, and taking the corresponding prefetch target information as the target information.
5. The method of claim 1, further comprising: after obtaining the target log corresponding to the program statement according to the target information, the name of the Java file, and the line number, the method further includes:
and establishing a hyperlink between the name and the line number of the Java file in the target log and the program statement of the log to be output so that a user can input a viewing instruction through the name and the line number of the Java file, wherein the viewing instruction is used for instructing a terminal to acquire the program statement of the log to be output and display the program statement of the log to be output.
6. The method of claim 1, further comprising, prior to the obtaining at least one parameter in a program statement of a log to be output:
and judging whether the running environment of the application program is a test environment or not, wherein the obtained judgment result is yes.
7. A log obtaining device based on a method stack is characterized by comprising:
the parameter acquisition module is used for acquiring at least one parameter in a program statement of the log to be output;
the position information acquisition module is used for acquiring the name of a Java file in which the program statement is located and the line number of the program statement in the Java file at a preset position of a method stack corresponding to an application program;
the target information acquisition module is used for acquiring target information containing each parameter according to each parameter;
and the target log obtaining module is used for obtaining a target log corresponding to the program statement of the log to be output according to the target information, the name of the Java file and the line number.
8. The apparatus of claim 7, wherein the target information obtaining module is specifically configured to: creating a character string construction object;
constructing an object by the character string and taking a first parameter as 1 st pre-fetching target information; the first parameter is a first parameter obtained from a memory, and the first parameter is a parameter of the at least one parameter;
judging whether the number of the parameters included in the 1 st prefetching target information is equal to the total number of the parameters;
if yes, taking the 1 st prefetching target information as the target information;
if not, adding a second parameter to the 1 st pre-fetching target information through the character string construction object to obtain 2 nd pre-fetching target information; the second parameter is a second parameter obtained from the memory, and the second parameter is a parameter of the at least one parameter;
and repeatedly executing the process of comparing the number of the parameters included in the prefetch target information with the total number until the number of the parameters included in the prefetch target information is equal to the total number, and taking the corresponding prefetch target information as the target information.
9. The apparatus of claim 7, further comprising: a hyperlink establishing module;
the hyperlink establishing module is used for establishing a hyperlink between the name and the line number of the Java file in the target log and the program statement of the log to be output so that a user can input a viewing instruction through the name and the line number of the Java file, and the viewing instruction is used for indicating a terminal to acquire the program statement of the log to be output and display the program statement of the log to be output.
10. A terminal, characterized in that it comprises a method stack based log retrieving device according to any of claims 7 to 9.
CN201710496952.0A 2017-06-26 2017-06-26 Method stack-based log acquisition method and device and terminal Active CN107463485B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201710496952.0A CN107463485B (en) 2017-06-26 2017-06-26 Method stack-based log acquisition method and device and terminal

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201710496952.0A CN107463485B (en) 2017-06-26 2017-06-26 Method stack-based log acquisition method and device and terminal

Publications (2)

Publication Number Publication Date
CN107463485A CN107463485A (en) 2017-12-12
CN107463485B true CN107463485B (en) 2020-11-10

Family

ID=60546398

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201710496952.0A Active CN107463485B (en) 2017-06-26 2017-06-26 Method stack-based log acquisition method and device and terminal

Country Status (1)

Country Link
CN (1) CN107463485B (en)

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112612701B (en) * 2020-12-24 2024-02-23 北京浪潮数据技术有限公司 Program fault positioning method, device, equipment and readable storage medium
CN112882902B (en) * 2021-03-05 2023-02-14 深圳市迅雷网络技术有限公司 Thread source obtaining method, electronic equipment and computer readable storage device
CN113360357B (en) * 2021-06-01 2023-05-09 深圳前海微众银行股份有限公司 Data monitoring method, system and equipment
CN113377674B (en) * 2021-07-02 2024-03-08 北京奇艺世纪科技有限公司 Log code adding method and device

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102360328A (en) * 2011-09-29 2012-02-22 用友软件股份有限公司 Programmed monitoring device and programmed monitoring method
CN102782649A (en) * 2010-03-04 2012-11-14 日本电气株式会社 Application modification section search device and application modification section search method
CN104268055A (en) * 2014-09-01 2015-01-07 腾讯科技(深圳)有限公司 Program exception monitoring method and device
CN106201756A (en) * 2016-07-12 2016-12-07 努比亚技术有限公司 Log acquisition device, mobile terminal and method

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9442725B2 (en) * 2013-08-21 2016-09-13 Airwatch Llc Branch trace compression

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102782649A (en) * 2010-03-04 2012-11-14 日本电气株式会社 Application modification section search device and application modification section search method
CN102360328A (en) * 2011-09-29 2012-02-22 用友软件股份有限公司 Programmed monitoring device and programmed monitoring method
CN104268055A (en) * 2014-09-01 2015-01-07 腾讯科技(深圳)有限公司 Program exception monitoring method and device
CN106201756A (en) * 2016-07-12 2016-12-07 努比亚技术有限公司 Log acquisition device, mobile terminal and method

Also Published As

Publication number Publication date
CN107463485A (en) 2017-12-12

Similar Documents

Publication Publication Date Title
CN107463485B (en) Method stack-based log acquisition method and device and terminal
CN107506300B (en) User interface testing method, device, server and storage medium
CN107992307B (en) Function compiling method and device
CN108459964B (en) Test case selection method, device, equipment and computer readable storage medium
US9436449B1 (en) Scenario-based code trimming and code reduction
CN110221959B (en) Application program testing method, device and computer readable medium
CN111596863A (en) Data reading method, device and equipment and readable storage medium
CN111389014A (en) Game resource data monitoring method and device, computer equipment and storage medium
CN115686631B (en) Random instruction generation method and device based on knowledge base and storage medium
CN107643893B (en) Program detection method and device
CN108694049B (en) Method and equipment for updating software
CN115268879A (en) Code processing method and device, electronic equipment and storage medium
CN105550575A (en) Method and device for obtaining un-exported function address and data structure offset
KR20180129623A (en) Apparatus for statically analyzing assembly code including assoxiated multi files
CN107526966B (en) Composite stain propagation tracking method for Android platform
CN107562423B (en) UI page development method and device
CN114201382A (en) Test case generation method and device, storage medium and electronic equipment
CN109426546B (en) Application starting method and device, computer storage medium and equipment
US9436587B2 (en) Test context generation
CN114610516B (en) Application program repairing method and device, computer equipment and storage medium
CN111400245B (en) Art resource migration method and device
CN114741294A (en) Page debugging method, device, equipment and storage medium
US9182990B1 (en) Method and apparatus for detecting execution of unsupported instructions while testing multiversioned code
CN115599534A (en) Data competition detection method, system, cluster and medium
CN113703753A (en) Method and device for product development and product development system

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant