blob: d7d5cbc21cf421599f857742ec3f3bb57b2935e7 [file] [log] [blame]
Mike Frysinger5ed12ec2025-08-21 10:25:25 -04001# 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 Changf19b3102023-09-01 16:07:34 -070017from git_command import GetEventTargetPath
Mike Frysinger64477332023-08-21 21:20:32 -040018from git_command import RepoSourceVersion
Jason Changf19b3102023-09-01 16:07:34 -070019from git_trace2_event_log_base import BaseEventLog
Ian Kasprzak30bc3542020-12-23 10:08:20 -080020
21
Jason Changf19b3102023-09-01 16:07:34 -070022class EventLog(BaseEventLog):
Gavin Makea2e3302023-03-11 06:46:20 +000023 """Event log that records events that occurred during a repo invocation.
Ian Kasprzak30bc3542020-12-23 10:08:20 -080024
Gavin Makea2e3302023-03-11 06:46:20 +000025 Events are written to the log as a consecutive JSON entries, one per line.
26 Entries follow the git trace2 EVENT format.
Ian Kasprzak30bc3542020-12-23 10:08:20 -080027
Gavin Makea2e3302023-03-11 06:46:20 +000028 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 Kasprzak30bc3542020-12-23 10:08:20 -080034
Gavin Makea2e3302023-03-11 06:46:20 +000035 Valid 'event' names and event specific fields are documented here:
36 https://git-scm.com/docs/api-trace2#_event_format
Josh Steadmon244c9a72022-03-08 10:24:43 -080037 """
38
Jason Changf19b3102023-09-01 16:07:34 -070039 def __init__(self, **kwargs):
40 super().__init__(repo_source_version=RepoSourceVersion(), **kwargs)
Josh Steadmon244c9a72022-03-08 10:24:43 -080041
Jason Changf19b3102023-09-01 16:07:34 -070042 def Write(self, path=None, **kwargs):
Gavin Makea2e3302023-03-11 06:46:20 +000043 if path is None:
44 path = self._GetEventTargetPath()
Jason Changf19b3102023-09-01 16:07:34 -070045 return super().Write(path=path, **kwargs)
Gavin Makea2e3302023-03-11 06:46:20 +000046
Jason Changf19b3102023-09-01 16:07:34 -070047 def _GetEventTargetPath(self):
48 return GetEventTargetPath()