Cloud Logs

This page will show you how to log information from a Binaris function and to read the execution logs after an invocation.

If you are new to Binaris it is recommended that you look through the previous getting-started tutorials:

Note: the instructions below assume you are using MacOS, Ubuntu or Debian.

1. Writing Binaris logs

Binaris JavaScript functions support console based logging. This means anything written to stdout (such as console.log) will be accessible via the bn logs command.

As an example, you can log the name argument of your function with the change below.

+ console.log(`${name} has been logged`);

Deploy and invoke the changed code.

$ bn deploy hello
Deployed function hello
Invoke with one of:
  "bn invoke hello"
  "curl -H X-Binaris-Api-Key:<Your_API_Key><Your_Account_Number>/hello"

$ bn invoke hello
"Howdy World!"

2. Reading cloud logs

Now use bn logs to view the log entries.

$ bn logs hello
[2018-10-22T22:03:55.997Z] World has been logged 
[2018-10-22T22:03:55.998Z] Function invocation took 27.437 us

As expected, we logged a World name. The last log line with the 27.437 us duration measurement is autogenerated per invocation.

Additionally bn logs supports logging Objects natively. Change the log statement to pass an object literal:

- console.log(`original name is ${name}`);
+ console.log({ original: name });

Re-deploy the function, invoke it one more time, and then check the logs again:

$ bn logs hello
[2018-10-22T22:08:07.412Z] { original: 'World' }
[2018-10-22T22:08:07.413Z] Function invocation took 25.628 us

3. Live logs

bn logs can show logs in real time, in a way similar to tail -f on a local file. To try it out, let’s split our terminal or open a new tab or window.

In the first terminal window, type:

$ bn logs hello --tail

In a separate terminal window, invoke the function a few times:

$ bn invoke hello --data '{"name": "firstName"}'
"Hello firstName!"
$ bn invoke hello --data '{"name": "secondName"}'
"Hello secondName!"

The first terminal shows the log shortly after each invocation:

$ bn logs hello --tail
[2018-12-07T15:54:43.334203Z] { original: 'firstName' }
[2018-12-07T15:54:43.334310Z] Function invocation took 490.398 us
[2018-12-07T15:54:58.862454Z] { original: 'secondName' }
[2018-12-07T15:54:58.862559Z] Function invocation took 169.55 us


For more information about the Binaris logging capabilities use bn logs --help.

What’s next

Call a function from another function