1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.bugreport.logcat;
18 
19 import java.util.ArrayList;
20 import java.util.GregorianCalendar;
21 import java.util.Set;
22 
23 /**
24  * Class to represent an android log.
25  */
26 public class Logcat {
27     /**
28      * The lines contained in this logcat.
29      */
30     public ArrayList<LogLine> lines = new ArrayList<LogLine>();
31 
32     /**
33      * Return the lines that match the given log tags and optional log level.
34      */
filter(Set<String> tags, String levels)35     public ArrayList<LogLine> filter(Set<String> tags, String levels) {
36         final ArrayList<LogLine> result = new ArrayList<LogLine>();
37         for (LogLine line: lines) {
38             if (tags.contains(line.tag) && (levels == null || levels.indexOf(line.level) >= 0)) {
39                 result.add(line);
40             }
41         }
42         return result;
43     }
44 
45     /**
46      * Return the lines that match the given log tag and optional log level.
47      */
filter(String tag, String levels)48     public ArrayList<LogLine> filter(String tag, String levels) {
49         final ArrayList<LogLine> result = new ArrayList<LogLine>();
50         for (LogLine line: lines) {
51             if (tag.equals(line.tag) && (levels == null || levels.indexOf(line.level) >= 0)) {
52                 result.add(line);
53             }
54         }
55         return result;
56     }
57 }
58