TestLogger | Algorand Developer Portal

TestLogger

Exposes an AlgoKit logger which captures log messages, while wrapping an original logger. This is useful for automated testing.

Implements

Table of contents

Constructors

Properties

Accessors

Methods

Constructors

constructor

• new TestLogger(originalLogger?): TestLogger

Create a new test logger that wraps the given logger if provided.

Parameters

Name Type Description
originalLogger? Logger The optional original logger to wrap.

Returns

TestLogger

Defined in

src/testing/test-logger.ts:16

Properties

logs

• Private logs: string[

Defined in

src/testing/test-logger.ts:10

originalLogger

• Private originalLogger: undefined | Logger

Defined in

src/testing/test-logger.ts:9

Accessors

capturedLogs

• get capturedLogs(): string[

Returns all logs captured thus far.

Returns

string[

Defined in

src/testing/test-logger.ts:22

Methods

clear

▸ clear(): void

Clears all logs captured so far.

Returns

void

Defined in

src/testing/test-logger.ts:27

debug

▸ debug(message, ...optionalParams): void

Parameters

Name Type
message string
...optionalParams unknown[

Returns

void

Implementation of

Logger.debug

Defined in

src/testing/test-logger.ts:89

error

▸ error(message, ...optionalParams): void

Parameters

Name Type
message string
...optionalParams unknown[

Returns

void

Implementation of

Logger.error

Defined in

src/testing/test-logger.ts:73

getLogSnapshot

▸ getLogSnapshot(config?): string

Returns a captured log snapshot. This helps ensure that the provided configuration items won’t appear with random values in the log snapshot, but rather will get substituted with predictable ids.

Parameters

Name Type Description
config? LogSnapshotConfig The snapshot configuration

Returns

string

The snapshotted logs.

Example

const logger = new TestLogger()

...

expect(logger.getLogSnapshot()).toMatchSnapshot()

Defined in

src/testing/test-logger.ts:47

info

▸ info(message, ...optionalParams): void

Parameters

Name Type
message string
...optionalParams unknown[

Returns

void

Implementation of

Logger.info

Defined in

src/testing/test-logger.ts:81

verbose

▸ verbose(message, ...optionalParams): void

Parameters

Name Type
message string
...optionalParams unknown[

Returns

void

Implementation of

Logger.verbose

Defined in

src/testing/test-logger.ts:85

warn

▸ warn(message, ...optionalParams): void

Parameters

Name Type
message string
...optionalParams unknown[

Returns

void

Implementation of

Logger.warn

Defined in

src/testing/test-logger.ts:77