Add custom logs
Logs are automatically collected for load balancers and Managed Databases with logging enabled. However, you can add any custom logs to the Logs service from your storage.
You can add logs using:
- AWS CLI;
- or SDK client.
You can also set up the Fluent Bit or Vector tool and add logs using them.
You can add logs to an existing log group and event stream or to a new log group and stream. Learn more about groups and streams in the How it works section of the About Logs manual.
SDK client
AWS CLI
Python
Go
-
Create or open the client script file.
-
If there is no log group for adding events, add the code to create a new group to the script:
response = client.create_log_group(logGroupName = <log_group_name>)Specify
<log_group_name>— the log group name, for example,user-log-group. -
If there is no event stream for adding events, add the code to create a new stream to the script:
response = client.create_log_stream(logGroupName=<log_group_name>,logStreamName=<log_stream_name>)Specify:
<log_group_name>— log group name, for example,user-log-group;<log_stream_name>— event stream name, for example,user-log-stream.
-
Add the code to add events to the script:
messages = [<message>, <message>]cur_time = int(time.time() * 1000)log_events = []for message in messages:log_events.append({'timestamp': cur_time,'message': message})log_events = [{'timestamp': cur_time,'message': message}]kwargs = {'logGroupName': <log_group_name>,'logStreamName': <log_stream_name>,'logEvents': log_events}response = self.client.put_log_events(**kwargs)Specify:
<messages>— event messages;<log_group_name>— log group name, for example,user-log-group. Events will be added to this group. You can view the list of existing log groups in the Control Panel;<log_stream_name>— event stream name, for example,user-log-stream. Events will be added to this stream. You can view the list of existing event streams in the Control Panel.
-
Run the script.