class FilterPattern
Language | Type name |
---|---|
.NET | Amazon.CDK.AWS.Logs.FilterPattern |
Go | github.com/aws/aws-cdk-go/awscdk/v2/awslogs#FilterPattern |
Java | software.amazon.awscdk.services.logs.FilterPattern |
Python | aws_cdk.aws_logs.FilterPattern |
TypeScript (source) | aws-cdk-lib » aws_logs » FilterPattern |
A collection of static methods to generate appropriate ILogPatterns.
Example
import * as destinations from 'aws-cdk-lib/aws-logs-destinations';
declare const fn: lambda.Function;
declare const logGroup: logs.LogGroup;
new logs.SubscriptionFilter(this, 'Subscription', {
logGroup,
destination: new destinations.LambdaDestination(fn),
filterPattern: logs.FilterPattern.allTerms("ERROR", "MainThread"),
filterName: 'ErrorInMainThread',
});
Initializer
new FilterPattern()
Methods
Name | Description |
---|---|
static all(...patterns) | A JSON log pattern that matches if all given JSON log patterns match. |
static all | A log pattern that matches all events. |
static all | A log pattern that matches if all the strings given appear in the event. |
static any(...patterns) | A JSON log pattern that matches if any of the given JSON log patterns match. |
static any | A log pattern that matches if any of the strings given appear in the event. |
static any | A log pattern that matches if any of the given term groups matches the event. |
static boolean | A JSON log pattern that matches if the field exists and equals the boolean value. |
static exists(jsonField) | A JSON log patter that matches if the field exists. |
static is | A JSON log pattern that matches if the field exists and has the special value 'null'. |
static literal(logPatternString) | Use the given string as log pattern. |
static not | A JSON log pattern that matches if the field does not exist. |
static number | A JSON log pattern that compares numerical values. |
static space | A space delimited log pattern matcher. |
static string | A JSON log pattern that compares string values. |
static all(...patterns)
public static all(...patterns: JsonPattern[]): JsonPattern
Parameters
- patterns
Json
Pattern
Returns
A JSON log pattern that matches if all given JSON log patterns match.
Events()
static allpublic static allEvents(): IFilterPattern
Returns
A log pattern that matches all events.
Terms(...terms)
static allpublic static allTerms(...terms: string[]): IFilterPattern
Parameters
- terms
string
— The words to search for.
Returns
A log pattern that matches if all the strings given appear in the event.
static any(...patterns)
public static any(...patterns: JsonPattern[]): JsonPattern
Parameters
- patterns
Json
Pattern
Returns
A JSON log pattern that matches if any of the given JSON log patterns match.
Term(...terms)
static anypublic static anyTerm(...terms: string[]): IFilterPattern
Parameters
- terms
string
— The words to search for.
Returns
A log pattern that matches if any of the strings given appear in the event.
TermGroup(...termGroups)
static anypublic static anyTermGroup(...termGroups: string[][]): IFilterPattern
Parameters
- termGroups
string[]
— A list of term groups to search for.
Returns
A log pattern that matches if any of the given term groups matches the event.
A term group matches an event if all the terms in it appear in the event string.
Value(jsonField, value)
static booleanpublic static booleanValue(jsonField: string, value: boolean): JsonPattern
Parameters
- jsonField
string
— Field inside JSON. - value
boolean
— The value to match.
Returns
A JSON log pattern that matches if the field exists and equals the boolean value.
static exists(jsonField)
public static exists(jsonField: string): JsonPattern
Parameters
- jsonField
string
— Field inside JSON.
Returns
A JSON log patter that matches if the field exists.
This is a readable convenience wrapper over 'field = *'
Null(jsonField)
static ispublic static isNull(jsonField: string): JsonPattern
Parameters
- jsonField
string
— Field inside JSON.
Returns
A JSON log pattern that matches if the field exists and has the special value 'null'.
static literal(logPatternString)
public static literal(logPatternString: string): IFilterPattern
Parameters
- logPatternString
string
— The pattern string to use.
Returns
Use the given string as log pattern.
See https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/FilterAndPatternSyntax.html for information on writing log patterns.
Exists(jsonField)
static notpublic static notExists(jsonField: string): JsonPattern
Parameters
- jsonField
string
— Field inside JSON.
Returns
A JSON log pattern that matches if the field does not exist.
Value(jsonField, comparison, value)
static numberpublic static numberValue(jsonField: string, comparison: string, value: number): JsonPattern
Parameters
- jsonField
string
— Field inside JSON. - comparison
string
— Comparison to carry out. - value
number
— The numerical value to compare to.
Returns
A JSON log pattern that compares numerical values.
This pattern only matches if the event is a JSON event, and the indicated field inside compares with the value in the indicated way.
Use '$' to indicate the root of the JSON structure. The comparison operator can only compare equality or inequality. The '*' wildcard may appear in the value may at the start or at the end.
For more information, see:
https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/FilterAndPatternSyntax.html
Delimited(...columns)
static spacepublic static spaceDelimited(...columns: string[]): SpaceDelimitedTextPattern
Parameters
- columns
string
— The columns in the space-delimited log stream.
Returns
A space delimited log pattern matcher.
The log event is divided into space-delimited columns (optionally enclosed by "" or [] to capture spaces into column values), and names are given to each column.
'...' may be specified once to match any number of columns.
Afterwards, conditions may be added to individual columns.
Value(jsonField, comparison, value)
static stringpublic static stringValue(jsonField: string, comparison: string, value: string): JsonPattern
Parameters
- jsonField
string
— Field inside JSON. - comparison
string
— Comparison to carry out. - value
string
— The string value to compare to.
Returns
A JSON log pattern that compares string values.
This pattern only matches if the event is a JSON event, and the indicated field inside compares with the string value.
Use '$' to indicate the root of the JSON structure. The comparison operator can only compare equality or inequality. The '*' wildcard may appear in the value may at the start or at the end.
For more information, see:
https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/FilterAndPatternSyntax.html