TestLogger
@algorandfoundation/algokit-utils / testing / TestLogger
testing.TestLogger
Exposes an AlgoKit logger which captures log messages, while wrapping an original logger. This is useful for automated testing.
Implements
Section titled “Implements”Table of contents
Section titled “Table of contents”Constructors
Section titled “Constructors”Properties
Section titled “Properties”Accessors
Section titled “Accessors”Methods
Section titled “Methods”Constructors
Section titled “Constructors”constructor
Section titled “constructor”• new TestLogger(originalLogger?): TestLogger
Create a new test logger that wraps the given logger if provided.
Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
originalLogger? | Logger | The optional original logger to wrap. |
Returns
Section titled “Returns”Defined in
Section titled “Defined in”Properties
Section titled “Properties”• Private logs: string[]
Defined in
Section titled “Defined in”originalLogger
Section titled “originalLogger”• Private originalLogger: undefined | Logger
Defined in
Section titled “Defined in”Accessors
Section titled “Accessors”capturedLogs
Section titled “capturedLogs”• get capturedLogs(): string[]
Returns all logs captured thus far.
Returns
Section titled “Returns”string[]
Defined in
Section titled “Defined in”Methods
Section titled “Methods”▸ clear(): void
Clears all logs captured so far.
Returns
Section titled “Returns”void
Defined in
Section titled “Defined in”▸ debug(message, ...optionalParams): void
Parameters
Section titled “Parameters”| Name | Type |
|---|---|
message | string |
...optionalParams | unknown[] |
Returns
Section titled “Returns”void
Implementation of
Section titled “Implementation of”Logger.debug
Defined in
Section titled “Defined in”▸ error(message, ...optionalParams): void
Parameters
Section titled “Parameters”| Name | Type |
|---|---|
message | string |
...optionalParams | unknown[] |
Returns
Section titled “Returns”void
Implementation of
Section titled “Implementation of”Logger.error
Defined in
Section titled “Defined in”getLogSnapshot
Section titled “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.
https://jestjs.io/docs/snapshot-testing#2-tests-should-be-deterministic
Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
config? | LogSnapshotConfig | The snapshot configuration |
Returns
Section titled “Returns”string
The snapshotted logs.
Example
const logger = new TestLogger()...expect(logger.getLogSnapshot()).toMatchSnapshot()Defined in
Section titled “Defined in”▸ info(message, ...optionalParams): void
Parameters
Section titled “Parameters”| Name | Type |
|---|---|
message | string |
...optionalParams | unknown[] |
Returns
Section titled “Returns”void
Implementation of
Section titled “Implementation of”Logger.info
Defined in
Section titled “Defined in”verbose
Section titled “verbose”▸ verbose(message, ...optionalParams): void
Parameters
Section titled “Parameters”| Name | Type |
|---|---|
message | string |
...optionalParams | unknown[] |
Returns
Section titled “Returns”void
Implementation of
Section titled “Implementation of”Logger.verbose
Defined in
Section titled “Defined in”▸ warn(message, ...optionalParams): void
Parameters
Section titled “Parameters”| Name | Type |
|---|---|
message | string |
...optionalParams | unknown[] |
Returns
Section titled “Returns”void
Implementation of
Section titled “Implementation of”Logger.warn