

# Working with CloudWatch Logs by using the AWS Toolkit for JetBrains
<a name="building-cloudwatch"></a>

Amazon CloudWatch Logs enables you to centralize the logs from all of your systems, applications, and AWS services that you use, in a single, highly scalable service. You can then easily view them, search them for specific error codes or patterns, filter them based on specific fields, or archive them securely for future analysis. For more information, see [What Is Amazon CloudWatch Logs?](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/WhatIsCloudWatchLogs.html) in the *Amazon CloudWatch User Guide*.

The following topics describe how to use the AWS Toolkit for JetBrains to work with CloudWatch Logs in an AWS account.

**Topics**
+ [Viewing CloudWatch log groups and log streams](viewing-CloudWatch-logs.md)
+ [Working with CloudWatch log events](working-CloudWatch-log-events.md)
+ [Working with CloudWatch Logs Insights](cloudwatch-log-insights.md)

# Viewing CloudWatch log groups and log streams by using the AWS Toolkit for JetBrains
<a name="viewing-CloudWatch-logs"></a>

A *log stream* is a sequence of log events that share the same source. Each separate source of logs into CloudWatch Logs makes up a separate log stream.

 A *log group* is a group of log streams that share the same retention, monitoring, and access control settings. You can define log groups and specify which streams to put into each group. There is no limit on the number of log streams that can belong to one log group. 

For more information, see [Working with Log Groups and Log Streams ](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Working-with-log-groups-and-streams.html) in the *Amazon CloudWatch User Guide*.

**Topics**
+ [Viewing log groups and log streams with the **CloudWatch Logs** node](#viewing-log-groups)
+ [Viewing log streams with the **Lambda** node](#viewing-lamba-log-groups)
+ [Viewing log streams with the **Amazon ECS** node](#viewing-ecs-log-groups)

## Viewing log groups and log streams with the **CloudWatch Logs** node
<a name="viewing-log-groups"></a>

1. Open AWS Explorer, if it isn't already open.

1. Click the **CloudWatch Logs** node to expand the list of log groups.

   The log groups for the [current AWS Region](setup-region.md#setup-region-current-region) are displayed under the **CloudWatch Logs** node.

1. To view the log streams in a log group, do one of the following:
   + Double-click the name of the log group.
   + Right-click the name of the log group, and then choose **View Log Streams**.

   The log group's contents are displayed in the **Log Streams** pane. For information about interacting with the log events in each stream, see [Working with CloudWatch log eventsWorking with CloudWatch Logs Insights](working-CloudWatch-log-events.md).  
![\[Viewing log streams in a CloudWatch log group in AWS Explorer\]](http://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/images/cloudwatch-view-log-streams.png)

## Viewing log streams with the **Lambda** node
<a name="viewing-lamba-log-groups"></a>

You can view CloudWatch Logs for AWS Lambda functions by using the **Lambda** node in AWS Explorer. 

**Note**  
You can also view log streams for all AWS services, including Lambda functions, using the **CloudWatch Logs** node in AWS Explorer. We recommend using the **Lambda** node, however, for an overview of log data specific to Lambda functions.

1. Open AWS Explorer, if it isn't already open.

1. Click the **Lambda** node to expand the list of Lambda functions.

   The Lambda functions for the [current AWS Region](setup-region.md#setup-region-current-region) are displayed beneath the **Lambda** node.

1. Right-click a Lambda function, and then choose **View Log Streams**.

   The log streams for the function are displayed in the **Log Streams** pane. For information about interacting with the log events in each stream, see [Working with CloudWatch log eventsWorking with CloudWatch Logs Insights](working-CloudWatch-log-events.md).

## Viewing log streams with the **Amazon ECS** node
<a name="viewing-ecs-log-groups"></a>

You can view CloudWatch Logs for clusters and containers that are run and maintained in Amazon Elastic Container Service by using the **Amazon ECS** node in AWS Explorer 

**Note**  
You can also view log groups for all AWS services, including Amazon ECS, using the **CloudWatch Logs** node in AWS Explorer. We recommend using the **Amazon ECS** node, however, for an overview of log data specific to Amazon ECS clusters and containers.

1. Open AWS Explorer, if it isn't already open.

1. Click the **Amazon ECS** node to expand the list of Amazon ECS clusters.

   The Amazon ECS clusters for the [current AWS Region](setup-region.md#setup-region-current-region) are displayed beneath the **Amazon ECS** node.

1. Right-click a cluster, and then choose **View Log Streams**.

   The log streams for the cluster are displayed in the **Log Streams** pane.

1. To view log streams for a specific container, click a cluster to expand its list of registered containers.

   The containers registered for the cluster are displayed beneath.

1. Right-click a container, and then choose **View Container Log Stream**.

   The log streams for the container are displayed in the **Log Streams** pane. For information about interacting with the log events for clusters and containers, see [Working with CloudWatch log eventsWorking with CloudWatch Logs Insights](working-CloudWatch-log-events.md). 

# Working with CloudWatch log events in log streams by using the AWS Toolkit for JetBrains
<a name="working-CloudWatch-log-events"></a>

After you've opened the **Log Steams** pane, you can access the log events in each stream. Log events are records of activity recorded by the application or resource being monitored.

**Topics**
+ [Viewing and filtering log events in a stream](#viewing-log-events)
+ [Working with log actions](#working-with-log-actions)
+ [Exporting CloudWatch log events to a file or an editor](#exporting-CW-logs)

## Viewing and filtering log events in a stream
<a name="viewing-log-events"></a>

When you open a log stream, the **Log Events** pane displays that stream's sequence of log events.

1. To find a log stream to view, open the **Log Streams** pane (see [Viewing CloudWatch log groups and log streams](viewing-CloudWatch-logs.md)).
**Note**  
You can use pattern matching to locate a stream in a list. Click the **Log Streams** pane and start entering text. The first log stream name with text that matches yours is highlighted. You can also reorder the list by clicking the top of the **Last Event Time** column.

1. Double-click a log stream to view its sequence of log events.

   The **Log Events** pane displays the log events that make up the log stream. 

1. To filter the log events according to content, enter text in the **Filter logstream** field and press **Return**. 

    The results are log events containing text that's a case-sensitive match with your filter text. The filter searches the complete log stream, including events not displayed on the screen.
**Note**  
You can also use pattern matching to locate a log event in the pane. Click the **Log Events** pane and start entering text. The first log event with text that matches yours is highlighted. Unlike with **Filter logstream** search, only on-screen events are checked.

1. To filter log events according to time, right-click a log event, and then choose **Show Logs Around**.

    You can select **One Minute**, **Five Minutes**, or **Ten Minutes**. For example, if you select **Five Minutes**, the filtered list shows only log events that occurred five minutes before and after the selected entry.  
![\[Viewing and filtering log actions on the Log Events pane.\]](http://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/images/cloudwatch-filter-log-events.png)

On the left of the **Log Events** pane, the [log actions](#working-with-log-actions) offer more ways to interact with log events.

## Working with log actions
<a name="working-with-log-actions"></a>

On the left of the **Log Events** pane, four log actions allow you to refresh, edit, tail, and wrap CloudWatch log events.

![\[Viewing log actions on the Log Events pane.\]](http://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/images/cloudwatch-log-actions.png)


1. To find log events to interact with, [open the **Log Streams**](#viewing-log-events) pane.

1. Choose one of the following log actions:
   + **Refresh** – Updates the list with log events that occurred after the **Log Events** pane was opened.
   + **Open in Editor** – Opens the on-screen log events in the IDE's default editor. 
**Note**  
This action exports only on-screen log events to the IDE editor. To view all the stream's events in the editor, choose the [**Export Log Stream**](#exporting-CW-logs) option. 
   + **Tail logs** – Streams new logs events to the **Log Events** pane. This is a useful feature for continuous updates on longer-running services such as Amazon EC2 instances and AWS CodeBuild builds. 
   + **Wrap logs** – Displays log event text on multiple lines if the size of the pane hides longer entries.

## Exporting CloudWatch log events to a file or an editor
<a name="exporting-CW-logs"></a>

Exporting a CloudWatch log stream enables you to open its log events in the IDE's default editor or download them to a local folder.

1. To find a log stream to access, [open the **Log Streams**](#viewing-log-events) pane.

1. Right-click a log stream, and then choose **Export Log Stream**, **Open in Editor** or **Export Log Stream**, **Save to a File**.
   + **Open in Editor** –Opens the log events that make up the selected stream in the IDE's default editor.
**Note**  
This option exports all events in the log stream to the IDE editor.
   + **Save to a File** – Opens the **Download Log Stream** dialog box. This enables you to select a download folder and rename the file containing the log events.

# Working with CloudWatch Logs Insights by using the AWS Toolkit for JetBrains
<a name="cloudwatch-log-insights"></a>

You can use the AWS Toolkit for JetBrains to work with CloudWatch Logs Insights. CloudWatch Logs Insights enables you to interactively search and analyze your log data in Amazon CloudWatch Logs. For more information, see [Analyzing Log Data with CloudWatch Logs Insights](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/AnalyzingLogData.html) in the *Amazon CloudWatch Logs User Guide*.

## IAM permissions for CloudWatch Logs Insights
<a name="iam-permissions-for-cwlog-insights"></a>

 You need the following permissions to run and view CloudWatch Logs Insights query results: 

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement" : [
    {
      "Effect" : "Allow",
      "Action" : [
        "logs:StartQuery",
        "logs:GetQueryResults",
        "logs:GetLogRecord",
        "logs:describeLogGroups",
        "logs:describeLogStreams"
      ],
      "Resource" : "*"
    }
  ]
}
```

------

The following permission is not required but will allow the AWS Toolkit for JetBrains to automatically stop any currently running queries when you close the associated results pane or IDE. 

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement" : [
    {
      "Effect" : "Allow",
      "Action" : [
        "logs:StopQuery"
      ],
      "Resource" : "*"
    }
  ]
}
```

------

## Working with CloudWatch Logs Insights
<a name="working-with-cwlog-insights"></a>

**To open the CloudWatch Logs Insights query editor**

1. Open AWS Explorer.

1.  Double-click the **CloudWatch Logs** node to expand the list of log groups. 

1.  Right-click on the log group you want to open, and then choose **Open Query Editor**. 

**To start a CloudWatch Logs Insights query**

1. In the **Query Log Groups** window, change the query parameters as desired.

   You can choose a time range by date or relative time.

   The **Query Log Groups** field accepts the CloudWatch Logs Insights Query Syntax. For more information, see [CloudWatch Logs Insights Query Syntax](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/CWL_QuerySyntax.html) in the *Amazon CloudWatch Logs User Guide*.

1.  Choose **Execute** to begin the query. 

**To save a CloudWatch Logs Insights query**

1. Type a query name. 

1.  Choose **Save Query**. 

    The selected log groups and query are saved to your AWS account. Time ranges are not saved. 

   You can retrieve and reuse saved queries from the CloudWatch Logs Insights AWS Management Console page.

**To retrieve a saved CloudWatch Logs Insights query**

1.  In the **Query Log Groups** window, choose **Retrieve Saved Queries**. 

1.  Choose the desired query and choose **OK**. 

   The selected log groups and query replace anything in the existing dialog.

**To navigate through query results**
+  In the CloudWatch Logs Insights **Query Results** window, in the top right corner, choose **Open Query Editor**. 

**To view an individual log record**
+  In the query results pane, double-click a row to open a new tab with details about that log record. 

   You can also navigate to the log record's associated log stream by choosing **View Log Stream** in the top right corner. 