Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/google/cloud/logging_v2/types/logging.py: 94%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

68 statements  

1# -*- coding: utf-8 -*- 

2# Copyright 2025 Google LLC 

3# 

4# Licensed under the Apache License, Version 2.0 (the "License"); 

5# you may not use this file except in compliance with the License. 

6# You may obtain a copy of the License at 

7# 

8# http://www.apache.org/licenses/LICENSE-2.0 

9# 

10# Unless required by applicable law or agreed to in writing, software 

11# distributed under the License is distributed on an "AS IS" BASIS, 

12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

13# See the License for the specific language governing permissions and 

14# limitations under the License. 

15# 

16from __future__ import annotations 

17 

18from typing import MutableMapping, MutableSequence 

19 

20import proto # type: ignore 

21 

22from google.api import monitored_resource_pb2 # type: ignore 

23from google.cloud.logging_v2.types import log_entry 

24from google.protobuf import duration_pb2 # type: ignore 

25from google.rpc import status_pb2 # type: ignore 

26 

27 

28__protobuf__ = proto.module( 

29 package="google.logging.v2", 

30 manifest={ 

31 "DeleteLogRequest", 

32 "WriteLogEntriesRequest", 

33 "WriteLogEntriesResponse", 

34 "WriteLogEntriesPartialErrors", 

35 "ListLogEntriesRequest", 

36 "ListLogEntriesResponse", 

37 "ListMonitoredResourceDescriptorsRequest", 

38 "ListMonitoredResourceDescriptorsResponse", 

39 "ListLogsRequest", 

40 "ListLogsResponse", 

41 "TailLogEntriesRequest", 

42 "TailLogEntriesResponse", 

43 }, 

44) 

45 

46 

47class DeleteLogRequest(proto.Message): 

48 r"""The parameters to DeleteLog. 

49 

50 Attributes: 

51 log_name (str): 

52 Required. The resource name of the log to delete: 

53 

54 - ``projects/[PROJECT_ID]/logs/[LOG_ID]`` 

55 - ``organizations/[ORGANIZATION_ID]/logs/[LOG_ID]`` 

56 - ``billingAccounts/[BILLING_ACCOUNT_ID]/logs/[LOG_ID]`` 

57 - ``folders/[FOLDER_ID]/logs/[LOG_ID]`` 

58 

59 ``[LOG_ID]`` must be URL-encoded. For example, 

60 ``"projects/my-project-id/logs/syslog"``, 

61 ``"organizations/123/logs/cloudaudit.googleapis.com%2Factivity"``. 

62 

63 For more information about log names, see 

64 [LogEntry][google.logging.v2.LogEntry]. 

65 """ 

66 

67 log_name: str = proto.Field( 

68 proto.STRING, 

69 number=1, 

70 ) 

71 

72 

73class WriteLogEntriesRequest(proto.Message): 

74 r"""The parameters to WriteLogEntries. 

75 

76 Attributes: 

77 log_name (str): 

78 Optional. A default log resource name that is assigned to 

79 all log entries in ``entries`` that do not specify a value 

80 for ``log_name``: 

81 

82 - ``projects/[PROJECT_ID]/logs/[LOG_ID]`` 

83 - ``organizations/[ORGANIZATION_ID]/logs/[LOG_ID]`` 

84 - ``billingAccounts/[BILLING_ACCOUNT_ID]/logs/[LOG_ID]`` 

85 - ``folders/[FOLDER_ID]/logs/[LOG_ID]`` 

86 

87 ``[LOG_ID]`` must be URL-encoded. For example: 

88 

89 :: 

90 

91 "projects/my-project-id/logs/syslog" 

92 "organizations/123/logs/cloudaudit.googleapis.com%2Factivity" 

93 

94 The permission ``logging.logEntries.create`` is needed on 

95 each project, organization, billing account, or folder that 

96 is receiving new log entries, whether the resource is 

97 specified in ``logName`` or in an individual log entry. 

98 resource (google.api.monitored_resource_pb2.MonitoredResource): 

99 Optional. A default monitored resource object that is 

100 assigned to all log entries in ``entries`` that do not 

101 specify a value for ``resource``. Example: 

102 

103 :: 

104 

105 { "type": "gce_instance", 

106 "labels": { 

107 "zone": "us-central1-a", "instance_id": "00000000000000000000" }} 

108 

109 See [LogEntry][google.logging.v2.LogEntry]. 

110 labels (MutableMapping[str, str]): 

111 Optional. Default labels that are added to the ``labels`` 

112 field of all log entries in ``entries``. If a log entry 

113 already has a label with the same key as a label in this 

114 parameter, then the log entry's label is not changed. See 

115 [LogEntry][google.logging.v2.LogEntry]. 

116 entries (MutableSequence[google.cloud.logging_v2.types.LogEntry]): 

117 Required. The log entries to send to Logging. The order of 

118 log entries in this list does not matter. Values supplied in 

119 this method's ``log_name``, ``resource``, and ``labels`` 

120 fields are copied into those log entries in this list that 

121 do not include values for their corresponding fields. For 

122 more information, see the 

123 [LogEntry][google.logging.v2.LogEntry] type. 

124 

125 If the ``timestamp`` or ``insert_id`` fields are missing in 

126 log entries, then this method supplies the current time or a 

127 unique identifier, respectively. The supplied values are 

128 chosen so that, among the log entries that did not supply 

129 their own values, the entries earlier in the list will sort 

130 before the entries later in the list. See the 

131 ``entries.list`` method. 

132 

133 Log entries with timestamps that are more than the `logs 

134 retention 

135 period <https://cloud.google.com/logging/quotas>`__ in the 

136 past or more than 24 hours in the future will not be 

137 available when calling ``entries.list``. However, those log 

138 entries can still be `exported with 

139 LogSinks <https://cloud.google.com/logging/docs/api/tasks/exporting-logs>`__. 

140 

141 To improve throughput and to avoid exceeding the `quota 

142 limit <https://cloud.google.com/logging/quotas>`__ for calls 

143 to ``entries.write``, you should try to include several log 

144 entries in this list, rather than calling this method for 

145 each individual log entry. 

146 partial_success (bool): 

147 Optional. Whether a batch's valid entries should be written 

148 even if some other entry failed due to a permanent error 

149 such as INVALID_ARGUMENT or PERMISSION_DENIED. If any entry 

150 failed, then the response status is the response status of 

151 one of the failed entries. The response will include error 

152 details in ``WriteLogEntriesPartialErrors.log_entry_errors`` 

153 keyed by the entries' zero-based index in the ``entries``. 

154 Failed requests for which no entries are written will not 

155 include per-entry errors. 

156 dry_run (bool): 

157 Optional. If true, the request should expect 

158 normal response, but the entries won't be 

159 persisted nor exported. Useful for checking 

160 whether the logging API endpoints are working 

161 properly before sending valuable data. 

162 """ 

163 

164 log_name: str = proto.Field( 

165 proto.STRING, 

166 number=1, 

167 ) 

168 resource: monitored_resource_pb2.MonitoredResource = proto.Field( 

169 proto.MESSAGE, 

170 number=2, 

171 message=monitored_resource_pb2.MonitoredResource, 

172 ) 

173 labels: MutableMapping[str, str] = proto.MapField( 

174 proto.STRING, 

175 proto.STRING, 

176 number=3, 

177 ) 

178 entries: MutableSequence[log_entry.LogEntry] = proto.RepeatedField( 

179 proto.MESSAGE, 

180 number=4, 

181 message=log_entry.LogEntry, 

182 ) 

183 partial_success: bool = proto.Field( 

184 proto.BOOL, 

185 number=5, 

186 ) 

187 dry_run: bool = proto.Field( 

188 proto.BOOL, 

189 number=6, 

190 ) 

191 

192 

193class WriteLogEntriesResponse(proto.Message): 

194 r"""Result returned from WriteLogEntries.""" 

195 

196 

197class WriteLogEntriesPartialErrors(proto.Message): 

198 r"""Error details for WriteLogEntries with partial success. 

199 

200 Attributes: 

201 log_entry_errors (MutableMapping[int, google.rpc.status_pb2.Status]): 

202 When ``WriteLogEntriesRequest.partial_success`` is true, 

203 records the error status for entries that were not written 

204 due to a permanent error, keyed by the entry's zero-based 

205 index in ``WriteLogEntriesRequest.entries``. 

206 

207 Failed requests for which no entries are written will not 

208 include per-entry errors. 

209 """ 

210 

211 log_entry_errors: MutableMapping[int, status_pb2.Status] = proto.MapField( 

212 proto.INT32, 

213 proto.MESSAGE, 

214 number=1, 

215 message=status_pb2.Status, 

216 ) 

217 

218 

219class ListLogEntriesRequest(proto.Message): 

220 r"""The parameters to ``ListLogEntries``. 

221 

222 Attributes: 

223 resource_names (MutableSequence[str]): 

224 Required. Names of one or more parent resources from which 

225 to retrieve log entries: 

226 

227 - ``projects/[PROJECT_ID]`` 

228 - ``organizations/[ORGANIZATION_ID]`` 

229 - ``billingAccounts/[BILLING_ACCOUNT_ID]`` 

230 - ``folders/[FOLDER_ID]`` 

231 

232 May alternatively be one or more views: 

233 

234 - ``projects/[PROJECT_ID]/locations/[LOCATION_ID]/buckets/[BUCKET_ID]/views/[VIEW_ID]`` 

235 - ``organizations/[ORGANIZATION_ID]/locations/[LOCATION_ID]/buckets/[BUCKET_ID]/views/[VIEW_ID]`` 

236 - ``billingAccounts/[BILLING_ACCOUNT_ID]/locations/[LOCATION_ID]/buckets/[BUCKET_ID]/views/[VIEW_ID]`` 

237 - ``folders/[FOLDER_ID]/locations/[LOCATION_ID]/buckets/[BUCKET_ID]/views/[VIEW_ID]`` 

238 

239 Projects listed in the ``project_ids`` field are added to 

240 this list. A maximum of 100 resources may be specified in a 

241 single request. 

242 filter (str): 

243 Optional. Only log entries that match the filter are 

244 returned. An empty filter matches all log entries in the 

245 resources listed in ``resource_names``. Referencing a parent 

246 resource that is not listed in ``resource_names`` will cause 

247 the filter to return no results. The maximum length of a 

248 filter is 20,000 characters. 

249 order_by (str): 

250 Optional. How the results should be sorted. Presently, the 

251 only permitted values are ``"timestamp asc"`` (default) and 

252 ``"timestamp desc"``. The first option returns entries in 

253 order of increasing values of ``LogEntry.timestamp`` (oldest 

254 first), and the second option returns entries in order of 

255 decreasing timestamps (newest first). Entries with equal 

256 timestamps are returned in order of their ``insert_id`` 

257 values. 

258 page_size (int): 

259 Optional. The maximum number of results to return from this 

260 request. Default is 50. If the value is negative or exceeds 

261 1000, the request is rejected. The presence of 

262 ``next_page_token`` in the response indicates that more 

263 results might be available. 

264 page_token (str): 

265 Optional. If present, then retrieve the next batch of 

266 results from the preceding call to this method. 

267 ``page_token`` must be the value of ``next_page_token`` from 

268 the previous response. The values of other method parameters 

269 should be identical to those in the previous call. 

270 """ 

271 

272 resource_names: MutableSequence[str] = proto.RepeatedField( 

273 proto.STRING, 

274 number=8, 

275 ) 

276 filter: str = proto.Field( 

277 proto.STRING, 

278 number=2, 

279 ) 

280 order_by: str = proto.Field( 

281 proto.STRING, 

282 number=3, 

283 ) 

284 page_size: int = proto.Field( 

285 proto.INT32, 

286 number=4, 

287 ) 

288 page_token: str = proto.Field( 

289 proto.STRING, 

290 number=5, 

291 ) 

292 

293 

294class ListLogEntriesResponse(proto.Message): 

295 r"""Result returned from ``ListLogEntries``. 

296 

297 Attributes: 

298 entries (MutableSequence[google.cloud.logging_v2.types.LogEntry]): 

299 A list of log entries. If ``entries`` is empty, 

300 ``nextPageToken`` may still be returned, indicating that 

301 more entries may exist. See ``nextPageToken`` for more 

302 information. 

303 next_page_token (str): 

304 If there might be more results than those appearing in this 

305 response, then ``nextPageToken`` is included. To get the 

306 next set of results, call this method again using the value 

307 of ``nextPageToken`` as ``pageToken``. 

308 

309 If a value for ``next_page_token`` appears and the 

310 ``entries`` field is empty, it means that the search found 

311 no log entries so far but it did not have time to search all 

312 the possible log entries. Retry the method with this value 

313 for ``page_token`` to continue the search. Alternatively, 

314 consider speeding up the search by changing your filter to 

315 specify a single log name or resource type, or to narrow the 

316 time range of the search. 

317 """ 

318 

319 @property 

320 def raw_page(self): 

321 return self 

322 

323 entries: MutableSequence[log_entry.LogEntry] = proto.RepeatedField( 

324 proto.MESSAGE, 

325 number=1, 

326 message=log_entry.LogEntry, 

327 ) 

328 next_page_token: str = proto.Field( 

329 proto.STRING, 

330 number=2, 

331 ) 

332 

333 

334class ListMonitoredResourceDescriptorsRequest(proto.Message): 

335 r"""The parameters to ListMonitoredResourceDescriptors 

336 

337 Attributes: 

338 page_size (int): 

339 Optional. The maximum number of results to return from this 

340 request. Non-positive values are ignored. The presence of 

341 ``nextPageToken`` in the response indicates that more 

342 results might be available. 

343 page_token (str): 

344 Optional. If present, then retrieve the next batch of 

345 results from the preceding call to this method. 

346 ``pageToken`` must be the value of ``nextPageToken`` from 

347 the previous response. The values of other method parameters 

348 should be identical to those in the previous call. 

349 """ 

350 

351 page_size: int = proto.Field( 

352 proto.INT32, 

353 number=1, 

354 ) 

355 page_token: str = proto.Field( 

356 proto.STRING, 

357 number=2, 

358 ) 

359 

360 

361class ListMonitoredResourceDescriptorsResponse(proto.Message): 

362 r"""Result returned from ListMonitoredResourceDescriptors. 

363 

364 Attributes: 

365 resource_descriptors (MutableSequence[google.api.monitored_resource_pb2.MonitoredResourceDescriptor]): 

366 A list of resource descriptors. 

367 next_page_token (str): 

368 If there might be more results than those appearing in this 

369 response, then ``nextPageToken`` is included. To get the 

370 next set of results, call this method again using the value 

371 of ``nextPageToken`` as ``pageToken``. 

372 """ 

373 

374 @property 

375 def raw_page(self): 

376 return self 

377 

378 resource_descriptors: MutableSequence[ 

379 monitored_resource_pb2.MonitoredResourceDescriptor 

380 ] = proto.RepeatedField( 

381 proto.MESSAGE, 

382 number=1, 

383 message=monitored_resource_pb2.MonitoredResourceDescriptor, 

384 ) 

385 next_page_token: str = proto.Field( 

386 proto.STRING, 

387 number=2, 

388 ) 

389 

390 

391class ListLogsRequest(proto.Message): 

392 r"""The parameters to ListLogs. 

393 

394 Attributes: 

395 parent (str): 

396 Required. The resource name to list logs for: 

397 

398 - ``projects/[PROJECT_ID]`` 

399 - ``organizations/[ORGANIZATION_ID]`` 

400 - ``billingAccounts/[BILLING_ACCOUNT_ID]`` 

401 - ``folders/[FOLDER_ID]`` 

402 resource_names (MutableSequence[str]): 

403 Optional. List of resource names to list logs for: 

404 

405 - ``projects/[PROJECT_ID]/locations/[LOCATION_ID]/buckets/[BUCKET_ID]/views/[VIEW_ID]`` 

406 - ``organizations/[ORGANIZATION_ID]/locations/[LOCATION_ID]/buckets/[BUCKET_ID]/views/[VIEW_ID]`` 

407 - ``billingAccounts/[BILLING_ACCOUNT_ID]/locations/[LOCATION_ID]/buckets/[BUCKET_ID]/views/[VIEW_ID]`` 

408 - ``folders/[FOLDER_ID]/locations/[LOCATION_ID]/buckets/[BUCKET_ID]/views/[VIEW_ID]`` 

409 

410 To support legacy queries, it could also be: 

411 

412 - ``projects/[PROJECT_ID]`` 

413 - ``organizations/[ORGANIZATION_ID]`` 

414 - ``billingAccounts/[BILLING_ACCOUNT_ID]`` 

415 - ``folders/[FOLDER_ID]`` 

416 

417 The resource name in the ``parent`` field is added to this 

418 list. 

419 page_size (int): 

420 Optional. The maximum number of results to return from this 

421 request. Non-positive values are ignored. The presence of 

422 ``nextPageToken`` in the response indicates that more 

423 results might be available. 

424 page_token (str): 

425 Optional. If present, then retrieve the next batch of 

426 results from the preceding call to this method. 

427 ``pageToken`` must be the value of ``nextPageToken`` from 

428 the previous response. The values of other method parameters 

429 should be identical to those in the previous call. 

430 """ 

431 

432 parent: str = proto.Field( 

433 proto.STRING, 

434 number=1, 

435 ) 

436 resource_names: MutableSequence[str] = proto.RepeatedField( 

437 proto.STRING, 

438 number=8, 

439 ) 

440 page_size: int = proto.Field( 

441 proto.INT32, 

442 number=2, 

443 ) 

444 page_token: str = proto.Field( 

445 proto.STRING, 

446 number=3, 

447 ) 

448 

449 

450class ListLogsResponse(proto.Message): 

451 r"""Result returned from ListLogs. 

452 

453 Attributes: 

454 log_names (MutableSequence[str]): 

455 A list of log names. For example, 

456 ``"projects/my-project/logs/syslog"`` or 

457 ``"organizations/123/logs/cloudresourcemanager.googleapis.com%2Factivity"``. 

458 next_page_token (str): 

459 If there might be more results than those appearing in this 

460 response, then ``nextPageToken`` is included. To get the 

461 next set of results, call this method again using the value 

462 of ``nextPageToken`` as ``pageToken``. 

463 """ 

464 

465 @property 

466 def raw_page(self): 

467 return self 

468 

469 log_names: MutableSequence[str] = proto.RepeatedField( 

470 proto.STRING, 

471 number=3, 

472 ) 

473 next_page_token: str = proto.Field( 

474 proto.STRING, 

475 number=2, 

476 ) 

477 

478 

479class TailLogEntriesRequest(proto.Message): 

480 r"""The parameters to ``TailLogEntries``. 

481 

482 Attributes: 

483 resource_names (MutableSequence[str]): 

484 Required. Name of a parent resource from which to retrieve 

485 log entries: 

486 

487 - ``projects/[PROJECT_ID]`` 

488 - ``organizations/[ORGANIZATION_ID]`` 

489 - ``billingAccounts/[BILLING_ACCOUNT_ID]`` 

490 - ``folders/[FOLDER_ID]`` 

491 

492 May alternatively be one or more views: 

493 

494 - ``projects/[PROJECT_ID]/locations/[LOCATION_ID]/buckets/[BUCKET_ID]/views/[VIEW_ID]`` 

495 - ``organizations/[ORGANIZATION_ID]/locations/[LOCATION_ID]/buckets/[BUCKET_ID]/views/[VIEW_ID]`` 

496 - ``billingAccounts/[BILLING_ACCOUNT_ID]/locations/[LOCATION_ID]/buckets/[BUCKET_ID]/views/[VIEW_ID]`` 

497 - ``folders/[FOLDER_ID]/locations/[LOCATION_ID]/buckets/[BUCKET_ID]/views/[VIEW_ID]`` 

498 filter (str): 

499 Optional. Only log entries that match the filter are 

500 returned. An empty filter matches all log entries in the 

501 resources listed in ``resource_names``. Referencing a parent 

502 resource that is not listed in ``resource_names`` will cause 

503 the filter to return no results. The maximum length of a 

504 filter is 20,000 characters. 

505 buffer_window (google.protobuf.duration_pb2.Duration): 

506 Optional. The amount of time to buffer log 

507 entries at the server before being returned to 

508 prevent out of order results due to late 

509 arriving log entries. Valid values are between 

510 0-60000 milliseconds. Defaults to 2000 

511 milliseconds. 

512 """ 

513 

514 resource_names: MutableSequence[str] = proto.RepeatedField( 

515 proto.STRING, 

516 number=1, 

517 ) 

518 filter: str = proto.Field( 

519 proto.STRING, 

520 number=2, 

521 ) 

522 buffer_window: duration_pb2.Duration = proto.Field( 

523 proto.MESSAGE, 

524 number=3, 

525 message=duration_pb2.Duration, 

526 ) 

527 

528 

529class TailLogEntriesResponse(proto.Message): 

530 r"""Result returned from ``TailLogEntries``. 

531 

532 Attributes: 

533 entries (MutableSequence[google.cloud.logging_v2.types.LogEntry]): 

534 A list of log entries. Each response in the stream will 

535 order entries with increasing values of 

536 ``LogEntry.timestamp``. Ordering is not guaranteed between 

537 separate responses. 

538 suppression_info (MutableSequence[google.cloud.logging_v2.types.TailLogEntriesResponse.SuppressionInfo]): 

539 If entries that otherwise would have been 

540 included in the session were not sent back to 

541 the client, counts of relevant entries omitted 

542 from the session with the reason that they were 

543 not included. There will be at most one of each 

544 reason per response. The counts represent the 

545 number of suppressed entries since the last 

546 streamed response. 

547 """ 

548 

549 class SuppressionInfo(proto.Message): 

550 r"""Information about entries that were omitted from the session. 

551 

552 Attributes: 

553 reason (google.cloud.logging_v2.types.TailLogEntriesResponse.SuppressionInfo.Reason): 

554 The reason that entries were omitted from the 

555 session. 

556 suppressed_count (int): 

557 A lower bound on the count of entries omitted due to 

558 ``reason``. 

559 """ 

560 

561 class Reason(proto.Enum): 

562 r"""An indicator of why entries were omitted. 

563 

564 Values: 

565 REASON_UNSPECIFIED (0): 

566 Unexpected default. 

567 RATE_LIMIT (1): 

568 Indicates suppression occurred due to relevant entries being 

569 received in excess of rate limits. For quotas and limits, 

570 see `Logging API quotas and 

571 limits <https://cloud.google.com/logging/quotas#api-limits>`__. 

572 NOT_CONSUMED (2): 

573 Indicates suppression occurred due to the 

574 client not consuming responses quickly enough. 

575 """ 

576 REASON_UNSPECIFIED = 0 

577 RATE_LIMIT = 1 

578 NOT_CONSUMED = 2 

579 

580 reason: "TailLogEntriesResponse.SuppressionInfo.Reason" = proto.Field( 

581 proto.ENUM, 

582 number=1, 

583 enum="TailLogEntriesResponse.SuppressionInfo.Reason", 

584 ) 

585 suppressed_count: int = proto.Field( 

586 proto.INT32, 

587 number=2, 

588 ) 

589 

590 entries: MutableSequence[log_entry.LogEntry] = proto.RepeatedField( 

591 proto.MESSAGE, 

592 number=1, 

593 message=log_entry.LogEntry, 

594 ) 

595 suppression_info: MutableSequence[SuppressionInfo] = proto.RepeatedField( 

596 proto.MESSAGE, 

597 number=2, 

598 message=SuppressionInfo, 

599 ) 

600 

601 

602__all__ = tuple(sorted(__protobuf__.manifest))