Class LogGroup
- All Implemented Interfaces:
IResource
,IResourceWithPolicy
,ILogGroup
,software.amazon.jsii.JsiiSerializable
,software.constructs.IConstruct
,software.constructs.IDependable
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();
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class software.amazon.jsii.JsiiObject
software.amazon.jsii.JsiiObject.InitializationMode
Nested classes/interfaces inherited from interface software.constructs.IConstruct
software.constructs.IConstruct.Jsii$Default
Nested classes/interfaces inherited from interface software.amazon.awscdk.services.logs.ILogGroup
ILogGroup.Jsii$Default, ILogGroup.Jsii$Proxy
Nested classes/interfaces inherited from interface software.amazon.awscdk.IResource
IResource.Jsii$Default
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
LogGroup
(software.amazon.jsii.JsiiObject.InitializationMode initializationMode) protected
LogGroup
(software.amazon.jsii.JsiiObjectRef objRef) LogGroup
(software.constructs.Construct scope, String id, LogGroupProps props) -
Method Summary
Modifier and TypeMethodDescriptionaddMetricFilter
(String id, MetricFilterOptions props) Create a new Metric Filter on this Log Group.Create a new Log Stream for this Log Group.addStream
(String id, StreamOptions props) Create a new Log Stream for this Log Group.addSubscriptionFilter
(String id, SubscriptionFilterOptions props) Create a new Subscription Filter on this Log Group.addToResourcePolicy
(PolicyStatement statement) Adds a statement to the resource policy associated with this log group.extractMetric
(String jsonField, String metricNamespace, String metricName) Extract a metric from structured log events in the LogGroup.static ILogGroup
fromLogGroupArn
(software.constructs.Construct scope, String id, String logGroupArn) Import an existing LogGroup given its ARN.static ILogGroup
fromLogGroupName
(software.constructs.Construct scope, String id, String logGroupName) Import an existing LogGroup given its name.The ARN of this log group.The name of this log group.grant
(IGrantable grantee, @NotNull String... actions) Give the indicated permissions on this log group and all streams.grantRead
(IGrantable grantee) Give permissions to read and filter events from this log group.grantWrite
(IGrantable grantee) Give permissions to create and write to streams in this log group.Public method to get the physical name of this log group.Creates a CloudWatch metric for this log group.metric
(String metricName, MetricOptions props) Creates a CloudWatch metric for this log group.Creates a CloudWatch metric for the volume of incoming log data in bytes to this log group.metricIncomingBytes
(MetricOptions props) Creates a CloudWatch metric for the volume of incoming log data in bytes to this log group.Creates a CloudWatch metric for the number of incoming log events to this log group.Creates a CloudWatch metric for the number of incoming log events to this log group.Methods inherited from class software.amazon.awscdk.Resource
applyRemovalPolicy, generatePhysicalName, getEnv, getPhysicalName, getResourceArnAttribute, getResourceNameAttribute, getStack, isOwnedResource, isResource
Methods inherited from class software.constructs.Construct
getNode, isConstruct, toString
Methods inherited from class software.amazon.jsii.JsiiObject
jsiiAsyncCall, jsiiAsyncCall, jsiiCall, jsiiCall, jsiiGet, jsiiGet, jsiiSet, jsiiStaticCall, jsiiStaticCall, jsiiStaticGet, jsiiStaticGet, jsiiStaticSet, jsiiStaticSet
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface software.constructs.IConstruct
getNode
Methods inherited from interface software.amazon.awscdk.IResource
applyRemovalPolicy, getEnv, getStack
Methods inherited from interface software.amazon.jsii.JsiiSerializable
$jsii$toJson
-
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 interfaceILogGroup
- 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. -
addStream
Create a new Log Stream for this Log Group. -
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 interfaceILogGroup
- 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 interfaceIResourceWithPolicy
- 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 interfaceILogGroup
- 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. -
grantRead
Give permissions to read and filter events from this log group. -
grantWrite
Give permissions to create and write to streams in this log group.- Specified by:
grantWrite
in interfaceILogGroup
- Parameters:
grantee
- This parameter is required.
-
logGroupPhysicalName
Public method to get the physical name of this log group.- Specified by:
logGroupPhysicalName
in interfaceILogGroup
- 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 interfaceILogGroup
- Parameters:
metricName
-- The name of the metric to create.
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
Creates a CloudWatch metric for this log group.- Specified by:
metric
in interfaceILogGroup
- Parameters:
metricName
-- The name of the metric to create.
- 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
Creates a CloudWatch metric for the volume of incoming log data in bytes to this log group.- Specified by:
metricIncomingBytes
in interfaceILogGroup
- 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
Creates a CloudWatch metric for the volume of incoming log data in bytes to this log group.- Specified by:
metricIncomingBytes
in interfaceILogGroup
- 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
Creates a CloudWatch metric for the number of incoming log events to this log group.- Specified by:
metricIncomingLogEvents
in interfaceILogGroup
- 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
Creates a CloudWatch metric for the number of incoming log events to this log group.- Specified by:
metricIncomingLogEvents
in interfaceILogGroup
- 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
The ARN of this log group.- Specified by:
getLogGroupArn
in interfaceILogGroup
-
getLogGroupName
The name of this log group.- Specified by:
getLogGroupName
in interfaceILogGroup
-