Share via


MemoryLogger Class

A static class to control SDK logging into an in-memory buffer. Turning on logging while running your Speech SDK scenario provides detailed information from the SDK's core native components. If you report an issue to Microsoft, you may be asked to provide logs to help Microsoft diagnose the issue. Your application should not take dependency on particular log strings, as they may change from one SDK release to another without notice. MemoryLogger is designed for the case where you want to get access to logs that were taken in the short duration before some unexpected event happens. For example, if you are running a Speech Recognizer, you may want to dump the MemoryLogger after getting an event indicating recognition was canceled due to some error. The size of the memory buffer is fixed at 2MB and cannot be changed. This is a "ring" buffer, that is, new log strings written replace the oldest ones in the buffer. Added in version 1.43.0

Memory logging is a process wide construct. That means that if (for example) you have multiple speech recognizer objects running in parallel, there will be one memory buffer containing interleaved logs from all recognizers. You cannot get separate logs for each recognizer.

Constructor

MemoryLogger()

Methods

dump

Writes the content of the whole memory buffer to the specified file. It does not block other SDK threads from continuing to log into the buffer.

dump_to_list

Returns the content of the whole memory buffer as a list of strings. For example, you can access it as a list by calling MemoryLogger.dump_to_list(). It does not block other SDK threads from continuing to log into the buffer.

dump_to_stream

Writes the content of the whole memory buffer to an object that implements io.IOBase. For example, sys.stdout (for console output). It does not block other SDK threads from continuing to log into the buffer.

set_filters

Sets filters for memory logging. Once filters are set, memory logger will only be updated with log strings containing at least one of the strings specified by the filters. The match is case sensitive.

set_level

Sets the level of the messages to be captured by the logger.

start

Starts logging into the internal memory buffer.

stop

Stops logging into the internal memory buffer.

dump

Writes the content of the whole memory buffer to the specified file. It does not block other SDK threads from continuing to log into the buffer.

static dump(file_path: str)

Parameters

Name Description
file_path
Required

Path to a log file on local disk.

dump_to_list

Returns the content of the whole memory buffer as a list of strings. For example, you can access it as a list by calling MemoryLogger.dump_to_list(). It does not block other SDK threads from continuing to log into the buffer.

static dump_to_list() -> list

Returns

Type Description

A list of strings of the contents of the memory buffer copied into it.

dump_to_stream

Writes the content of the whole memory buffer to an object that implements io.IOBase. For example, sys.stdout (for console output). It does not block other SDK threads from continuing to log into the buffer.

static dump_to_stream(out_stream: IOBase)

Parameters

Name Description
out_stream
Required

IOBase object to write to.

set_filters

Sets filters for memory logging. Once filters are set, memory logger will only be updated with log strings containing at least one of the strings specified by the filters. The match is case sensitive.

static set_filters(filters: List[str] = [])

Parameters

Name Description
filters

Filters to use, or an empty list to remove previously set filters.

Default value: []

set_level

Sets the level of the messages to be captured by the logger.

static set_level(level: LogLevel = LogLevel.Info)

Parameters

Name Description
level

Maximum level of detail to be captured by the logger.

Default value: LogLevel.Info

start

Starts logging into the internal memory buffer.

static start()

stop

Stops logging into the internal memory buffer.

static stop()