aws-cdk-lib.aws_logs.FilterPattern

class FilterPattern

LanguageType name
.NETAmazon.CDK.AWS.Logs.FilterPattern
Gogithub.com/aws/aws-cdk-go/awscdk/v2/awslogs#FilterPattern
Javasoftware.amazon.awscdk.services.logs.FilterPattern
Pythonaws_cdk.aws_logs.FilterPattern
TypeScript (source)aws-cdk-lib » aws_logs » FilterPattern

A collection of static methods to generate appropriate ILogPatterns.

Example

// Search for all events where the component field is equal to
// "HttpServer" and either error is true or the latency is higher
// than 1000.
const pattern = logs.FilterPattern.all(
  logs.FilterPattern.stringValue('$.component', '=', 'HttpServer'),
  logs.FilterPattern.any(
    logs.FilterPattern.booleanValue('$.error', true),
    logs.FilterPattern.numberValue('$.latency', '>', 1000),
  ),
);

Initializer

new FilterPattern()

Methods

NameDescription
static all(...patterns)A JSON log pattern that matches if all given JSON log patterns match.
static allEvents()A log pattern that matches all events.
static allTerms(...terms)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 anyTerm(...terms)A log pattern that matches if any of the strings given appear in the event.
static anyTermGroup(...termGroups)A log pattern that matches if any of the given term groups matches the event.
static booleanValue(jsonField, value)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 isNull(jsonField)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 notExists(jsonField)A JSON log pattern that matches if the field does not exist.
static numberValue(jsonField, comparison, value)A JSON log pattern that compares numerical values.
static spaceDelimited(...columns)A space delimited log pattern matcher.
static stringValue(jsonField, comparison, value)A JSON log pattern that compares string values.

static all(...patterns)

public static all(...patterns: JsonPattern[]): JsonPattern

Parameters

  • patterns JsonPattern

Returns

  • JsonPattern

A JSON log pattern that matches if all given JSON log patterns match.


static allEvents()

public static allEvents(): IFilterPattern

Returns

  • IFilterPattern

A log pattern that matches all events.


static allTerms(...terms)

public static allTerms(...terms: string[]): IFilterPattern

Parameters

  • terms string — The words to search for.

Returns

  • IFilterPattern

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 JsonPattern

Returns

  • JsonPattern

A JSON log pattern that matches if any of the given JSON log patterns match.


static anyTerm(...terms)

public static anyTerm(...terms: string[]): IFilterPattern

Parameters

  • terms string — The words to search for.

Returns

  • IFilterPattern

A log pattern that matches if any of the strings given appear in the event.


static anyTermGroup(...termGroups)

public static anyTermGroup(...termGroups: string[][]): IFilterPattern

Parameters

  • termGroups string[] — A list of term groups to search for.

Returns

  • IFilterPattern

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.


static booleanValue(jsonField, value)

public static booleanValue(jsonField: string, value: boolean): JsonPattern

Parameters

  • jsonField string — Field inside JSON.
  • value boolean — The value to match.

Returns

  • JsonPattern

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

  • JsonPattern

A JSON log patter that matches if the field exists.

This is a readable convenience wrapper over 'field = *'


static isNull(jsonField)

public static isNull(jsonField: string): JsonPattern

Parameters

  • jsonField string — Field inside JSON.

Returns

  • JsonPattern

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

  • IFilterPattern

Use the given string as log pattern.

See https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/FilterAndPatternSyntax.html for information on writing log patterns.


static notExists(jsonField)

public static notExists(jsonField: string): JsonPattern

Parameters

  • jsonField string — Field inside JSON.

Returns

  • JsonPattern

A JSON log pattern that matches if the field does not exist.


static numberValue(jsonField, comparison, value)

public 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

  • JsonPattern

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


static spaceDelimited(...columns)

public static spaceDelimited(...columns: string[]): SpaceDelimitedTextPattern

Parameters

  • columns string — The columns in the space-delimited log stream.

Returns

  • SpaceDelimitedTextPattern

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.


static stringValue(jsonField, comparison, value)

public 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

  • JsonPattern

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