Working with CloudWatch Logs in Visual Studio - AWS Toolkit for Visual Studio

Working with CloudWatch Logs in Visual Studio

Amazon CloudWatch Logs integration allows you to monitor, store, and access CloudWatch Logs from the AWS Toolkit for Visual Studio. Having access to CloudWatch Logs features—without the need to leave your IDE—improves efficiency by simplifying the CloudWatch Logs development process and reducing disruptions to your work flow. The following topics describe how to work with the basic features and functions of the CloudWatch Logs integration.

CloudWatch Log Groups

A log group is a group of log streams that share the same retention, monitoring, and access control settings. There is no limit on the number of log streams that can belong to one log group.

Viewing Log Groups

The View Log Groups feature displays a list of log groups in the CloudWatch Log Groups Explorer.

To access the View Log Groups feature and open the CloudWatch Log Groups Explorer, complete the following steps.

  1. From the AWS Explorer, expand Amazon CloudWatch.

  2. Double-click Log Groups or open the context menu (right-click) and select View, to open the CloudWatch Log Groups Explorer.

    Note

    The CloudWatch Log Groups Explorer will open in the same window location as the Solutions Explorer.

Filtering Log Groups

Your individual account is able to contain thousands of different log groups. To simplify your search for specific groups, use the filtering feature described below.

  1. From the CloudWatch Log Groups Explorer, set your cursor in the search bar located at the top of the window.

  2. Start typing a prefix related to the log groups that you're looking for.

  3. CloudWatch Log Groups Explorer is automatically updated to show results matching the search terms you specified in the previous step.

Delete Log Groups

To delete a specific log group, refer to the following procedure.

  1. From the CloudWatch Log Groups Explorer, right-click the Log Group that you want to delete.

  2. When prompted, confirm that you want to delete the currently selected Log Group.

  3. Choosing the Yes button deletes the selected log group, then refreshes the CloudWatch Log Groups Explorer.

Refresh Log Groups

To refresh the current list of log groups displayed in the CloudWatch Log Groups Explorer, choose the Refresh icon button located in the toolbar.

Copy Log Group ARN

To copy the ARN of a specific log group, complete the steps described below.

  1. From the CloudWatch Log Groups Explorer, right-click the Log Group you want to copy an ARN from.

  2. Choose the Copy ARN option from the menu.

  3. The ARN is now copied to your local clipboard and ready to paste.

CloudWatch Log Streams

A log stream is a sequence of log events that share the same source.

Note

When viewing log streams, be aware of the following properties:

  • By default the log streams are sorted by the most-recent event time stamp.

  • Columns associated with a log stream can be sorted in either ascending or descending order, by toggling the caret located in the column headers.

  • Filtered entries can only be sorted by Log Stream Name.

Viewing Log Streams

  1. From the CloudWatch Log Groups Explorer double-click a Log Group, or right-click a log group and select View Log Stream from the context menu.

  2. A new tab will open in the document window, which contains a list of log streams associated with your log group.

Filtering Log Streams

  1. From the Log Streams tab, in the document window, set your cursor in the search bar.

  2. Start typing a prefix related to the log stream that you're looking for.

  3. As you type, the current display automatically updates to filter your Log Streams by your input.

Refresh Log Streams

To refresh the current list of log streams displayed in the document window, choose the Refresh icon button, located in the toolbar, next to the search bar.

Copy Log Streams ARN

To copy the ARN of a specific log stream, complete the steps described below.

  1. From the Log Streams tab, in the document window, right-click the log stream you want to copy an ARN from.

  2. Choose the Copy ARN option from the menu.

  3. The ARN is now copied to your local clipboard and ready to paste.

Download Log Streams

The Export Log Stream feature downloads and stores the selected log stream locally, where it can be accessed by custom tools and software for additional processing.

  1. From the Log Streams tab, in the document window, right-click the log stream you want to download.

  2. Choose Export Log Stream to open the Export to a text file dialog.

  3. Choose the location where you want to store the file locally and specify a name in the provided text field.

  4. Confirm the download by selecting OK. The status of the download is displayed in the Visual Studio Task Status Center

CloudWatch Log Events

Log events are records of activity recorded by the application or resource being monitored by CloudWatch.

Log Event actions

Log events are displayed as a table. By default, the events are sorted from the oldest event to the most recent.

The following actions are associated with log events in Visual Studio:

  • Wrapped-text mode: You can toggle wrapped-text by clicking an event.

  • Text-wrap button: located in the document window toolbar, this button toggles text-wrap on and off, for all entries.

  • Copy messages to your clipboard: select the messages you want to copy, then right-click the selection and choose Copy (keyboard shortcut Ctrl + C).

Viewing Log Events

  1. From the document window, choose a tab that contains a list of log streams.

  2. Double-click a log stream, or right-click a log stream and select View Log Stream from the menu.

  3. A new log event tab will open in the document window, which contains a table of log events associated with your chosen log stream.

Filtering Log Events

There are three ways for you to filter log events: by content, time range, or both. To filter your log events by both content and time range, start by filtering your messages by either content or time range, then filter those results by the other method.

To filter your log events by content:

  1. From the log event tab, in the document window, set your cursor in the search bar, located at the top of the window.

  2. Start typing a term or phrase related to the log events that you're searching for.

  3. As you type, the current display automatically begins to filter your log events.

    Note

    Filter patterns are case sensitive. You can improve search results by enclosing exact terms, and phrases, with non-alphanumeric characters in double quotation marks (*""*). For more detailed information about filter patterns, see the Filter and Pattern Syntax topic in the Amazon CloudWatch guide.

To view log events generated during a specific time range:

  1. From the log event tab, in the document window, choose the Calendar icon button, located in the toolbar.

  2. Using the provided fields, specify the time range that you want to search.

  3. The filtered results update automatically as you specify the date and time constraints.

    Note

    The Clear Filter option clears all of your current date-and-time filter selections.

Refresh Log Events

To refresh the current list of log events displayed in the log event tab, choose the Refresh icon button, located in the toolbar.

Additional access to CloudWatch Logs

You can access CloudWatch Logs associated with other AWS services and resources directly from the AWS Toolkit in Visual Studio.

Lambda

To view log streams that are associated with a Lambda function:

Note

Your Lambda execution role must have appropriate permissions to send logs to CloudWatch Logs. For more information about the Lambda permissions required for CloudWatch Logs, see the https://docs.aws.amazon.com/lambda/latest/dg/monitoring-cloudwatchlogs.html#monitoring-cloudwatchlogs-prereqs

  1. From the AWS Toolkit Explorer, expand Lambda.

  2. right-click the function you want to view, then choose View Logs to open the associated log streams in the document window.

To view log streams using the Lambda integration function view:

  1. From the AWS Toolkit Explorer, expand Lambda.

  2. right-click the function you want to view, then choose View Function to open the function view in the document window.

  3. From the function view, switch to the Logs tab, the log streams associated with the chosen Lambda function are displayed.

ECS

To view log resources that are associated with an ECS Task Container, complete the following procedure.

Note

In order for the Amazon ECS service to send logs to CloudWatch, each container for a given Amazon ECS Task must meet the required configuration. For additional information about the required set up and configurations, please see the guide Using the AWS Logs Log Driver.

  1. From the AWS Toolkit Explorer, expand Amazon ECS.

  2. Choose the Amazon ECS Cluster that you want to view to open a new ECS Cluster tab, in the document window.

  3. From the navigation menu, located on the left side of the ECS Cluster tab, choose Tasks to list all tasks associated with the cluster.

  4. From the Tasks display, select a task and choose the View Logs link, located in the bottom-left corner.

    Note

    This display lists all tasks contained in the cluster, the View Logs link is only visible for each task that meets the required logs configuration.

    • If a Task is only associated with a single container, the View Logs link opens that container's log stream.

    • If a Task is associated with multiple containers, the View Logs link opens the View CloudWatch Logs for ECS Task dialog, use the Container: drop-down menu to choose the container you want to view Logs for, then choose OK.

  5. A new tab opens in the document window displaying the log streams associated with your container selection.