UNPKG

10.4 kBTypeScriptView Raw
1import * as cloudwatch from '@aws-cdk/aws-cloudwatch';
2import * as iam from '@aws-cdk/aws-iam';
3import * as kms from '@aws-cdk/aws-kms';
4import { RemovalPolicy, Resource } from '@aws-cdk/core';
5import { Construct } from 'constructs';
6import { LogStream } from './log-stream';
7import { MetricFilter } from './metric-filter';
8import { IFilterPattern } from './pattern';
9import { ILogSubscriptionDestination, SubscriptionFilter } from './subscription-filter';
10export interface ILogGroup extends iam.IResourceWithPolicy {
11 /**
12 * The ARN of this log group, with ':*' appended
13 *
14 * @attribute
15 */
16 readonly logGroupArn: string;
17 /**
18 * The name of this log group
19 * @attribute
20 */
21 readonly logGroupName: string;
22 /**
23 * Create a new Log Stream for this Log Group
24 *
25 * @param id Unique identifier for the construct in its parent
26 * @param props Properties for creating the LogStream
27 */
28 addStream(id: string, props?: StreamOptions): LogStream;
29 /**
30 * Create a new Subscription Filter on this Log Group
31 *
32 * @param id Unique identifier for the construct in its parent
33 * @param props Properties for creating the SubscriptionFilter
34 */
35 addSubscriptionFilter(id: string, props: SubscriptionFilterOptions): SubscriptionFilter;
36 /**
37 * Create a new Metric Filter on this Log Group
38 *
39 * @param id Unique identifier for the construct in its parent
40 * @param props Properties for creating the MetricFilter
41 */
42 addMetricFilter(id: string, props: MetricFilterOptions): MetricFilter;
43 /**
44 * Extract a metric from structured log events in the LogGroup
45 *
46 * Creates a MetricFilter on this LogGroup that will extract the value
47 * of the indicated JSON field in all records where it occurs.
48 *
49 * The metric will be available in CloudWatch Metrics under the
50 * indicated namespace and name.
51 *
52 * @param jsonField JSON field to extract (example: '$.myfield')
53 * @param metricNamespace Namespace to emit the metric under
54 * @param metricName Name to emit the metric under
55 * @returns A Metric object representing the extracted metric
56 */
57 extractMetric(jsonField: string, metricNamespace: string, metricName: string): cloudwatch.Metric;
58 /**
59 * Give permissions to write to create and write to streams in this log group
60 */
61 grantWrite(grantee: iam.IGrantable): iam.Grant;
62 /**
63 * Give the indicated permissions on this log group and all streams
64 */
65 grant(grantee: iam.IGrantable, ...actions: string[]): iam.Grant;
66 /**
67 * Public method to get the physical name of this log group
68 */
69 logGroupPhysicalName(): string;
70}
71/**
72 * An CloudWatch Log Group
73 */
74declare abstract class LogGroupBase extends Resource implements ILogGroup {
75 /**
76 * The ARN of this log group, with ':*' appended
77 */
78 abstract readonly logGroupArn: string;
79 /**
80 * The name of this log group
81 */
82 abstract readonly logGroupName: string;
83 private policy?;
84 /**
85 * Create a new Log Stream for this Log Group
86 *
87 * @param id Unique identifier for the construct in its parent
88 * @param props Properties for creating the LogStream
89 */
90 addStream(id: string, props?: StreamOptions): LogStream;
91 /**
92 * Create a new Subscription Filter on this Log Group
93 *
94 * @param id Unique identifier for the construct in its parent
95 * @param props Properties for creating the SubscriptionFilter
96 */
97 addSubscriptionFilter(id: string, props: SubscriptionFilterOptions): SubscriptionFilter;
98 /**
99 * Create a new Metric Filter on this Log Group
100 *
101 * @param id Unique identifier for the construct in its parent
102 * @param props Properties for creating the MetricFilter
103 */
104 addMetricFilter(id: string, props: MetricFilterOptions): MetricFilter;
105 /**
106 * Extract a metric from structured log events in the LogGroup
107 *
108 * Creates a MetricFilter on this LogGroup that will extract the value
109 * of the indicated JSON field in all records where it occurs.
110 *
111 * The metric will be available in CloudWatch Metrics under the
112 * indicated namespace and name.
113 *
114 * @param jsonField JSON field to extract (example: '$.myfield')
115 * @param metricNamespace Namespace to emit the metric under
116 * @param metricName Name to emit the metric under
117 * @returns A Metric object representing the extracted metric
118 */
119 extractMetric(jsonField: string, metricNamespace: string, metricName: string): cloudwatch.Metric;
120 /**
121 * Give permissions to create and write to streams in this log group
122 */
123 grantWrite(grantee: iam.IGrantable): iam.Grant;
124 /**
125 * Give the indicated permissions on this log group and all streams
126 */
127 grant(grantee: iam.IGrantable, ...actions: string[]): iam.Grant;
128 /**
129 * Public method to get the physical name of this log group
130 * @returns Physical name of log group
131 */
132 logGroupPhysicalName(): string;
133 /**
134 * Adds a statement to the resource policy associated with this log group.
135 * A resource policy will be automatically created upon the first call to `addToResourcePolicy`.
136 *
137 * Any ARN Principals inside of the statement will be converted into AWS Account ID strings
138 * because CloudWatch Logs Resource Policies do not accept ARN principals.
139 *
140 * @param statement The policy statement to add
141 */
142 addToResourcePolicy(statement: iam.PolicyStatement): iam.AddToResourcePolicyResult;
143 private convertArnPrincpalToAccountId;
144}
145/**
146 * How long, in days, the log contents will be retained.
147 */
148export declare enum RetentionDays {
149 /**
150 * 1 day
151 */
152 ONE_DAY = 1,
153 /**
154 * 3 days
155 */
156 THREE_DAYS = 3,
157 /**
158 * 5 days
159 */
160 FIVE_DAYS = 5,
161 /**
162 * 1 week
163 */
164 ONE_WEEK = 7,
165 /**
166 * 2 weeks
167 */
168 TWO_WEEKS = 14,
169 /**
170 * 1 month
171 */
172 ONE_MONTH = 30,
173 /**
174 * 2 months
175 */
176 TWO_MONTHS = 60,
177 /**
178 * 3 months
179 */
180 THREE_MONTHS = 90,
181 /**
182 * 4 months
183 */
184 FOUR_MONTHS = 120,
185 /**
186 * 5 months
187 */
188 FIVE_MONTHS = 150,
189 /**
190 * 6 months
191 */
192 SIX_MONTHS = 180,
193 /**
194 * 1 year
195 */
196 ONE_YEAR = 365,
197 /**
198 * 13 months
199 */
200 THIRTEEN_MONTHS = 400,
201 /**
202 * 18 months
203 */
204 EIGHTEEN_MONTHS = 545,
205 /**
206 * 2 years
207 */
208 TWO_YEARS = 731,
209 /**
210 * 5 years
211 */
212 FIVE_YEARS = 1827,
213 /**
214 * 10 years
215 */
216 TEN_YEARS = 3653,
217 /**
218 * Retain logs forever
219 */
220 INFINITE = 9999
221}
222/**
223 * Properties for a LogGroup
224 */
225export interface LogGroupProps {
226 /**
227 * The KMS Key to encrypt the log group with.
228 *
229 * @default - log group is encrypted with the default master key
230 */
231 readonly encryptionKey?: kms.IKey;
232 /**
233 * Name of the log group.
234 *
235 * @default Automatically generated
236 */
237 readonly logGroupName?: string;
238 /**
239 * How long, in days, the log contents will be retained.
240 *
241 * To retain all logs, set this value to RetentionDays.INFINITE.
242 *
243 * @default RetentionDays.TWO_YEARS
244 */
245 readonly retention?: RetentionDays;
246 /**
247 * Determine the removal policy of this log group.
248 *
249 * Normally you want to retain the log group so you can diagnose issues
250 * from logs even after a deployment that no longer includes the log group.
251 * In that case, use the normal date-based retention policy to age out your
252 * logs.
253 *
254 * @default RemovalPolicy.Retain
255 */
256 readonly removalPolicy?: RemovalPolicy;
257}
258/**
259 * Define a CloudWatch Log Group
260 */
261export declare class LogGroup extends LogGroupBase {
262 /**
263 * Import an existing LogGroup given its ARN
264 */
265 static fromLogGroupArn(scope: Construct, id: string, logGroupArn: string): ILogGroup;
266 /**
267 * Import an existing LogGroup given its name
268 */
269 static fromLogGroupName(scope: Construct, id: string, logGroupName: string): ILogGroup;
270 /**
271 * The ARN of this log group
272 */
273 readonly logGroupArn: string;
274 /**
275 * The name of this log group
276 */
277 readonly logGroupName: string;
278 constructor(scope: Construct, id: string, props?: LogGroupProps);
279}
280/**
281 * Properties for a new LogStream created from a LogGroup
282 */
283export interface StreamOptions {
284 /**
285 * The name of the log stream to create.
286 *
287 * The name must be unique within the log group.
288 *
289 * @default Automatically generated
290 */
291 readonly logStreamName?: string;
292}
293/**
294 * Properties for a new SubscriptionFilter created from a LogGroup
295 */
296export interface SubscriptionFilterOptions {
297 /**
298 * The destination to send the filtered events to.
299 *
300 * For example, a Kinesis stream or a Lambda function.
301 */
302 readonly destination: ILogSubscriptionDestination;
303 /**
304 * Log events matching this pattern will be sent to the destination.
305 */
306 readonly filterPattern: IFilterPattern;
307}
308/**
309 * Properties for a MetricFilter created from a LogGroup
310 */
311export interface MetricFilterOptions {
312 /**
313 * Pattern to search for log events.
314 */
315 readonly filterPattern: IFilterPattern;
316 /**
317 * The namespace of the metric to emit.
318 */
319 readonly metricNamespace: string;
320 /**
321 * The name of the metric to emit.
322 */
323 readonly metricName: string;
324 /**
325 * The value to emit for the metric.
326 *
327 * Can either be a literal number (typically "1"), or the name of a field in the structure
328 * to take the value from the matched event. If you are using a field value, the field
329 * value must have been matched using the pattern.
330 *
331 * If you want to specify a field from a matched JSON structure, use '$.fieldName',
332 * and make sure the field is in the pattern (if only as '$.fieldName = *').
333 *
334 * If you want to specify a field from a matched space-delimited structure,
335 * use '$fieldName'.
336 *
337 * @default "1"
338 */
339 readonly metricValue?: string;
340 /**
341 * The value to emit if the pattern does not match a particular event.
342 *
343 * @default No metric emitted.
344 */
345 readonly defaultValue?: number;
346}
347export {};