Commit 124374a 1 parent f39e919 commit 124374a Copy full SHA for 124374a
File tree 2 files changed +62
-0
lines changed
2 files changed +62
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Copyright 2023 Google LLC
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
+ # [START logging_list_logs]
16
+ from typing import List
17
+ from google .cloud import logging_v2
18
+
19
+
20
+ def list_logs (project_id : str ) -> List [str ]:
21
+ """Lists all logs in a project.
22
+
23
+ Args:
24
+ project_id: the ID of the project
25
+
26
+ Returns:
27
+ A list of log names.
28
+ """
29
+ client = logging_v2 .services .logging_service_v2 .LoggingServiceV2Client ()
30
+ request = logging_v2 .types .ListLogsRequest (
31
+ parent = f"projects/{ project_id } " ,
32
+ )
33
+
34
+ logs = client .list_logs (request = request )
35
+ for log in logs :
36
+ print (log )
37
+
38
+ return logs
39
+ # [END logging_list_logs]
Original file line number Diff line number Diff line change
1
+ # Copyright 2023 Google LLC
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
+ import list_logs
16
+ import os
17
+
18
+ PROJECT = os .environ ["GOOGLE_CLOUD_PROJECT" ]
19
+
20
+
21
+ def test_list_logs (capsys ):
22
+ logs = list_logs .list_logs (PROJECT )
23
+ assert "logs" in str (logs )
You can’t perform that action at this time.
0 commit comments