

# Monitoring a channel using Amazon CloudWatch Logs
<a name="monitoring-with-logs"></a>

MediaLive produces channel logs that contain detailed information about activity in a channel. The logs provide a sequential description of activity that occurs in the channel. These logs can be useful when the information in alerts ([Monitoring a channel or multiplex using Amazon CloudWatch Events](monitoring-via-cloudwatch.md)) does not provide enough information to resolve an issue on the channel. 

**Topics**
+ [About channel logs](monitoring-logs-about.md)
+ [Enabling channel encoder logs](enabling-disabling-logs.md)
+ [Working with logs](working-with-logs.md)

# About channel logs
<a name="monitoring-logs-about"></a>

MediaLive produces channel logs that contain detailed information about activity in a channel. The logs provide a sequential description of activity that occurs in the channel. These logs can be useful when the information in alerts ([Monitoring a channel or multiplex using Amazon CloudWatch Events](monitoring-via-cloudwatch.md)) does not provide enough information to resolve an issue on the channel. 

There are two sets of channel logs:
+ Channel encoder logs. You must [enable ](enabling-disabling-logs.md)these logs.
+ Channel as-run logs. MediaLive always produces these logs.

## Comparison of types of logs
<a name="monitoring-logs-comparison"></a>

**Features that are the same in both types of logs**  
Both types of logs are sent to Amazon CloudWatch Logs. You can use the standard features of CloudWatch Logs to view and manage the logs. For more information, see [Amazon CloudWatch Logs User Guide](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/WhatIsCloudWatchLogs.html).

**Features that are different in the two types of logs**  
The following table describes the differences between channel encoder logs and channel as-run logs.


|  | Encoder logs | As-run logs | 
| --- | --- | --- | 
| Trigger for creation | You must [enable these logs ](enabling-disabling-logs.md)in order for MediaLive to produce them. | MediaLive always produces these logs. | 
| Level of detail | You can set a logging level to control the detail collected. | You can't change the logging level. | 
| Cost | There is a cost for these logs, as part of your charges for Amazon CloudWatch Logs. See [Amazon CloudWatch Pricing](https://aws.amazon.com/cloudwatch/pricing/). Remember to [remove the logs](working-with-logs.md#manage-log-storage) after you delete the channel. | These logs are free. | 
| CloudWatch log stream | The log stream is named after the ARN/pipeline.  | The log stream is named after the ARN/pipeline with \$1as\$1run appended to the name. | 
| Automation | You should not automate any processing based on the wording in these logs because that wording is subject to change.(By comparison, you can automate based on the wording in alerts, which are accessed using CloudWatch Events, because the wording of alerts does not change.)  | You can automate based on the wording in these logs. | 

# Enabling channel encoder logs
<a name="enabling-disabling-logs"></a>

You enable channel encoder logs for an individual channel on the MediaLive console. You enable logging and set the logging level (error, warning, info, or debug) on a per channel basis. The channel must be idle in order to enable or disable logging. 

You don't need to enable as-run logs. MediaLive always produces these logs.

**To enable a channel encoder log (MediaLive console)**

1. If you are a returning user of MediaLive, check with your administrator that your deployment has been set up in AWS IAM to support channel logs.

1. Your administrator might instruct you to update the `MediaLiveAccessRole` permission in one of the channels. If you are given this instruction, you must [edit a channel](editing-deleting-channel.md#editing-a-channel) (choose any idle channel), [display the **Channel and input details** page](role-and-remember-arn.md), and choose the **Update** button. When the role is updated in one channel, the change applies to all channels. 

1. To enable encoder logs in a new channel, set up logging during [creation](creating-channel-scratch.md). 

   To enable encoder logs in an existing channel, [edit the channel](editing-deleting-channel.md#editing-a-channel); this channel must be idle.

   In both cases, on the **General settings** page, in the **Channel logging** section, choose **Logging**. Choose a level other than **DISABLED**. For more information, see [Logging](creating-a-channel-step3.md#channel-logging).

1. You or an administrator can also go into CloudWatch Logs and set an expiry date for the logs.

## Disabling channel encoder logs
<a name="disabling-logs"></a>

You disable the capture of encoder-related logging information for an individual channel on the MediaLive console. Edit the channel, and on the **General settings** page, on the **Channel logging** section, choose **Logging**. Set the level to **DISABLED**. 

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

You view both encoder logs and as-run logs on the CloudWatch Logs console, in the same way that you view logs for any service. 

You don't have to set up the logs, logging groups, or log streams on the CloudWatch Logs console because MediaLive automatically sets them up for you. 
+ Log group – The log group is always the following: **ElementalMediaLive**.
+ Log stream –The log stream is named as follows:
  + Encoder logs – named after the ARN/pipeline. 
  + As-run logs – named after the ARN/pipeline with `_as_run` appended.

  For example:

  `arn_aws_medialive_us-west-2_111122223333_channel_5106412_0`

  `arn_aws_medialive_us-west-2_111122223333_channel_5106412_0_as_run`

  Where `5106412` is the channel ID and `0` is the pipeline.

## Content of encoder logs
<a name="content-logs"></a>

The logs are in JSON format:

```
{
    "encoder_pipeline": 0,
    "severity": "I",
    "timestamp": "2018-05-21T16:36:41.650318",
    "channel_arn": "arn:aws:medialive:us-west-2:111122223333:channel:5106412",
    "logger_name": "",
    "message": "Probing input media..."
  },  
.
.
.
]
```

The data is the following:
+ `encoder_pipeline`: `0` or `1` (if the channel is set up as a [standard channel](channel-class.md) and therefore has two pipelines).
+ `severity`: A letter. The logging level (which you set when you enable logging) controls which severities could appear in logs. For more information, see [Log Levels and Verbosities](#log-levels).
+ `timestamp`: The time in ISO 8601 format: yyyy - mm - dd T hh : mm : ss : decimal fraction of second.
+ `channel_arn`: The ARN plus the channel ID. In the preceding example, the channel has ID `5106412`.
+ `logger_name`: This might be blank or might specify a name that ties a series of related messages together.
+ `message`: The message. Remember that the wording is subject to change, so you should not automate against it.

## Log levels and verbosities for encoder logs
<a name="log-levels"></a>

To use this table, find a level in the first column then read across to identify the message severities that will appear in the logs with this logging level.


| Level | Debug messages | Info messages | Warning messages | Critical messages | Fatal messages | 
| --- | --- | --- | --- | --- | --- | 
| DEBUG | Yes | Yes | Yes | Yes | Yes | 
| INFO |  | Yes | Yes | Yes | Yes | 
| WARNING |  |  | Yes | Yes | Yes | 
| ERROR |  |  |  | Yes | Yes | 

## Managing log storage
<a name="manage-log-storage"></a>

When you delete a channel, the associated logs remain in CloudWatch Logs. You will continue to be charged for their storage until you delete them. To delete logs, change the log data retention. All the data that is older than the retention setting that you specify will be deleted. For more information, see [Amazon CloudWatch Logs User Guide](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/Working-with-log-groups-and-streams.html). The **Log group **for the logs is **ElementalMediaLive**. 