Yandex Cloud
Search
Contact UsGet started
  • Blog
  • Pricing
  • Documentation
  • All Services
  • System Status
    • Featured
    • Infrastructure & Network
    • Data Platform
    • Containers
    • Developer tools
    • Serverless
    • Security
    • Monitoring & Resources
    • ML & AI
    • Business tools
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Customer Stories
    • Gateway to Russia
    • Cloud for Startups
    • Education and Science
  • Blog
  • Pricing
  • Documentation
Yandex project
© 2025 Yandex.Cloud LLC
Yandex Serverless Containers
  • Comparison with other Yandex Cloud services
    • All guides
    • Getting an IAM token for a service account using a container
      • Making a revision active
      • Changing the container operation mode
      • Adding environment variables
      • Specifying a cloud network
      • Transferring Yandex Lockbox secrets
      • Viewing monitoring charts
        • Viewing logs
        • Writing logs
      • Migration to the ru-central1-d availability zone
      • Deleting a container
    • Viewing operations with service resources
  • Access management
  • Pricing policy
  • Terraform reference
  • Audit Trails events
  • Release notes
  • FAQ

In this article:

  • Structured logs
  • Applications and Dockerfile examples
  1. Step-by-step guides
  2. Managing a container
  3. Managing logs
  4. Writing logs

Writing to the container execution log

Written by
Yandex Cloud
Updated at May 5, 2025
  • Structured logs
    • Applications and Dockerfile examples

Note

Logging is not free of charge. For more information, see the Yandex Cloud Logging documentation.

Management console
CLI
Terraform
API
  1. In the management console, select the folder with your container.
  2. Select Serverless Containers.
  3. Select the container you want to configure logging for.
  4. Go to the Editor tab.
  5. Under Logging, select the following in the Destination field:
    • Not specified: To disable logging.
    • Folder: To write logs to the default log group for the folder the container is in.
      1. (Optional) In the Min. logging level field, select the minimum logging level.
    • Log group: To write logs to a custom log group.
      1. (Optional) In the Min. logging level field, select the minimum logging level.
      2. In the Log group field, select the log group to write the logs to. If you do not have a log group, create one.
  6. At the top of the page, click Create revision.

If you set the minimum logging level, logs of that level and higher will be written to the execution log. With no minimum logging level set, all container logs will be written to the execution log.

If you do not have the Yandex Cloud CLI yet, install and initialize it.

The folder specified when creating the CLI profile is used by default. To change the default folder, use the yc config set folder-id <folder_ID> command. You can specify a different folder using the --folder-name or --folder-id parameter.

Logging destinationLogging destination

If a custom log group is not specified in the container revision parameters or logging is not turned off, the container automatically writes all logs to the default log group for the folder it resides in.

To write logs to a custom log group, provide the log group ID in the --log-group-id parameter when creating a container revision. The log group must reside in the same folder as the container.

Minimum logging levelMinimum logging level

To set a minimum logging level, specify it in the --min-log-level parameter when creating a container revision.

If you set the minimum logging level, logs of that level and higher will be written to the execution log. With no minimum logging level set, all container logs will be written to the execution log.

Disabling loggingDisabling logging

To disable logging, specify the --no-logging parameter when creating a container revision.

Command exampleCommand example

To write logs to a custom log group, run this command:

yc serverless container revision deploy \
  --container-id <container_ID> \
  --image <Docker_image_URL> \
  --service-account-id <service_account_ID> \
  --log-folder-id <folder_ID> \
  --min-log-level <minimum_logging_level>

Where:

  • --container-id: Container ID. To find out the ID, get a list of containers.
  • --image: Docker image URL.
  • --service-account-id: ID of the service account with permissions to download a Docker image.
  • --log-group-id: ID of the log group to write logs to.
  • --min-log-level: Minimum logging level. This is an optional parameter.

Result:

done (5s)
id: bba9vrtrjlld********
container_id: bbanb9mvu1dl********
created_at: "2024-05-08T07:22:45.378Z"
image:
  image_url: cr.yandex/crprip91p1q9********/ubuntu:hello
  image_digest: sha256:aa55c46fba9b14b8d8de16e2f8a07d716edfb1dbbb9433b827214ad2********
resources:
  memory: "1073741824"
  cores: "1"
  core_fraction: "100"
execution_timeout: 3s
service_account_id: ajeh91ebakk1********
status: ACTIVE
log_options:
  log_group_id: e23824sf51g5********
  min_level: ERROR

With Terraform, you can quickly create a cloud infrastructure in Yandex Cloud and manage it using configuration files. These files store the infrastructure description written in HashiCorp Configuration Language (HCL). If you change the configuration files, Terraform automatically detects which part of your configuration is already deployed, and what should be added or removed.

Terraform is distributed under the Business Source License. The Yandex Cloud provider for Terraform is distributed under the MPL-2.0 license.

For more information about the provider resources, see the documentation on the Terraform website or mirror website.

If you do not have Terraform yet, install it and configure its Yandex Cloud provider.

Logging destinationLogging destination

If a custom log group is not specified in the container revision parameters or logging is not turned off, the container automatically writes all logs to the default log group for the folder it resides in.

To write logs to a custom log group, in the log_options section, provide the log group ID in the log_group_id parameter when creating a container revision. The log group must reside in the same folder as the container.

Minimum logging levelMinimum logging level

To set a minimum logging level, specify it in the log_group_id parameter when creating a container revision.

If you set the minimum logging level, logs of that level and higher will be written to the execution log. With no minimum logging level set, all container logs will be written to the execution log.

Disabling loggingDisabling logging

To disable logging, under log_options, set the disabled parameter to true when creating a container revision.

ExampleExample

To write logs to a custom log group:

  1. Open the Terraform configuration file and add the log_options section to the yandex_serverless_container resource description:

    Here is an example of the configuration file structure:

    resource "yandex_serverless_container" "<container_name>" {
      name               = "<container_name>"
      service_account_id = "<service_account_ID>"
      memory             = <RAM_size>
      image {
        url = "<Docker_image_URL>"
      }
      log_options {
        folder_id = "<folder_ID>"
        min_level = "<minimum_logging_level>"
      }
    }
    

    Where:

    • name: Container name.
    • service_account_id: ID of the service account with permissions to download a Docker image.
    • memory: Required memory. The default value is 128 MB.
    • url: Docker image URL.
    • folder_id: Folder ID.
    • min_level: Minimum logging level. This is an optional parameter.

    For more information about the yandex_serverless_container resource parameters, see the provider documentation.

  2. Create resources:

    1. In the terminal, change to the folder where you edited the configuration file.

    2. Make sure the configuration file is correct using the command:

      terraform validate
      

      If the configuration is correct, the following message is returned:

      Success! The configuration is valid.
      
    3. Run the command:

      terraform plan
      

      The terminal will display a list of resources with parameters. No changes are made at this step. If the configuration contains errors, Terraform will point them out.

    4. Apply the configuration changes:

      terraform apply
      
    5. Confirm the changes: type yes in the terminal and press Enter.

To write to the container execution log, use the deployRevision REST API method for the Container resource or the ContainerService/DeployRevision gRPC API call.

Structured logsStructured logs

Apart from text, you can write structured logs to the standard output stream (stdout) and standard error output stream (stderr).

Applications and Dockerfile examplesApplications and Dockerfile examples

Node.js
Python
Go

index.js

const winston = require('winston');
const express = require('express');

const logger = winston.createLogger({
    level: 'debug',
    format: winston.format.json(),
    transports: [new winston.transports.Console()],
});

const app = express();
app.use(express.urlencoded({ extended: true }));
app.use(express.json());

app.get("/", (req, res) => {
    logger.info({"message": "My log message", "my-key": "my-value"})
    return res.send("Hello, world!");
});

app.listen(process.env.PORT);

Dockerfile

FROM node:16-slim

WORKDIR /app
RUN npm install winston express
COPY ./index.js .

CMD [ "node", "index.js" ]

requirements.txt

python-json-logger==2.0.4
sanic==22.12.0

index.py

import logging
import os

from pythonjsonlogger import jsonlogger
from sanic import Sanic
from sanic.response import text


class YcLoggingFormatter(jsonlogger.JsonFormatter):
    def add_fields(self, log_record, record, message_dict):
        super(YcLoggingFormatter, self).add_fields(log_record, record, message_dict)
        log_record['logger'] = record.name
        log_record['level'] = str.replace(str.replace(record.levelname, "WARNING", "WARN"), "CRITICAL", "FATAL")


app = Sanic(__name__)

logHandler = logging.StreamHandler()
logHandler.setFormatter(YcLoggingFormatter('%(message)s %(level)s %(logger)s'))

logger = logging.getLogger('MyLogger')
logger.propagate = False
logger.addHandler(logHandler)
logger.setLevel(logging.DEBUG)


@app.route("/")
async def hello(request):
    logger.info("My log message", extra={"my-key": "my-value"})
    return text("Hello, world!", status=200)


if __name__ == "__main__":
    app.run(host='0.0.0.0', port=int(os.environ['PORT']), motd=False, access_log=False)

Dockerfile

FROM python:3.10-slim

WORKDIR /app
COPY ./index.py .
COPY ./requirements.txt .
RUN pip install --no-cache-dir --prefer-binary --requirement=./requirements.txt

CMD [ "python", "index.py" ]

index.go

package main

import (
    "go.uber.org/zap"
    "net/http"
    "os"
)

func main() {
    zapConfig := zap.NewProductionConfig()
    zapConfig.DisableCaller = true
    zapConfig.Level.SetLevel(zap.DebugLevel)
    logger, _ := zapConfig.Build()

    portStr := os.Getenv("PORT")
    http.Handle("/", handler{logger})
    http.ListenAndServe(":"+portStr, nil)
}

type handler struct {
    logger *zap.Logger
}

func (h handler) ServeHTTP(writer http.ResponseWriter, _ *http.Request) {
    h.logger.Info(
        "My log message",
        zap.String("my-key", "my-value"),
    )

    writer.WriteHeader(200)
    _, _ = writer.Write([]byte("Hello, world!"))
}

Dockerfile

FROM golang:latest AS build

WORKDIR /app
ADD index.go .
ADD go.mod .
ADD go.sum .
RUN go build -a -tags netgo -ldflags '-w -extldflags "-static"' -o server-app *.go

FROM scratch
COPY --from=build /app/server-app /server-app

ENTRYPOINT ["/server-app"]

Was the article helpful?

Previous
Viewing logs
Next
Migration to the ru-central1-d availability zone
Yandex project
© 2025 Yandex.Cloud LLC