Home

Awesome

Remote Logging

A simple demo of remote logging using the Bunyan logger.

First, fetch dependencies.

# mix deps.get

Open three terminals in this directory.

In the first, issue the following command:

$ iex --name global@127.0.0.1 -S mix run

(You will get 4 warnings when the demo.ex module compiles. That's because it deliberately contains code that will cause runtime errors.)

In the second terminal, run

$ iex --name regional@127.0.0.1 -S mix run

And finally, in the third

$ iex --name local@127.0.0.1 -S mix run

The node names are important, as they help the demo configure the logger.

OK, Now What

Go the the terminal that's running the local node, and keep the other two windows visible.

In the local iex session, run

iex> require Bunyan
iex> import  Bunyan
iex> debug  "a debug message in local"
iex> info   "and then an info message", answer: 42, helpful: false
iex> warn   "don't panic"
iex> error  fn -> System.user_home end, args: System.argv

and watch the log messages appear.

Do the same in the other sessions.

What You Just Configured

We now have three applications running, each on its own node.

diagram showing the three nodes and the messages displayed and saved
on each

And Then...

While the three nodes are running, start another global node. You'll need to call it global1 (or anything else starting "global").

$ iex --name global1@127.0.0.1 -S mix run

Back in the local node, generate some log messages: you should see them appear in both global nodes.

The Regional and Global Loggers Seem to Lag...

Good eye! When you use a remote logger, Bunyan attempts to reduce network overhead by batching log messages. What you're seeing is the default 200ms batching timeout. You can adjust both this timeout and the maximum batch size in the configuration.

Next Steps...