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.106.0 (build e852934)", date="2025-03-04T22:57:27.199Z") @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
    • metric

      @Stability(Stable) @NotNull public Metric metric(@NotNull String metricName, @Nullable MetricOptions props)
      Creates a CloudWatch metric for this log group.

      Specified by:
      metric in interface ILogGroup
      Parameters:
      metricName -
      • The name of the metric to create.
      This parameter is required.
      props -
      • Optional.
      Returns:
      A CloudWatch Metric object representing the specified metric for this log group.

      This method creates a CloudWatch Metric object with predefined settings for the log group. It sets the namespace to 'AWS/Logs' and the statistic to 'Sum' by default.

      The created metric is automatically associated with this log group using the attachTo method.

      Common metric names for log groups include:

      • 'IncomingBytes': The volume of log data in bytes ingested into the log group.
      • 'IncomingLogEvents': The number of log events ingested into the log group.

       
    • metric

      @Stability(Stable) @NotNull public Metric metric(@NotNull String metricName)
      Creates a CloudWatch metric for this log group.

      Specified by:
      metric in interface ILogGroup
      Parameters:
      metricName -
      • The name of the metric to create.
      This parameter is required.
      Returns:
      A CloudWatch Metric object representing the specified metric for this log group.

      This method creates a CloudWatch Metric object with predefined settings for the log group. It sets the namespace to 'AWS/Logs' and the statistic to 'Sum' by default.

      The created metric is automatically associated with this log group using the attachTo method.

      Common metric names for log groups include:

      • 'IncomingBytes': The volume of log data in bytes ingested into the log group.
      • 'IncomingLogEvents': The number of log events ingested into the log group.

       
    • metricIncomingBytes

      @Stability(Stable) @NotNull public Metric metricIncomingBytes(@Nullable MetricOptions props)
      Creates a CloudWatch metric for the volume of incoming log data in bytes to this log group.

      Specified by:
      metricIncomingBytes in interface ILogGroup
      Parameters:
      props -
      • Optional.
      Returns:
      A CloudWatch Metric object representing the IncomingBytes metric.

      This method allows you to monitor the volume of data being ingested into the log group. It's useful for understanding the size of your logs, which can impact storage costs and help in identifying unexpectedly large log entries.

      Example usage:

       const logGroup = new logs.LogGroup(this, 'MyLogGroup');
       logGroup.metricIncomingBytes().createAlarm(stack, 'IncomingBytesPerInstanceAlarm', {
       threshold: 1,
       evaluationPeriods: 1,
       });
       
    • metricIncomingBytes

      @Stability(Stable) @NotNull public Metric metricIncomingBytes()
      Creates a CloudWatch metric for the volume of incoming log data in bytes to this log group.

      Specified by:
      metricIncomingBytes in interface ILogGroup
      Returns:
      A CloudWatch Metric object representing the IncomingBytes metric.

      This method allows you to monitor the volume of data being ingested into the log group. It's useful for understanding the size of your logs, which can impact storage costs and help in identifying unexpectedly large log entries.

      Example usage:

       const logGroup = new logs.LogGroup(this, 'MyLogGroup');
       logGroup.metricIncomingBytes().createAlarm(stack, 'IncomingBytesPerInstanceAlarm', {
       threshold: 1,
       evaluationPeriods: 1,
       });
       
    • metricIncomingLogEvents

      @Stability(Stable) @NotNull public Metric metricIncomingLogEvents(@Nullable MetricOptions props)
      Creates a CloudWatch metric for the number of incoming log events to this log group.

      Specified by:
      metricIncomingLogEvents in interface ILogGroup
      Parameters:
      props -
      • Optional.
      Returns:
      A CloudWatch Metric object representing the IncomingLogEvents metric.

      This method allows you to monitor the rate at which log events are being ingested into the log group. It's useful for understanding the volume of logging activity and can help in capacity planning or detecting unusual spikes in logging.

      Example usage:

       const logGroup = new logs.LogGroup(this, 'MyLogGroup');
       logGroup.metricIncomingLogEvents().createAlarm(stack, 'IncomingEventsPerInstanceAlarm', {
       threshold: 1,
       evaluationPeriods: 1,
       });
       
    • metricIncomingLogEvents

      @Stability(Stable) @NotNull public Metric metricIncomingLogEvents()
      Creates a CloudWatch metric for the number of incoming log events to this log group.

      Specified by:
      metricIncomingLogEvents in interface ILogGroup
      Returns:
      A CloudWatch Metric object representing the IncomingLogEvents metric.

      This method allows you to monitor the rate at which log events are being ingested into the log group. It's useful for understanding the volume of logging activity and can help in capacity planning or detecting unusual spikes in logging.

      Example usage:

       const logGroup = new logs.LogGroup(this, 'MyLogGroup');
       logGroup.metricIncomingLogEvents().createAlarm(stack, 'IncomingEventsPerInstanceAlarm', {
       threshold: 1,
       evaluationPeriods: 1,
       });
       
    • 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