# FilterPattern

A collection of static methods to generate appropriate ILogPatterns.

- Source: [`aws-logs/lib/pattern.ts`](https://github.com/aws/aws-cdk/blob/v2.274.0/packages/aws-cdk-lib/aws-logs/lib/pattern.ts#L29)
- Type last changed: v2.179.0 · 18 Feb 2025

## Example

```ts
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

```ts
new FilterPattern()
```

## Methods

- `all(...patterns: JsonPattern[]): JsonPattern` (static) — A JSON log pattern that matches if all given JSON log patterns match.

- `allEvents(): IFilterPattern` (static) — A log pattern that matches all events.

- `allTerms(...terms: string[]): IFilterPattern` (static) — A log pattern that matches if all the strings given appear in the event.

  **Parameters**

  - `terms` — The words to search for.

- `any(...patterns: JsonPattern[]): JsonPattern` (static) — A JSON log pattern that matches if any of the given JSON log patterns match.

- `anyTerm(...terms: string[]): IFilterPattern` (static) — A log pattern that matches if any of the strings given appear in the event.

  **Parameters**

  - `terms` — The words to search for.

- `anyTermGroup(...termGroups: string[][]): IFilterPattern` (static) — 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.

  **Parameters**

  - `termGroups` — A list of term groups to search for.

- `booleanValue(jsonField: string, value: boolean): JsonPattern` (static) — A JSON log pattern that matches if the field exists and equals the boolean value.

  **Parameters**

  - `jsonField` — Field inside JSON.
  - `value` — The value to match.

- `exists(jsonField: string): JsonPattern` (static) — A JSON log patter that matches if the field exists.

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

  **Parameters**

  - `jsonField` — Field inside JSON.

- `isNull(jsonField: string): JsonPattern` (static) — A JSON log pattern that matches if the field exists and has the special value 'null'.

  **Parameters**

  - `jsonField` — Field inside JSON.

- `literal(logPatternString: string): IFilterPattern` (static) — Use the given string as log pattern.

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

  **Parameters**

  - `logPatternString` — The pattern string to use.

- `notExists(jsonField: string): JsonPattern` (static) — A JSON log pattern that matches if the field does not exist.

  **Parameters**

  - `jsonField` — Field inside JSON.

- `numberValue(jsonField: string, comparison: string, value: number): JsonPattern` (static) — 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

  **Parameters**

  - `jsonField` — Field inside JSON.
  - `comparison` — Comparison to carry out.
  - `value` — The numerical value to compare to.

- `regexValue(jsonField: string, comparison: string, value: string): JsonPattern` (static) — A JSON log pattern that compares against a Regex values.

  This pattern only matches if the event is a JSON event, and the indicated field inside
  compares with the regex value.

  Use '$' to indicate the root of the JSON structure. The comparison operator can only
  compare equality or inequality.

  For more information, see:

  https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/FilterAndPatternSyntax.html

  **Parameters**

  - `jsonField` — Field inside JSON.
  - `comparison` — Comparison to carry out.
  - `value` — The regex value to compare to.

- `spaceDelimited(...columns: string[]): SpaceDelimitedTextPattern` (static) — 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.

  **Parameters**

  - `columns` — The columns in the space-delimited log stream.

- `stringValue(jsonField: string, comparison: string, value: string): JsonPattern` (static) — 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

  **Parameters**

  - `jsonField` — Field inside JSON.
  - `comparison` — Comparison to carry out.
  - `value` — The string value to compare to.
