Skip to main content

Logging Agent - JS/TS

Write a log.

Logic TypeAvailable
Generic logic
Aggregator logic

Logs will be collected in the task's task result and will look like this:

2023-12-31T12:59:59.000000000+00:00     Info    plaintext       some logging
2024-01-01T01:00:00.000000000+00:00 Error json {"error":true,"errorMessage":"some error","stack":"Error: some error...","taskId":"..."}
info

Logs output with console.log() will not show up in the execution result.

Import and Usage

import {
LoggingAgent,
} from "@fstnetwork/loc-logic-sdk";

export async function run(ctx) {
LoggingAgent.info("some logging");
}

export async function handleError(ctx, error) {
LoggingAgent.error("some error");
}

Class Reference

Type

  • LoggingAgent

Methods: Write a Log

info(value: string | object)
ParameterDescription
valueA string message or JavaScript JSON object

Write a log with Info severity level.

warning

Runtime will throw a JSON parsing error if the object cannot be serialised properly to JSON.

You can try using JSON.parse(JSON.stringify(object) to transform an object with methods into a proper JSON object, although some fields may be different or discarded.

The methods represent different logging severity levels:

Log TypeLevel
ErrorHighest
Warn
Info
Debug
TraceLowest

Examples

Write Logs

// log a string
LoggingAgent.info("don't panic!");

// log a JSON object
LoggingAgent.error({
status: "error",
taskId: ctx.task.taskKey.taskId,
error: {
message: error.message,
stack: error.stack,
}
list: [
"item 1",
"item 2",
"item 3"
],
});