Log

Use the Log forwarder-type Function to record events from your stream. Events are converted to a string in the form of a message. If the message is larger than 50000 characters, it is truncated. 

You add a JSON schema to determine what you want to log. If you want to log just part of the output, you can specify which key(s) you want to log. For example, if you have the keys of value, and timestamp but you only want to see the value data in your logs, enter the following:

value

The following appears in the log:

{"value": 1}
{"value": 2}
{"value": 3}

To view the logs, click Logs in the Stream Editor view. Alternatively, go to the stream list, select your stream and click View Log, or select View Log from the Action drop-down list.

For an example of how to use this function in a stream, see My First Stream.

Syntax

Here are some examples of the keys that you can specify in the Key field to log or record the data using the Log function:

  • Logging a single field

    [
        "value"
    ]
  • Logging multiple fields

    [
        "value",
        "fast",
        "bar"
    ]
  • Logging an object

    [
        "object"
    ]
  • Logging fields from a record with object (nested structure)

    For example, if you have a record with the structure of { "brand1": { "model": 1 }, "brand2":  2}' and you only want to output the value of model, you can enter the following:

    brand1.model

    The following appears in the log:

    { "brand1": { "model": 1 } }

Logs View

To view the logs, click Logs in the Stream Editor view. Alternatively, go to the stream list, select your stream and click View Log, or select View Log from the Action drop-down list.

Note!

If you include a Log Function in your stream, or use the log function in the Script Function, for example log.info, the events are displayed in the Logs view. 

For an example of how to use this Function in a stream, see My First Stream.

Example Logs  Syntax

Import this stream into your Usage Engine service for more information on the syntax used above.

Example stream

{
  "ingress": {
    "http": {
      "url": "https://ingress.dev.dazzl.io/65bb2f70-2b35-11ec-bb47-bf797a07cbe8"
    }
  },
  "schemaVersion": 1,
  "previewLocked": false,
  "schedulable": true,
  "name": "log (Copy)",
  "solutionId": "957ad6f0-eac3-11eb-a765-4d1a3bfc5223",
  "nodes": [
    {
      "partitionKey": null,
      "schemaVersion": 2,
      "id": "5752aa70-2b31-11ec-9f1b-df359e32be28",
      "name": "Count",
      "type": "readers/counter",
      "params": {
        "max": 10
      },
      "x": 450,
      "y": 300
    },
    {
      "partitionKey": null,
      "schemaVersion": 1,
      "id": "5c7fbd30-2b31-11ec-9f1b-df359e32be28",
      "name": "Script",
      "type": "transforms/script",
      "params": {
        "transform": "await push({\n    ...payload,\n    foo: Math.floor(Math.random()*10),\n    bar: new Date(),\n    baz: {\n        a: payload.value,\n        b: Math.floor(Math.random()*10),\n        c: new Date(),\n    }\n});"
      },
      "x": 650,
      "y": 300
    },
    {
      "partitionKey": null,
      "schemaVersion": 1,
      "id": "950be7a0-2b31-11ec-9f1b-df359e32be28",
      "name": "Log one field",
      "type": "writers/log",
      "params": {
        "key": [
          "value"
        ]
      },
      "x": 850,
      "y": 150
    },
    {
      "partitionKey": null,
      "schemaVersion": 1,
      "id": "025a1520-2b32-11ec-9f1b-df359e32be28",
      "name": "Log multiple fields",
      "type": "writers/log",
      "params": {
        "key": [
          "value",
          "fast",
          "bar"
        ]
      },
      "x": 850,
      "y": 300
    },
    {
      "partitionKey": null,
      "schemaVersion": 1,
      "id": "19b6c3d0-2b32-11ec-9f1b-df359e32be28",
      "name": "Log object",
      "type": "writers/log",
      "params": {
        "key": [
          "object"
        ]
      },
      "x": 850,
      "y": 450
    },
    {
      "partitionKey": null,
      "schemaVersion": 1,
      "id": "8c67f640-2b34-11ec-9f1b-df359e32be28",
      "name": "Log object value by key",
      "type": "writers/log",
      "params": {
        "key": [
          "baz.c"
        ]
      },
      "x": 850,
      "y": 600
    }
  ],
  "edges": [
    {
      "id": "5e469a80-2b31-11ec-9f1b-df359e32be28",
      "from": "5752aa70-2b31-11ec-9f1b-df359e32be28",
      "to": "5c7fbd30-2b31-11ec-9f1b-df359e32be28",
      "config": {}
    },
    {
      "id": "96b0be00-2b31-11ec-9f1b-df359e32be28",
      "from": "5c7fbd30-2b31-11ec-9f1b-df359e32be28",
      "to": "950be7a0-2b31-11ec-9f1b-df359e32be28",
      "config": {}
    },
    {
      "id": "04195150-2b32-11ec-9f1b-df359e32be28",
      "from": "5c7fbd30-2b31-11ec-9f1b-df359e32be28",
      "to": "025a1520-2b32-11ec-9f1b-df359e32be28",
      "config": {}
    },
    {
      "id": "1b8f5460-2b32-11ec-9f1b-df359e32be28",
      "from": "5c7fbd30-2b31-11ec-9f1b-df359e32be28",
      "to": "19b6c3d0-2b32-11ec-9f1b-df359e32be28",
      "config": {}
    },
    {
      "id": "8f5aa960-2b34-11ec-9f1b-df359e32be28",
      "from": "5c7fbd30-2b31-11ec-9f1b-df359e32be28",
      "to": "8c67f640-2b34-11ec-9f1b-df359e32be28",
      "config": {}
    }
  ],
  "__v": 0,
  "createdBy": "ebad7dc4-661a-4a31-a076-091fc16a3fe8",
  "createdAt": "2021-10-12T08:21:28.170Z",
  "updatedAt": "2021-10-12T11:43:31.856Z",
  "checksum": "1001928a1f3334b7e18d8e29192ca7202609a94a",
  "id": "65bb2f70-2b35-11ec-bb47-bf797a07cbe8"
}