Logging

2 min read

Flowlet provides logging capabilities that allow you to write log messages and read data from the logs. JSON messages can be appended to log messages to provide further details.

Logs should not be used as a primary storage solution, as reading logs can be slow in comparison to reading directly from a database. The maximum log storage space for each workspace is 5MB, which typically holds 5000 to 10.000 messages, enough for most use cases. When the log space is full, new messages will overwrite the oldest messages.

You can view the logs through the Flowlet interface. In addition to the interface, you can also read and write log messages from scripts.

Write to log

add(name: string, data: LogsData): void;

Search log messages

Two methods are provided for this purpose. The logs method may return multiple rows, while the find method returns the first match only, or false if no match was found.

list(criteria: LogsCriteria, limit?: number, offset?: number): Promise<{
  count: number!
  items: {
    date: string;
    name: string;
    data: LogsData;
  }[]
}>;
find(criteria: LogsCriteria): Promise<false | {
  date: string;
  name: string;
  data: LogsData;
}>;

The LogsCriteria is an object where the key names are the fields to search in, and their values are the respective search keywords. There are two special keys: $search for full-text search and $name for the log name.

The offset is zero-based. Providing a limit of 10 and an offset of 0 gives the ten oldest messages. You may use a negative offset to return the newest records. For example, limit 5 with offset -5 shows the last five items.

Metadata

The number of stored items and the used and total size in bytes is accessible via the methods listed below.

getLength(): Promise<number>;
getUsage(): Promise<number>;
getSize(): Promise<number>;