Class LogGroup

java.lang.Object
software.amazon.jsii.JsiiObject
software.constructs.Construct
software.amazon.awscdk.Resource
software.amazon.awscdk.services.logs.LogGroup
All Implemented Interfaces:
IResource, IResourceWithPolicy, ILogGroup, software.amazon.jsii.JsiiSerializable, software.constructs.IConstruct, software.constructs.IDependable

@Generated(value="jsii-pacmak/1.98.0 (build 00b106d)", date="2024-05-24T02:42:40.510Z") @Stability(Stable) public class LogGroup extends Resource implements ILogGroup
Define a CloudWatch Log Group.

Example:

 import software.amazon.awscdk.services.logs.*;
 LogGroup logGroup = new LogGroup(this, "Log Group");
 Bucket logBucket = new Bucket(this, "S3 Bucket");
 EmrContainersStartJobRun.Builder.create(this, "EMR Containers Start Job Run")
         .virtualCluster(VirtualClusterInput.fromVirtualClusterId("de92jdei2910fwedz"))
         .releaseLabel(ReleaseLabel.EMR_6_2_0)
         .jobDriver(JobDriver.builder()
                 .sparkSubmitJobDriver(SparkSubmitJobDriver.builder()
                         .entryPoint(TaskInput.fromText("local:///usr/lib/spark/examples/src/main/python/pi.py"))
                         .sparkSubmitParameters("--conf spark.executor.instances=2 --conf spark.executor.memory=2G --conf spark.executor.cores=2 --conf spark.driver.cores=1")
                         .build())
                 .build())
         .monitoring(Monitoring.builder()
                 .logGroup(logGroup)
                 .logBucket(logBucket)
                 .build())
         .build();
 
  • Constructor Details

    • LogGroup

      protected LogGroup(software.amazon.jsii.JsiiObjectRef objRef)
    • LogGroup

      protected LogGroup(software.amazon.jsii.JsiiObject.InitializationMode initializationMode)
    • LogGroup

      @Stability(Stable) public LogGroup(@NotNull software.constructs.Construct scope, @NotNull String id, @Nullable LogGroupProps props)
      Parameters:
      scope - This parameter is required.
      id - This parameter is required.
      props -
    • LogGroup

      @Stability(Stable) public LogGroup(@NotNull software.constructs.Construct scope, @NotNull String id)
      Parameters:
      scope - This parameter is required.
      id - This parameter is required.
  • Method Details

    • fromLogGroupArn

      @Stability(Stable) @NotNull public static ILogGroup fromLogGroupArn(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull String logGroupArn)
      Import an existing LogGroup given its ARN.

      Parameters:
      scope - This parameter is required.
      id - This parameter is required.
      logGroupArn - This parameter is required.
    • fromLogGroupName

      @Stability(Stable) @NotNull public static ILogGroup fromLogGroupName(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull String logGroupName)
      Import an existing LogGroup given its name.

      Parameters:
      scope - This parameter is required.
      id - This parameter is required.
      logGroupName - This parameter is required.
    • addMetricFilter

      @Stability(Stable) @NotNull public MetricFilter addMetricFilter(@NotNull String id, @NotNull MetricFilterOptions props)
      Create a new Metric Filter on this Log Group.

      Specified by:
      addMetricFilter in interface ILogGroup
      Parameters:
      id - Unique identifier for the construct in its parent. This parameter is required.
      props - Properties for creating the MetricFilter. This parameter is required.
    • addStream

      @Stability(Stable) @NotNull public LogStream addStream(@NotNull String id, @Nullable StreamOptions props)
      Create a new Log Stream for this Log Group.

      Specified by:
      addStream in interface ILogGroup
      Parameters:
      id - Unique identifier for the construct in its parent. This parameter is required.
      props - Properties for creating the LogStream.
    • addStream

      @Stability(Stable) @NotNull public LogStream addStream(@NotNull String id)
      Create a new Log Stream for this Log Group.

      Specified by:
      addStream in interface ILogGroup
      Parameters:
      id - Unique identifier for the construct in its parent. This parameter is required.
    • addSubscriptionFilter

      @Stability(Stable) @NotNull public SubscriptionFilter addSubscriptionFilter(@NotNull String id, @NotNull SubscriptionFilterOptions props)
      Create a new Subscription Filter on this Log Group.

      Specified by:
      addSubscriptionFilter in interface ILogGroup
      Parameters:
      id - Unique identifier for the construct in its parent. This parameter is required.
      props - Properties for creating the SubscriptionFilter. This parameter is required.
    • addToResourcePolicy

      @Stability(Stable) @NotNull public AddToResourcePolicyResult addToResourcePolicy(@NotNull PolicyStatement statement)
      Adds a statement to the resource policy associated with this log group.

      A resource policy will be automatically created upon the first call to addToResourcePolicy.

      Any ARN Principals inside of the statement will be converted into AWS Account ID strings because CloudWatch Logs Resource Policies do not accept ARN principals.

      Specified by:
      addToResourcePolicy in interface IResourceWithPolicy
      Parameters:
      statement - The policy statement to add. This parameter is required.
    • extractMetric

      @Stability(Stable) @NotNull public Metric extractMetric(@NotNull String jsonField, @NotNull String metricNamespace, @NotNull String metricName)
      Extract a metric from structured log events in the LogGroup.

      Creates a MetricFilter on this LogGroup that will extract the value of the indicated JSON field in all records where it occurs.

      The metric will be available in CloudWatch Metrics under the indicated namespace and name.

      Specified by:
      extractMetric in interface ILogGroup
      Parameters:
      jsonField - JSON field to extract (example: '$.myfield'). This parameter is required.
      metricNamespace - Namespace to emit the metric under. This parameter is required.
      metricName - Name to emit the metric under. This parameter is required.
      Returns:
      A Metric object representing the extracted metric
    • grant

      @Stability(Stable) @NotNull public Grant grant(@NotNull IGrantable grantee, @NotNull @NotNull String... actions)
      Give the indicated permissions on this log group and all streams.

      Specified by:
      grant in interface ILogGroup
      Parameters:
      grantee - This parameter is required.
      actions - This parameter is required.
    • grantRead

      @Stability(Stable) @NotNull public Grant grantRead(@NotNull IGrantable grantee)
      Give permissions to read and filter events from this log group.

      Specified by:
      grantRead in interface ILogGroup
      Parameters:
      grantee - This parameter is required.
    • grantWrite

      @Stability(Stable) @NotNull public Grant grantWrite(@NotNull IGrantable grantee)
      Give permissions to create and write to streams in this log group.

      Specified by:
      grantWrite in interface ILogGroup
      Parameters:
      grantee - This parameter is required.
    • logGroupPhysicalName

      @Stability(Stable) @NotNull public String logGroupPhysicalName()
      Public method to get the physical name of this log group.

      Specified by:
      logGroupPhysicalName in interface ILogGroup
      Returns:
      Physical name of log group
    • getLogGroupArn

      @Stability(Stable) @NotNull public String getLogGroupArn()
      The ARN of this log group.
      Specified by:
      getLogGroupArn in interface ILogGroup
    • getLogGroupName

      @Stability(Stable) @NotNull public String getLogGroupName()
      The name of this log group.
      Specified by:
      getLogGroupName in interface ILogGroup