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

The binaris cloud logs standard output and error of each function invocation. This means anything written to stdout (such as print) will be accessible via the bn logs command.

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

+ print '{} has been logged'.format(name)

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:$(bn show apiKey) https://run.binaris.com/v2/run/<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 38.023 us

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

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

- print '{} has been logged'.format(name)
+ print { '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': u'firstName'}
[2018-12-07T15:54:43.334310Z] Function invocation took 321.150 us
[2018-12-07T15:54:58.862454Z] {'original': u'secondName'}
[2018-12-07T15:54:58.862559Z] Function invocation took 318.766 us

Tip

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

What next?

Call a function from another function