(log_code_lines, current_version)
| 88 | |
| 89 | |
| 90 | def extract_logs(log_code_lines, current_version): |
| 91 | global pattern_id |
| 92 | log_templates = set() |
| 93 | log_triggers = ([" log(", " LOG(", " LOGSOME", " warning()", |
| 94 | " error()", " out()", " problem()"]) |
| 95 | |
| 96 | for filename in source_files(mongodb_path): |
| 97 | f = open(filename, 'rb') |
| 98 | |
| 99 | # remove parent path |
| 100 | filename = filename[len(mongodb_path):] |
| 101 | |
| 102 | lines = f.readlines() |
| 103 | for lineno, line in enumerate(lines): |
| 104 | trigger = next((t for t in log_triggers if t in line), None) |
| 105 | |
| 106 | if trigger: |
| 107 | # extend line to wrap over line breaks until ; at end of line |
| 108 | # is encountered |
| 109 | statement = line |
| 110 | current_lineno = lineno |
| 111 | |
| 112 | semicolon_match = None |
| 113 | while not semicolon_match: |
| 114 | current_lineno += 1 |
| 115 | if current_lineno >= len(lines): |
| 116 | break |
| 117 | statement += lines[current_lineno] |
| 118 | # match semicolon at end of line |
| 119 | # (potentially with whitespace between) |
| 120 | semicolon_match = re.search(';\s*$', statement, |
| 121 | flags=re.MULTILINE) |
| 122 | if semicolon_match: |
| 123 | statement = statement[:semicolon_match.start()] |
| 124 | break |
| 125 | |
| 126 | # exclude triggers in comments (both // and /* */) |
| 127 | trigger_pos = statement.find(trigger) |
| 128 | newline_pos = statement.rfind("\n", 0, trigger_pos) |
| 129 | if statement.find("//", newline_pos + 1, trigger_pos) != -1: |
| 130 | # output_verbose(current_version, filename, lineno, |
| 131 | # line, statement, "comment //") |
| 132 | continue |
| 133 | comment_pos = statement.find("/*", 0, trigger_pos) |
| 134 | if comment_pos != -1: |
| 135 | if statement.find("*/", comment_pos + 2, |
| 136 | trigger_pos) == -1: |
| 137 | # output_verbose(current_version, filename, lineno, |
| 138 | # line, statement, "comment /* */") |
| 139 | continue |
| 140 | |
| 141 | statement = statement[statement.find(trigger) + |
| 142 | len(trigger):].strip() |
| 143 | |
| 144 | # unescape strings |
| 145 | # statement = statement.decode("string-escape") |
| 146 | # print(statement) |
| 147 |
no test coverage detected