I want to turn on logging for Redis slow log or engine log in an Amazon ElastiCache for Redis OSS or Amazon ElastiCache for Valkey cluster.
Resolution
Prerequisites:
The IAM policy must have the following permissions:
- logs:CreateLogDelivery
- logs:UpdateLogDelivery
- logs:DeleteLogDelivery
- logs:GetLogDelivery
- logs:ListLogDeliveries
Note: Valkey 7.x and later and Redis OSS cache clusters and replication groups that use engine version 6.0 and later support slow log. Valkey 7.x, and Redis OSS cache clusters and replication groups that use engine version 6.2 and later support engine log.
Turn on log delivery for your cluster
You can use ElastiCache APIs to turn on and configure log delivery when you create or modify a cluster. ElastiCache delivers log entries to the specified destination in either JSON or text format.
To turn on log delivery for Redis when you create or modify a cluster, see Specifying log delivery using the Console.
To turn on log delivery for Redis slow log, you must periodically retrieve a fixed number of slow log entries from the engine. The entries must be between the following two parameters that you define in the parameter group:
- slowlog-log-slower-than
- slowlog-max-len
When a command exceeds the slowlog-log-slower-than threshold, a new entry is added to the slow log. The slowlog-max-len configuration determines the maximum number of entries for the slow log.
NOTE: If no commands that take longer than slowlog-log-slower-than, then no slow logs are generated.
When you turn on log delivery for Redis engine log, the logs record internal operations of the Redis engine and provide additional insights. Insights include initiation of backup and critical events, such as failed synchronization.
When you turn on engine logs during cluster creation, you can view engine log entries that relate to successful synchronization between the primary and replica nodes.
However, when you turn on engine logs after cluster creation, the log stream might be empty because there's no specific activity at the Redis engine.
To confirm that you correctly configured Amazon CloudWatch Logs for your cluster, create a manual backup of your cluster. If the logs of the backup are sent to your CloudWatch log group, then you correctly configured CloudWatch Logs.
Related information
Log type and log format specifications
Contents of a slow log entry
Contents of an engine log entry