# StreamedLog<!-- -->

Streams Actor run log output to a Python logger in a background thread.

The log stream is consumed in a background thread and each log message is forwarded to the provided logger with an appropriate log level inferred from the message content.

Can be used as a context manager, which automatically starts and stops the streaming thread. Alternatively, call `start` and `stop` manually. Obtain an instance via `RunClient.get_streamed_log`.

### Hierarchy

* [StreamedLogBase](https://docs.apify.com/api/client/python/reference/class/StreamedLogBase.md)
  * *StreamedLog*

## Index[](#Index)

### Methods

* [\_\_enter\_\_](https://docs.apify.com/api/client/python/reference/class/StreamedLog.md#__enter__)
* [\_\_exit\_\_](https://docs.apify.com/api/client/python/reference/class/StreamedLog.md#__exit__)
* [\_\_init\_\_](https://docs.apify.com/api/client/python/reference/class/StreamedLog.md#__init__)
* [start](https://docs.apify.com/api/client/python/reference/class/StreamedLog.md#start)
* [stop](https://docs.apify.com/api/client/python/reference/class/StreamedLog.md#stop)

## Methods<!-- -->[](#Methods)

### [](#__enter__)\_\_enter\_\_

* **\_\_enter\_\_**(): Self

- Start the streaming thread within the context. Exiting the context will finish the streaming thread.

  ***

  #### Returns Self

### [](#__exit__)\_\_exit\_\_

* **\_\_exit\_\_**(exc_type, exc_val, exc_tb): None

- Stop the streaming thread.

  ***

  #### Parameters

  * ##### exc_type: [type](https://docs.apify.com/api/client/python/reference/class/DatasetSchemaValidationError.md#type)\[BaseException] | None
  * ##### exc_val: BaseException | None
  * ##### exc_tb: TracebackType | None

  #### Returns None

### [](#__init__)\_\_init\_\_

* **\_\_init\_\_**(log_client, \*, to_logger, from_start): None

- Overrides [StreamedLogBase.\_\_init\_\_](https://docs.apify.com/api/client/python/reference/class/StreamedLogBase.md#__init__)

  Initialize `StreamedLog`.

  ***

  #### Parameters

  * ##### log_client: [LogClient](https://docs.apify.com/api/client/python/reference/class/LogClient.md)

    The log client used to stream raw log data from the Actor run.

  * ##### keyword-onlyto_logger: logging.Logger

    The logger to which the log messages will be forwarded.

  * ##### optionalkeyword-onlyfrom_start: bool = <!-- -->True

    If `True`, all logs from the start of the Actor run will be streamed. If `False`, only newly arrived logs will be streamed. This can be useful for long-running Actors in stand-by mode where only recent logs are relevant.

  #### Returns None

### [](#start)start

* **start**(): Thread

- Start the streaming thread.

  The caller is responsible for cleanup by calling the `stop` method when done.

  ***

  #### Returns Thread

### [](#stop)stop

* **stop**(): None

- Signal the streaming thread to stop logging and wait up to `_stop_timeout_s` for it to finish.

  A thread that outlives the wait is a daemon with `_stop_event` set, so it exits after at most one more chunk, and only then does its buffered tail reach the logger. Its handle is kept while it is alive, so `start` cannot revive it beside a second thread on the same buffer. If no stream has delivered anything yet, the thread reads the whole log in one request before it ends.

  ***

  #### Returns None
