UNPKG

10.6 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 * 6 years
215 */
216 SIX_YEARS = 2192,
217 /**
218 * 7 years
219 */
220 SEVEN_YEARS = 2557,
221 /**
222 * 8 years
223 */
224 EIGHT_YEARS = 2922,
225 /**
226 * 9 years
227 */
228 NINE_YEARS = 3288,
229 /**
230 * 10 years
231 */
232 TEN_YEARS = 3653,
233 /**
234 * Retain logs forever
235 */
236 INFINITE = 9999
237}
238/**
239 * Properties for a LogGroup
240 */
241export interface LogGroupProps {
242 /**
243 * The KMS Key to encrypt the log group with.
244 *
245 * @default - log group is encrypted with the default master key
246 */
247 readonly encryptionKey?: kms.IKey;
248 /**
249 * Name of the log group.
250 *
251 * @default Automatically generated
252 */
253 readonly logGroupName?: string;
254 /**
255 * How long, in days, the log contents will be retained.
256 *
257 * To retain all logs, set this value to RetentionDays.INFINITE.
258 *
259 * @default RetentionDays.TWO_YEARS
260 */
261 readonly retention?: RetentionDays;
262 /**
263 * Determine the removal policy of this log group.
264 *
265 * Normally you want to retain the log group so you can diagnose issues
266 * from logs even after a deployment that no longer includes the log group.
267 * In that case, use the normal date-based retention policy to age out your
268 * logs.
269 *
270 * @default RemovalPolicy.Retain
271 */
272 readonly removalPolicy?: RemovalPolicy;
273}
274/**
275 * Define a CloudWatch Log Group
276 */
277export declare class LogGroup extends LogGroupBase {
278 /**
279 * Import an existing LogGroup given its ARN
280 */
281 static fromLogGroupArn(scope: Construct, id: string, logGroupArn: string): ILogGroup;
282 /**
283 * Import an existing LogGroup given its name
284 */
285 static fromLogGroupName(scope: Construct, id: string, logGroupName: string): ILogGroup;
286 /**
287 * The ARN of this log group
288 */
289 readonly logGroupArn: string;
290 /**
291 * The name of this log group
292 */
293 readonly logGroupName: string;
294 constructor(scope: Construct, id: string, props?: LogGroupProps);
295}
296/**
297 * Properties for a new LogStream created from a LogGroup
298 */
299export interface StreamOptions {
300 /**
301 * The name of the log stream to create.
302 *
303 * The name must be unique within the log group.
304 *
305 * @default Automatically generated
306 */
307 readonly logStreamName?: string;
308}
309/**
310 * Properties for a new SubscriptionFilter created from a LogGroup
311 */
312export interface SubscriptionFilterOptions {
313 /**
314 * The destination to send the filtered events to.
315 *
316 * For example, a Kinesis stream or a Lambda function.
317 */
318 readonly destination: ILogSubscriptionDestination;
319 /**
320 * Log events matching this pattern will be sent to the destination.
321 */
322 readonly filterPattern: IFilterPattern;
323}
324/**
325 * Properties for a MetricFilter created from a LogGroup
326 */
327export interface MetricFilterOptions {
328 /**
329 * Pattern to search for log events.
330 */
331 readonly filterPattern: IFilterPattern;
332 /**
333 * The namespace of the metric to emit.
334 */
335 readonly metricNamespace: string;
336 /**
337 * The name of the metric to emit.
338 */
339 readonly metricName: string;
340 /**
341 * The value to emit for the metric.
342 *
343 * Can either be a literal number (typically "1"), or the name of a field in the structure
344 * to take the value from the matched event. If you are using a field value, the field
345 * value must have been matched using the pattern.
346 *
347 * If you want to specify a field from a matched JSON structure, use '$.fieldName',
348 * and make sure the field is in the pattern (if only as '$.fieldName = *').
349 *
350 * If you want to specify a field from a matched space-delimited structure,
351 * use '$fieldName'.
352 *
353 * @default "1"
354 */
355 readonly metricValue?: string;
356 /**
357 * The value to emit if the pattern does not match a particular event.
358 *
359 * @default No metric emitted.
360 */
361 readonly defaultValue?: number;
362}
363export {};