-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Problem
The CloudWatch logger in the logging container generates excessive log entries, creating noise and making it difficult to find important information. Every connection and message is logged at INFO level, leading to redundant entries.
Solution
Reduce logging verbosity by changing INFO level logs to DEBUG for routine operations.
Code Changes
# cloudwatch_logger.py changes
def handle_client(conn, addr, cloudwatch, log_group, log_stream):
logger.debug(f"Connected by {addr}") # Changed from logger.info
try:
while True:
data = conn.recv(1024)
if not data:
break
message = data.decode()
# Only log the actual message being sent, not the content
logger.debug(f"Forwarding log to CloudWatch") # Changed from logger.info with message content
try:
cloudwatch.put_log_events(
logGroupName=log_group,
logStreamName=log_stream,
logEvents=[{
'timestamp': int(time.time() * 1000),
'message': message
}]
)
# Don't log the message content again - it's already in CloudWatch
# Removed redundant logger.info here
except Exception as e:
logger.error(f"Error sending log to CloudWatch: {e}")
except Exception as e:
logger.error(f"Error handling connection: {e}")
finally:
conn.close()
logger.debug(f"Connection closed for {addr}") # Changed from logger.infoBenefits
- Reduced log noise: Connection events logged at DEBUG level
- No duplicate logging: Message content only appears once (in CloudWatch)
- Cleaner logs: Easier to find actual errors and important events
- Better debugging: Can still enable DEBUG logging when needed
Impact
- Reduces Docker container log size
- Makes CloudWatch logs more readable
- Preserves all actual application logs while removing infrastructure noise
Metadata
Metadata
Assignees
Labels
No labels