---
title: "Add custom logs"
sidebar_label: "Add logs"
description: "How to add custom events to the Logs service"
sidebar_position: 2
---

import Formbricks from '@theme/MDXComponents/Formbricks'
import Tabs from '@theme/Tabs'
import TabItem from '@theme/TabItem'
import {TabItemLabel} from 'docs-kit/components'

# Add custom logs

Logs are automatically collected for [load balancer](/cloud-servers/load-balancers/manage/logs.mdx) and [Managed Databases](/managed-databases/) for which logging is enabled.However, you can add any custom logs to the Logs service from your storage.

You can add logs using:

* [AWS CLI](/logs/tools/aws-cli.mdx);
* or [SDK client](/logs/tools/sdk-client.mdx).

You can also configure [Fluent Bit](/logs/tools/fluent-bit.mdx) or [Vector](/logs/tools/vector.mdx) 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 [Principle of operation](/logs/about-logs.mdx#principle-of-operation) subsection of the [General information about the Logs service](/logs/about-logs.mdx).

<Tabs queryString="add-logs">
  <TabItem value="sdk-client">
    <TabItemLabel>
      SDK client
    </TabItemLabel>

    <Tabs>
      <TabItem value="python">
        <TabItemLabel>
          Python
        </TabItemLabel>

        1. Create or open the client script file.

        2. If there is no log group for adding events, add the code to create a new group to the script:

           ```python
           response = client.create_log_group(logGroupName = <log_group_name>)
           ```

           Specify `<log_group_name>` — the log group name, for example `user-log-group`.

        3. If there is no event stream for adding events, add the code to create a new stream to the script:

           ```python
           response = client.create_log_stream(
               logGroupName=<log_group_name>,
               logStreamName=<log_stream_name>
           )
           ```

           Specify:

           * `<log_group_name>` — the log group name, for example `user-log-group`;
           * `<log_stream_name>` — the event stream name, for example `user-log-stream`.

        4. Add the code to add events to the script:

           ```python
           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>` — name of the log group, for example, `user-log-group`. Events will be added to this group. You can see the list of existing log groups in the [Control Panel](https://my.selectel.ru/logs/default/logs);
           * `<log_stream_name>` — name of the event stream, for example, `user-log-stream`. Events will be added to this stream. You can see the list of existing event streams in the [Control Panel](https://my.selectel.ru/logs/default/logs).

        5. Run the script.
      </TabItem>

      <TabItem value="go">
        <TabItemLabel>
          Go
        </TabItemLabel>

        1. Create or open the client script file.

        2. If there is no log group for adding events, add the code to create a new group to the script:

           ```go
           resp, err := client.CreateLogGroup(ctx, &logs.CreateLogGroupInput{
               LogGroupName: aws.String("<log_group_name>"),
           })
           ```

           Specify `<log_group_name>` — the log group name, for example `user-log-group`.

        3. If there is no event stream for adding events, add the code to create a new stream to the script:

           ```go
           resp, err = client.CreateLogStream(context.TODO(), &cloudwatchlogs.CreateLogStreamInput{
               LogGroupName:  aws.String("<log_group_name>"),
               LogStreamName: aws.String("<log_stream_name>"),
           })
           ```

           Specify:

           * `<log_group_name>` — the log group name, for example `user-log-group`;
           * `<log_stream_name>` — the event stream name, for example `user-log-stream`.

        4. Add the code to add events to the script:

           ```go
           messages := []string{"<message>", "<message>"}

           curTime := time.Now().UnixMilli()

           var logEvents []cloudwatchlogs.InputLogEvent
           for _, msg := range messages {
               logEvents = append(logEvents, cloudwatchlogs.InputLogEvent{
                   Timestamp: aws.Int64(curTime),
                   Message:   aws.String(msg),
               })
           }

           input := &cloudwatchlogs.PutLogEventsInput{
               LogGroupName:  aws.String("<log_group_name>"),
               LogStreamName: aws.String("<log_stream_name>"),
               LogEvents:     logEvents,
           }

           resp, err := client.PutLogEvents(context.TODO(), input)
           if err != nil {
               fmt.Printf("Error sending logs: %v\n", err)
               return
           }

           fmt.Printf("Logs sent successfully. NextSequenceToken: %s\n", *resp.NextSequenceToken)
           ```

           Specify:

           * `<messages>` — event messages;
           * `<log_group_name>` — name of the log group, for example, `user-log-group`. Events will be added to this group. You can see the list of existing log groups in the [Control Panel](https://my.selectel.ru/logs/default/logs);
           * `<log_stream_name>` — name of the event stream, for example, `user-log-stream`. Events will be added to this stream. You can see the list of existing event streams in the [Control Panel](https://my.selectel.ru/logs/default/logs).

        5. Run the script.
      </TabItem>
    </Tabs>
  </TabItem>

  <TabItem value="aws-cli">
    <TabItemLabel>
      AWS CLI
    </TabItemLabel>

    1. If there is no log group for adding events, create a new group:

       ```bash
       aws logs create-log-group --log-group-name <log_group_name>
       ```

       Specify `<log_group_name>` — the log group name, for example `user-log-group`.

    2. If there is no event stream for adding events, create a new stream:

       ```bash
       aws logs create-log-stream --log-group-name <log_group_name> --log-stream-name <log_stream_name>
       ```

       Specify:

       * `<log_group_name>` — the name of the log group to which you want to add events, for example `user-log-group`;
       * `<log_stream_name>` — the name of the event stream to which you want to add events, for example `user-log-stream`.

    3. Add events to the event stream and log group:

       ```bash
       aws logs put-log-events --log-group-name <log_group_name> --log-stream-name <log_stream_name> --log-events timestamp=<timestamp>,message="<message>"
       ```

       Specify:

       * `<log_group_name>` — name of the log group to add events to, for example, `user-log-group`. You can see the list of existing log groups using the `aws logs describe-log-groups` command or in the [Control Panel](https://my.selectel.ru/logs/default/logs);
       * `<log_stream_name>` — name of the event stream to add events to, for example, `user-log-stream`. You can see the list of existing event streams using the `aws logs describe-log-streams --log-group-name <log_group_name>` command or in the [Control Panel](https://my.selectel.ru/logs/default/logs);
       * `<timestamp>` — event time in `timestamp` format;
       * `<message>` — the event message.
  </TabItem>
</Tabs>
