log()

Output a log message in the query summary and return null.

Signature

log()(args: …​Any) => Null

Description

The log() method outputs args containing a message to the summary of query responses. In the summary, log messages are annotated as info.

log() is similar to console.log() or print() in other programming languages.

log() and dbg()

log() is similar to dbg() except that log() does not return its message in the query results.

Log message template

The log message template is:

info at *<source>*:<line>: <message>

where:

Field Description

<source>

Message source.
One of:

Source Description

query

The log() call occurred in the main query body.

udf:<function>

The log() call occurred in the user-defined function named <function>

<line>

Line number where log() is used.

<message>

String-serialized message.

Parameters

Parameter Type Required Description

args

Any

Values to output to the query summary. Supports interpolated strings containing FQL variables.

Return value

Type Description

Null

After output, the args are discarded.

Examples

The following FQL query logs several summary messages:

log("Before assignment")
let x = 5
let y = { lat: 37.5542782, long: -122.3007394 }
log("After assignment x=#{x}")
log(y)
x

The query as a Query endpoint request:

 curl -X POST \
  'https://db.fauna.com/query/1' \
  -H 'Authorization: Bearer <FAUNA_SECRET>' \
  -H 'Content-Type: application/json' \
  -H 'X-Format: tagged' \
  -d '{
    "query": "log(\"Before assignment\")\nlet x = 5\nlet y = { lat: 37.5542782, long: -122.3007394 }\nlog(\"After assignment x=#{x}\")\nlog(y)\nx\n"
  }'

Unlike dbg(), log() does not return a value. The message is excluded from the query results in data.

The summary includes the query lines that called log():

{
  "data": {
    "@int": "5"
  },
  "static_type": "5",
  "summary": "info at *query*:1: Before assignment\n\ninfo at *query*:4: After assignment x=5\n\ninfo at *query*:5: { lat: 37.5542782, long: -122.3007394 }",
  ...
}

When unescaped, the response’s summary renders as:

"info at *query*:1: Before assignment

info at *query*:4: After assignment x=5

info at *query*:5: { lat: 37.5542782, long: -122.3007394 }

See also

Is this article helpful? 

Tell Fauna how the article can be improved:
Visit Fauna's forums or email docs@fauna.com

Thank you for your feedback!