Yandex Cloud
Search
Contact UsGet started
  • Pricing
  • Customer Stories
  • Documentation
  • Blog
  • All Services
  • System Status
    • Featured
    • Infrastructure & Network
    • Data Platform
    • Containers
    • Developer tools
    • Serverless
    • Security
    • Monitoring & Resources
    • AI Studio
    • Business tools
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Start testing with double trial credits
    • Cloud credits to scale your IT product
    • Gateway to Russia
    • Cloud for Startups
    • Education and Science
    • Yandex Cloud Partner program
  • Pricing
  • Customer Stories
  • Documentation
  • Blog
© 2025 Direct Cursus Technology L.L.C.
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
  • Monitoring metrics
  • Audit Trails events
  • Public materials
  • 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 July 29, 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. Navigate to the Editor tab.

  5. Under Logging:

    1. Enable Write logs.

    2. In the Destination field, select:

      • Folder: To write logs to the default log group for the folder the container is in.
      • Log group: To write logs to a custom log group.

        Select the log group to write logs to or create a new one.

    3. Optionally, select the minimum logging level.

  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 installed yet, install and initialize it.

By default, the CLI uses the folder specified when creating the profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also set a different folder for any specific command 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.

For logging to another folder's default log group, provide that folder's ID in the --log-folder-id parameter when creating a container revision. The account used to run the command must have the logging.editor role or higher for the folder.

For logging to a custom log group, provide that log group's ID in the --log-group-id parameter when creating a container revision. The log group may reside in a different folder. The account used to run the command must have the logging.editor role or higher for the folder.

Minimum logging levelMinimum logging level

To set the 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

For logging 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 relevant documentation on the Terraform website or its mirror.

If you do not have Terraform yet, install it and configure the 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.

For logging to another folder's default log group, provide that folder's ID under log_options in the folder_id parameter when creating a container revision. The account used to run the command must have the logging.editor role or higher for the folder.

For logging to a custom log group, provide that log group's ID under log_options in the log_group_id parameter when creating a container revision. The log group may reside in a different folder. The account used to run the command must have the logging.editor role or higher for the folder.

Minimum logging levelMinimum logging level

To set the minimum logging level, specify it under log_options in the min_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, under log_options, set the disabled parameter to true when creating a container revision.

ExampleExample

For logging 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.
    • image: Docker image parameters:
      • url: Docker image URL.
    • log_options: Logging settings:
      • 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 the resources:

    1. In the terminal, go to the directory where you edited the configuration file.

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

      terraform validate
      

      If the configuration is correct, you will get this message:

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

      terraform plan
      

      You will see a detailed list of resources. No changes will be made at this step. If the configuration contains any errors, Terraform will show them.

    4. Apply the changes:

      terraform apply
      
    5. Type yes and press Enter to confirm the changes.

For logging 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
© 2025 Direct Cursus Technology L.L.C.