diff options
Diffstat (limited to 'git_trace2_event_log.py')
-rw-r--r-- | git_trace2_event_log.py | 45 |
1 files changed, 40 insertions, 5 deletions
diff --git a/git_trace2_event_log.py b/git_trace2_event_log.py index 8f12d1a9..0e5e9089 100644 --- a/git_trace2_event_log.py +++ b/git_trace2_event_log.py | |||
@@ -144,6 +144,19 @@ class EventLog(object): | |||
144 | command_event['subcommands'] = subcommands | 144 | command_event['subcommands'] = subcommands |
145 | self._log.append(command_event) | 145 | self._log.append(command_event) |
146 | 146 | ||
147 | def LogConfigEvents(self, config, event_dict_name): | ||
148 | """Append a |event_dict_name| event for each config key in |config|. | ||
149 | |||
150 | Args: | ||
151 | config: Configuration dictionary. | ||
152 | event_dict_name: Name of the event dictionary for items to be logged under. | ||
153 | """ | ||
154 | for param, value in config.items(): | ||
155 | event = self._CreateEventDict(event_dict_name) | ||
156 | event['param'] = param | ||
157 | event['value'] = value | ||
158 | self._log.append(event) | ||
159 | |||
147 | def DefParamRepoEvents(self, config): | 160 | def DefParamRepoEvents(self, config): |
148 | """Append a 'def_param' event for each repo.* config key to the current log. | 161 | """Append a 'def_param' event for each repo.* config key to the current log. |
149 | 162 | ||
@@ -152,12 +165,34 @@ class EventLog(object): | |||
152 | """ | 165 | """ |
153 | # Only output the repo.* config parameters. | 166 | # Only output the repo.* config parameters. |
154 | repo_config = {k: v for k, v in config.items() if k.startswith('repo.')} | 167 | repo_config = {k: v for k, v in config.items() if k.startswith('repo.')} |
168 | self.LogConfigEvents(repo_config, 'def_param') | ||
169 | |||
170 | def GetDataEventName(self, value): | ||
171 | """Returns 'data-json' if the value is an array else returns 'data'.""" | ||
172 | return 'data-json' if value[0] == '[' and value[-1] == ']' else 'data' | ||
155 | 173 | ||
156 | for param, value in repo_config.items(): | 174 | def LogDataConfigEvents(self, config, prefix): |
157 | def_param_event = self._CreateEventDict('def_param') | 175 | """Append a 'data' event for each config key/value in |config| to the current log. |
158 | def_param_event['param'] = param | 176 | |
159 | def_param_event['value'] = value | 177 | For each keyX and valueX of the config, "key" field of the event is '|prefix|/keyX' |
160 | self._log.append(def_param_event) | 178 | and the "value" of the "key" field is valueX. |
179 | |||
180 | Args: | ||
181 | config: Configuration dictionary. | ||
182 | prefix: Prefix for each key that is logged. | ||
183 | """ | ||
184 | for key, value in config.items(): | ||
185 | event = self._CreateEventDict(self.GetDataEventName(value)) | ||
186 | event['key'] = f'{prefix}/{key}' | ||
187 | event['value'] = value | ||
188 | self._log.append(event) | ||
189 | |||
190 | def ErrorEvent(self, msg, fmt): | ||
191 | """Append a 'error' event to the current log.""" | ||
192 | error_event = self._CreateEventDict('error') | ||
193 | error_event['msg'] = msg | ||
194 | error_event['fmt'] = fmt | ||
195 | self._log.append(error_event) | ||
161 | 196 | ||
162 | def _GetEventTargetPath(self): | 197 | def _GetEventTargetPath(self): |
163 | """Get the 'trace2.eventtarget' path from git configuration. | 198 | """Get the 'trace2.eventtarget' path from git configuration. |