[Yandex Cloud documentation](../../../index.md) > [Yandex Cloud Functions](../../index.md) > [Developing in Python](index.md) > Logging

# Python function execution logging

Cloud Functions automatically captures the Python application's standard output streams and sends them to the centralized [logging system](../../operations/function/function-logs.md) in Yandex Cloud. In addition to the application execution logs, the system also logs request execution events.

Additional messages are logged using standard language constructs:
1. `print`: Outputs a message to the standard output stream, `stdout`.
1. `logging`: Outputs a message in the specified format to the selected output stream.

{% note info %}

Multiline messages must use `\r` (carriage return) as a separator, not `\n` (line feed). When using a line feed, each line is sent as a separate message and displayed separately in the log.

{% endnote %}

## System messages {#router-loggin}

When processing each function call, the system also logs the `START`, `END`, and `REPORT` system messages:

```text
START RequestID: <request_ID> Version: <function_version_ID>
END RequestID: <request_ID>
REPORT RequestID: <request_ID>
    Duration: 236.606 ms
    Billed Duration: 300 ms
    Memory Size: 128 MB
    Max Memory Used: 22 MB
    Queuing Duration: 0.027 ms
    Function Init Duration: 225.298 ms
```

All lines contain the ID of the request (`RequestID`), which is generated automatically when the function is invoked.

The `REPORT` line provides a report on the function run. It contains additional information about the resources consumed:
* `Duration`: Time spent invoking the function. It includes the `Queuing Duration` and `Function Init Duration` parameters.
* `Billed Duration`: Time billed based on the [pricing policy](../../pricing.md).
* `Memory Size`: Amount of memory specified when creating the version, in MB.
* `Max Memory Used`: Memory used when the request starts running.
* `Queuing Duration`: Time spent by the request in the internal queue. If this time increases, it may indicate a lack of function instances. The maximum number of instances is limited by [quotas](../../concepts/limits.md).
* `Function Init Duration`: Time spent initializing the runtime and loading the function code.

## User messages {#user-logging}

Before running a function, Cloud Functions configures the following for the [root logger](https://docs.python.org/3/howto/logging.html#advanced-logging-tutorial):
* Handler for writing logs to `stdout`.
* Formatter that adds the creation timestamp, request ID, and logging level to each message.

{% note warning %}

You cannot change the root logger settings using the `logging.basicConfig()` function.

{% endnote %}

By default, the root logger level is `Warning`, and all logs below this level are ignored. You can change the logging level using the `setLevel` method for:

* The entire app.
  ```python
  logging.getLogger().setLevel(logging.DEBUG)
  ```
* Any logger except the root one.
  ```python
  logging.getLogger('requests.packages.urllib3').setLevel(logging.DEBUG)
  logging.getLogger('myapp').setLevel(logging.DEBUG)
  ```

You can change the log format as follows:

```python
root_handler = logging.getLogger().handlers[0]
root_handler.setFormatter(logging.Formatter(
	'[%(levelname)s]\t%(name)s\t%(request_id)s\t%(message)s\n'
))
```

This example outputs the logger name instead of the message creation timestamp.

Learn more about how to configure logging in [this Python guide](https://docs.python.org/3/howto/logging.html#configuring-logging).