Recommending Log Placement Based on Code Vocabulary

Recommending Log Placement Based on Code Vocabulary

Recommending Log Placement Based on Code Vocabulary 1 2 3 Konstantinos Lyrakis , Jeanderson Candidoˆ , Maur´ıcio Aniche 1 TU Delft Abstract mostly concern how to create log statements, rather than defining where or what to log. As a result, developers need to Logging is a common practice of vital importance make their own decisions when it comes to logging and they that enables developers to collect runtime informa- have to rely on their experience and domain expertise to do tion from a system. This information is then used so. to monitor a system’s performance as it runs in pro- duction and to detect the cause of system failures. In this paper, we focus on the ”where to log” problem and Besides its importance, logging is still a manual propose a way to help developers to decide which parts of the and difficult process. Developers rely on their ex- source code need to be logged. Prior studies have proposed perience and domain expertise in order to decide different approaches in order to achieve this goal [6], [7], where to put log statements. In this paper, we tried which exploit the textual features of the source code among to automatically suggest log placement by treating others in order to suggest log placement. code as plain text that is derived from a vocabu- This research focuses solely on the value of textual lary. Intuitively, we believe that the Code Vocabu- features for recommending log placement at method level. lary can indicate whether a code snippet should be We treat the source code as plain text and consider each logged or not. In order to validate this hypothesis, method to be a separate document, which consists of words we trained machine learning models based solely that belong to a vocabulary. Intuitively, we assume that each on the Code Vocabulary in order to suggest log method’s vocabulary can be used to decide whether it should placement at method level. We also studied which be logged or not. We conjecture that some words from words of the Code Vocabulary are more important the vocabulary are more closely related to the logging of a when it comes to deciding where to put log state- method than others. Specifically, we focus on the following ments. We evaluated our experiments on three open research questions: source systems and we found that i) The Code Vo- cabulary is a great source of training data when it RQ1: What is the performance of a Machine Learning comes to suggesting log placement at method level, model based on Code Vocabulary for log placement at ii) Classifiers trained solely on Vocabulary data are method level? This is the main focus of the research. A hard to interpret as there are no words in the Code well performing classifier trained solely on Code Vocabulary Vocabulary significantly more valuable than others. would verify our assumption that Code Vocabulary can provide us with sufficient training data to recommend log placement. 1 Introduction Logging is a regular practice followed by software developers RQ2: What value do different words add to the classifier? in order to monitor the operation of deployed systems. Log By answering this question we can explain why a classifier statements are placed in the source code to provide informa- performs well or not by examining which words provide the tion about the state of a system as it runs in production. In most information. We could also detect patterns that lead case of a system failure, these log statements can be collected developers to decide which methods need to be logged or not. and analyzed in order to detect what caused a system to fail. Efficient and accurate analysis of log statements, depends RQ3: How does the size of a method affect the per- heavily on the quality of the log data. Therefore, it is of vi- formance of the trained classifier? tal importance that developers decide correctly on where and The long term goal of this research is to help developers what to log. However, it is not always feasible to know what make better logging decisions. Answering this question kind of data should be logged during development time. Log would help us decide what kind of tool we would be able placement is currently a manual process, which is not stan- to build for this purpose. For example, if a classifier can dardized in the industry. Although there are various blog accurately predict log placement regardless of the size of a posts about logging best practices [1], [2], [3],[4],[5], they method, we could implement a tool that suggests log place- ment in real time as the developer types the code of a method. simple functionalities (e.g. getters and setters). We decided to filter out these methods to avoid introducing bias to the Paper Organization Section 2 describes the methodology classifiers. Table 1 shows that even after filtering out the small that was followed in order to answer the research questions. methods, the number of logged methods remains the same, so Section 3 presents the results for each research question. Sec- the removed methods would not provide extra information to tion 4 discusses the ethical implications of this research. Sec- the classifiers, as they all belong to the ”not logged” class. tion 5 contains a discussion on the results and Section 6 sur- veys related work. Finally, Section 7 summarizes the paper, Methods Logged Filtered Filtered Logged provides the conclusions of the research and suggests ideas 38509 4040 15282 4040 for future work. Table 1: Number of Methods 2 Methodology This section describes the process that we followed to an- The second step of Data Cleaning was to remove the log swer the research questions mentioned in the introduction. statements from the Logged Methods. Because the goal of An overview of the methodology can be seen in Figure 1. this research is to recommend log placement, keeping the log Subsection 2.1 provides information about the studied sys- statements would provide the classifiers with information that tems. The processes described in subsection 2.2 and subsec- they would not have in a ”real” setting. tion 2.3 were followed for each system separately. Feature Extraction 2.1 Studied Systems In order to extract features from the collected methods, we used the Bag of Words model [14]. First, we tokenized the The systems that were studied during the research are Apache methods and created a vocabulary from the extracted tokens. CloudStack[8], Hadoop[9] and Airavata[10]. All the three Afterwards we removed the stop words from the vocabulary. systems are open source projects built in Java. They were For this research, the stop words constitute of Java’s key- selected because they are large systems with many years of words, as all the studied systems are Java projects. Finally, we development, so we assume that they follow good logging used TF.IDF [15] term weighting in order to vectorize each practices, therefore they constitute a valuable data source for method. All of these steps were performed using scikit-learn this research. [16]. 2.2 Creation of the dataset Balancing Data The dataset that was used in this paper was created from the The dataset that was created after the vectorization of the ex- source code files of the systems’ repositories. For the pur- tracted methods, contains very unbalanced data. 26.4% of poses of this research, only the source code files were used, the extracted methods were labeled as ”logged” and the rest because the test files are expected to have different logging were labeled as ”not logged”. This could negatively affect the strategies which would be associated with a different vocab- performance of the trained models, so we decided to balance ulary. the training data by oversampling the ”logged” class using the Synthetic Minority Over-sampling Technique (SMOTE) Method Extraction [17]. To do so, we employed the imbalanced [18] tool. The first step towards the creation of the dataset, is to extract the methods from the source code. In order to do so, the Java- 2.3 Model Training Parser [11] was employed. For each method, we collected its As mentioned before, this paper focuses on suggesting log statements and used CK [12] to count its Lines of Code. In placement based solely on textual features. As a result, we de- total, 38509 methods were collected, out of which 4040 were cided to treat log placement as a binary document classifica- logged. tion problem [19], where each method constitutes a document and can be classified as ”logged” or ”not logged”. We trained Labelling 5 different classifiers, namely Logistic Regression [20], Sup- A vital step of the data preparation, is to label the methods port Vector Machines (SVM) [21], Naive Bayes [22], De- that were collected. Each method was labeled as ”logged” cision Tree [23] and Random Forest [24]. These classifiers if it contained a log statement, otherwise it was labelled as were selected because they are known to perform well in this ”not logged”. A log statement is a statement that contains type of problem [25], [26], [27], [28], [29]. a method call to a logging library. All the studied systems use the log4j [13] framework, which defines 6 levels of log- 3 Results ging that correspond to similarly named methods: fatal, error, warning, info, debug, trace. So any statement that contains a This section describes how the results of the research were call to these methods is considered to be a log statement. evaluated and answers the questions posed in section 1. Data Cleaning 3.1 Evaluation The source code files, contain many methods that are very After creating the dataset, we employed scikit-learn to train small, consisting of less than 3 lines of code.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    12 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us