| Mike Frysinger | 5ed12ec | 2025-08-21 10:25:25 -0400 | [diff] [blame] | 1 | # Copyright (C) 2020 The Android Open Source Project |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
| 15 | """Event logging in the git trace2 EVENT format.""" |
| 16 | |
| Jason Chang | f19b310 | 2023-09-01 16:07:34 -0700 | [diff] [blame] | 17 | from git_command import GetEventTargetPath |
| Mike Frysinger | 6447733 | 2023-08-21 21:20:32 -0400 | [diff] [blame] | 18 | from git_command import RepoSourceVersion |
| Jason Chang | f19b310 | 2023-09-01 16:07:34 -0700 | [diff] [blame] | 19 | from git_trace2_event_log_base import BaseEventLog |
| Ian Kasprzak | 30bc354 | 2020-12-23 10:08:20 -0800 | [diff] [blame] | 20 | |
| 21 | |
| Jason Chang | f19b310 | 2023-09-01 16:07:34 -0700 | [diff] [blame] | 22 | class EventLog(BaseEventLog): |
| Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 23 | """Event log that records events that occurred during a repo invocation. |
| Ian Kasprzak | 30bc354 | 2020-12-23 10:08:20 -0800 | [diff] [blame] | 24 | |
| Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 25 | Events are written to the log as a consecutive JSON entries, one per line. |
| 26 | Entries follow the git trace2 EVENT format. |
| Ian Kasprzak | 30bc354 | 2020-12-23 10:08:20 -0800 | [diff] [blame] | 27 | |
| Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 28 | Each entry contains the following common keys: |
| 29 | - event: The event name |
| 30 | - sid: session-id - Unique string to allow process instance to be |
| 31 | identified. |
| 32 | - thread: The thread name. |
| 33 | - time: is the UTC time of the event. |
| Ian Kasprzak | 30bc354 | 2020-12-23 10:08:20 -0800 | [diff] [blame] | 34 | |
| Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 35 | Valid 'event' names and event specific fields are documented here: |
| 36 | https://git-scm.com/docs/api-trace2#_event_format |
| Josh Steadmon | 244c9a7 | 2022-03-08 10:24:43 -0800 | [diff] [blame] | 37 | """ |
| 38 | |
| Jason Chang | f19b310 | 2023-09-01 16:07:34 -0700 | [diff] [blame] | 39 | def __init__(self, **kwargs): |
| 40 | super().__init__(repo_source_version=RepoSourceVersion(), **kwargs) |
| Josh Steadmon | 244c9a7 | 2022-03-08 10:24:43 -0800 | [diff] [blame] | 41 | |
| Jason Chang | f19b310 | 2023-09-01 16:07:34 -0700 | [diff] [blame] | 42 | def Write(self, path=None, **kwargs): |
| Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 43 | if path is None: |
| 44 | path = self._GetEventTargetPath() |
| Jason Chang | f19b310 | 2023-09-01 16:07:34 -0700 | [diff] [blame] | 45 | return super().Write(path=path, **kwargs) |
| Gavin Mak | ea2e330 | 2023-03-11 06:46:20 +0000 | [diff] [blame] | 46 | |
| Jason Chang | f19b310 | 2023-09-01 16:07:34 -0700 | [diff] [blame] | 47 | def _GetEventTargetPath(self): |
| 48 | return GetEventTargetPath() |