Class LogGroup
Define a CloudWatch Log Group.
Implements
Inherited Members
Namespace: Amazon.CDK.AWS.Logs
Assembly: Amazon.CDK.Lib.dll
Syntax (csharp)
public class LogGroup : Resource, ILogGroup, IResourceWithPolicy, IResourceWithPolicyV2, IResource, IEnvironmentAware, IConstruct, IDependable
Syntax (vb)
Public Class LogGroup Inherits Resource Implements ILogGroup, IResourceWithPolicy, IResourceWithPolicyV2, IResource, IEnvironmentAware, IConstruct, IDependable
Remarks
ExampleMetadata: infused
Examples
using Amazon.CDK.AWS.Logs;
var logGroup = new LogGroup(this, "Log Group");
var logBucket = new Bucket(this, "S3 Bucket");
new EmrContainersStartJobRun(this, "EMR Containers Start Job Run", new EmrContainersStartJobRunProps {
VirtualCluster = VirtualClusterInput.FromVirtualClusterId("de92jdei2910fwedz"),
ReleaseLabel = ReleaseLabel.EMR_6_2_0,
JobDriver = new JobDriver {
SparkSubmitJobDriver = new SparkSubmitJobDriver {
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"
}
},
Monitoring = new Monitoring {
LogGroup = logGroup,
LogBucket = logBucket
}
});
Synopsis
Constructors
| LogGroup(Construct, string, ILogGroupProps?) | Define a CloudWatch Log Group. |
Properties
| LogGroupArn | The ARN of this log group. |
| LogGroupName | The name of this log group. |
| PROPERTY_INJECTION_ID | Uniquely identifies this class. |
Methods
| AddMetricFilter(string, IMetricFilterOptions) | Create a new Metric Filter on this Log Group. |
| AddStream(string, IStreamOptions?) | Create a new Log Stream for this Log Group. |
| AddSubscriptionFilter(string, ISubscriptionFilterOptions) | Create a new Subscription Filter on this Log Group. |
| AddToResourcePolicy(PolicyStatement) | Adds a statement to the resource policy associated with this log group. |
| AddTransformer(string, ITransformerOptions) | Create a new Transformer on this Log Group. |
| ExtractMetric(string, string, string) | Extract a metric from structured log events in the LogGroup. |
| FromLogGroupArn(Construct, string, string) | Import an existing LogGroup given its ARN. |
| FromLogGroupName(Construct, string, string) | Import an existing LogGroup given its name. |
| Grant(IGrantable, params string[]) | Give the indicated permissions on this log group and all streams. |
| GrantRead(IGrantable) | Give permissions to read and filter events from this log group. |
| GrantWrite(IGrantable) | Give permissions to create and write to streams in this log group. |
| LogGroupPhysicalName() | Public method to get the physical name of this log group. |
| Metric(string, IMetricOptions?) | Creates a CloudWatch metric for this log group. |
| MetricIncomingBytes(IMetricOptions?) | Creates a CloudWatch metric for the volume of incoming log data in bytes to this log group. |
| MetricIncomingLogEvents(IMetricOptions?) | Creates a CloudWatch metric for the number of incoming log events to this log group. |
Constructors
LogGroup(Construct, string, ILogGroupProps?)
Define a CloudWatch Log Group.
public LogGroup(Construct scope, string id, ILogGroupProps? props = null)
Parameters
- scope Construct
- id string
- props ILogGroupProps
Remarks
ExampleMetadata: infused
Examples
using Amazon.CDK.AWS.Logs;
var logGroup = new LogGroup(this, "Log Group");
var logBucket = new Bucket(this, "S3 Bucket");
new EmrContainersStartJobRun(this, "EMR Containers Start Job Run", new EmrContainersStartJobRunProps {
VirtualCluster = VirtualClusterInput.FromVirtualClusterId("de92jdei2910fwedz"),
ReleaseLabel = ReleaseLabel.EMR_6_2_0,
JobDriver = new JobDriver {
SparkSubmitJobDriver = new SparkSubmitJobDriver {
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"
}
},
Monitoring = new Monitoring {
LogGroup = logGroup,
LogBucket = logBucket
}
});
Properties
LogGroupArn
The ARN of this log group.
public virtual string LogGroupArn { get; }
Property Value
Remarks
ExampleMetadata: infused
LogGroupName
The name of this log group.
public virtual string LogGroupName { get; }
Property Value
Remarks
ExampleMetadata: infused
PROPERTY_INJECTION_ID
Uniquely identifies this class.
public static string PROPERTY_INJECTION_ID { get; }
Property Value
Remarks
ExampleMetadata: infused
Methods
AddMetricFilter(string, IMetricFilterOptions)
Create a new Metric Filter on this Log Group.
public virtual MetricFilter AddMetricFilter(string id, IMetricFilterOptions props)
Parameters
- id string
Unique identifier for the construct in its parent.
- props IMetricFilterOptions
Properties for creating the MetricFilter.
Returns
Remarks
ExampleMetadata: infused
AddStream(string, IStreamOptions?)
Create a new Log Stream for this Log Group.
public virtual LogStream AddStream(string id, IStreamOptions? props = null)
Parameters
- id string
Unique identifier for the construct in its parent.
- props IStreamOptions
Properties for creating the LogStream.
Returns
Remarks
ExampleMetadata: infused
AddSubscriptionFilter(string, ISubscriptionFilterOptions)
Create a new Subscription Filter on this Log Group.
public virtual SubscriptionFilter AddSubscriptionFilter(string id, ISubscriptionFilterOptions props)
Parameters
- id string
Unique identifier for the construct in its parent.
- props ISubscriptionFilterOptions
Properties for creating the SubscriptionFilter.
Returns
Remarks
ExampleMetadata: infused
AddToResourcePolicy(PolicyStatement)
Adds a statement to the resource policy associated with this log group.
public virtual IAddToResourcePolicyResult AddToResourcePolicy(PolicyStatement statement)
Parameters
- statement PolicyStatement
The policy statement to add.
Returns
Remarks
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.
AddTransformer(string, ITransformerOptions)
Create a new Transformer on this Log Group.
public virtual Transformer AddTransformer(string id, ITransformerOptions props)
Parameters
- id string
Unique identifier for the construct in its parent.
- props ITransformerOptions
Properties for creating the Transformer.
Returns
Remarks
ExampleMetadata: infused
ExtractMetric(string, string, string)
Extract a metric from structured log events in the LogGroup.
public virtual Metric ExtractMetric(string jsonField, string metricNamespace, string metricName)
Parameters
- jsonField string
JSON field to extract (example: '$.myfield').
- metricNamespace string
Namespace to emit the metric under.
- metricName string
Name to emit the metric under.
Returns
A Metric object representing the extracted metric
Remarks
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.
FromLogGroupArn(Construct, string, string)
Import an existing LogGroup given its ARN.
public static ILogGroup FromLogGroupArn(Construct scope, string id, string logGroupArn)
Parameters
Returns
Remarks
ExampleMetadata: infused
FromLogGroupName(Construct, string, string)
Import an existing LogGroup given its name.
public static ILogGroup FromLogGroupName(Construct scope, string id, string logGroupName)
Parameters
Returns
Remarks
ExampleMetadata: infused
Grant(IGrantable, params string[])
Give the indicated permissions on this log group and all streams.
public virtual Grant Grant(IGrantable grantee, params string[] actions)
Parameters
- grantee IGrantable
- actions string[]
Returns
Remarks
ExampleMetadata: infused
GrantRead(IGrantable)
Give permissions to read and filter events from this log group.
public virtual Grant GrantRead(IGrantable grantee)
Parameters
- grantee IGrantable
Returns
Remarks
ExampleMetadata: infused
GrantWrite(IGrantable)
Give permissions to create and write to streams in this log group.
public virtual Grant GrantWrite(IGrantable grantee)
Parameters
- grantee IGrantable
Returns
Remarks
ExampleMetadata: infused
LogGroupPhysicalName()
Public method to get the physical name of this log group.
public virtual string LogGroupPhysicalName()
Returns
Physical name of log group
Remarks
ExampleMetadata: infused
Metric(string, IMetricOptions?)
Creates a CloudWatch metric for this log group.
public virtual Metric Metric(string metricName, IMetricOptions? props = null)
Parameters
- metricName string
- The name of the metric to create.
- props IMetricOptions
- 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.
```
Remarks
ExampleMetadata: infused
MetricIncomingBytes(IMetricOptions?)
Creates a CloudWatch metric for the volume of incoming log data in bytes to this log group.
public virtual Metric MetricIncomingBytes(IMetricOptions? props = null)
Parameters
- props IMetricOptions
- 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,
});
```
Remarks
ExampleMetadata: infused
MetricIncomingLogEvents(IMetricOptions?)
Creates a CloudWatch metric for the number of incoming log events to this log group.
public virtual Metric MetricIncomingLogEvents(IMetricOptions? props = null)
Parameters
- props IMetricOptions
- 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,
});
```
Remarks
ExampleMetadata: infused