@@ -205,7 +205,7 @@ class OCILog(OCILoggingModelMixin, oci.logging.models.Log):
205
205
"""Represents the OCI Log resource.
206
206
207
207
Usage: (OCI requires display_name to be unique and it cannot contain space)
208
- >>> log = OCILog.create (display_name="My_Log", log_group_id=LOG_GROUP_ID)
208
+ >>> log = OCILog(display_name="My_Log", log_group_id=LOG_GROUP_ID).create( )
209
209
Usually it is better to create a log using the create_log() method in OCILogGroup.
210
210
>>> log.delete() # Delete the resource
211
211
Get a log object from OCID
@@ -269,15 +269,17 @@ def create_async(self):
269
269
self .log_group_id , self .to_oci_model (oci .logging .models .CreateLogDetails )
270
270
)
271
271
272
- def sync (self ) -> None :
272
+ def sync (self , ** kwargs ) -> None :
273
273
"""Refreshes the properties of the Log model
274
274
OCI requires both Log OCID and Log group OCID to get the Log model.
275
275
276
276
This method override the sync() method from OCIMixin to improve performance.
277
277
"""
278
278
if not self .log_group_id :
279
279
self .log_group_id = self ._get_log_group_id (self .id , self .compartment_id )
280
- self .update_from_oci_model (self .client .get_log (self .log_group_id , self .id ).data )
280
+ self .update_from_oci_model (
281
+ self .client .get_log (self .log_group_id , self .id ).data , ** kwargs
282
+ )
281
283
return self
282
284
283
285
def delete (self ):
@@ -522,6 +524,7 @@ def _search_and_format(
522
524
limit : int = LOG_RECORDS_LIMIT ,
523
525
sort_by : str = "datetime" ,
524
526
sort_order : str = SortOrder .DESC ,
527
+ log_filter : str = None ,
525
528
):
526
529
"""Returns the formatted log records.
527
530
@@ -539,6 +542,9 @@ def _search_and_format(
539
542
The field for sorting the logs.
540
543
sort_order: (str, optional). Defaults to "DESC".
541
544
The sort order for the log records. Can be "ASC" or "DESC".
545
+ log_filter : (str, optional). Defaults to None.
546
+ Expression for filtering the logs.
547
+ This will be the WHERE clause of the query.
542
548
543
549
Returns
544
550
-------
@@ -556,6 +562,7 @@ def _search_and_format(
556
562
limit = limit ,
557
563
sort_by = sort_by ,
558
564
sort_order = sort_order ,
565
+ log_filter = log_filter ,
559
566
)
560
567
logs = sorted ((log .data for log in logs ), key = lambda x : x .get ("datetime" ))
561
568
logs = [log .get ("logContent" , {}) for log in logs ]
@@ -573,6 +580,7 @@ def tail(
573
580
source : str = None ,
574
581
limit = LOG_RECORDS_LIMIT ,
575
582
time_start : datetime .datetime = None ,
583
+ log_filter : str = None ,
576
584
) -> List [dict ]:
577
585
"""Returns the most recent log records.
578
586
@@ -586,6 +594,9 @@ def tail(
586
594
time_start: (datetime.datetime, optional)
587
595
Starting time for the log query.
588
596
Defaults to None. Logs up to 14 days from now will be returned.
597
+ log_filter : (str, optional). Defaults to None.
598
+ Expression for filtering the logs.
599
+ This will be the WHERE clause of the query.
589
600
590
601
Returns
591
602
-------
@@ -594,7 +605,11 @@ def tail(
594
605
Each log record is a dictionary with the following keys: `id`, `time`, `message`.
595
606
"""
596
607
return self ._search_and_format (
597
- source = source , limit = limit , sort_order = SortOrder .DESC , time_start = time_start
608
+ source = source ,
609
+ limit = limit ,
610
+ sort_order = SortOrder .DESC ,
611
+ time_start = time_start ,
612
+ log_filter = log_filter ,
598
613
)
599
614
600
615
def head (
@@ -632,6 +647,7 @@ def stream(
632
647
interval : int = LOG_INTERVAL ,
633
648
stop_condition : callable = None ,
634
649
time_start : datetime .datetime = None ,
650
+ log_filter : str = None ,
635
651
):
636
652
"""Streams logs to console/terminal until stop_condition() returns true.
637
653
@@ -646,6 +662,10 @@ def stream(
646
662
time_start: datetime.datetime
647
663
Starting time for the log query.
648
664
Defaults to None. Logs up to 14 days from now will be returned.
665
+ log_filter : str, optional
666
+ Expression for filtering the logs.
667
+ This will be the WHERE clause of the query.
668
+ Defaults to None.
649
669
650
670
Returns
651
671
-------
@@ -664,7 +684,9 @@ def stream(
664
684
next_time_start = datetime .datetime .utcnow () - datetime .timedelta (
665
685
seconds = 180
666
686
)
667
- logs = self .tail (source , limit = None , time_start = time_start )
687
+ logs = self .tail (
688
+ source , limit = None , time_start = time_start , log_filter = log_filter
689
+ )
668
690
# Update time_start if the tail() is successful
669
691
time_start = next_time_start
670
692
except Exception :
0 commit comments