Check out v4 of the Fauna CLI
v4 of the Fauna CLI is now GA. The new version introduces enhancements to the developer experience, including an improved authentication workflow. To get started, check out the CLI v4 quick start. Migrating from v3 of the CLI? See the CLI migration guide. |
log()
Output a log message in
the query summary and return
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 message template
The log message template is:
info at *<source>*:<line>: <message>
where:
Field | Description | ||||||
---|---|---|---|---|---|---|---|
|
Message source.
|
||||||
|
Line number where |
||||||
|
String-serialized |
Log messages for UDF calls
When calling a user-defined
function (UDF) that uses log()
, the
visibility of log messages depends on the
authentication secret's role:
Role | Visibility |
---|---|
Messages are returned in the response’s
|
|
Messages are not returned, even if the UDF is annotated with
|
Parameters
Parameter | Type | Required | Description |
---|---|---|---|
|
Values to output to the query summary. Supports interpolated strings containing FQL variables. |
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 }
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!