Often times when you develop an application on your local system it's not enough to run a single application but maybe many different ones.
The idea behind scotty
originated from the resulting pain of having many terminal windows printing logs and stitching together the logs you
need in order to understand the bug you're searching for..tedious
With scotty
you can multiplex your application logs into one consolidated terminal window apply filterss on specific streams and format structred (JSON format) logs. In the future the secondary goal of scotty is it to allow you to query/aggregate your logs.
brew tap KonstantinGasser/tap
brew install scotty beam
go install github.com/KonstantinGasser/[email protected]
go install github.com/KonstantinGasser/[email protected]
Somehow your logs need to be send or say beamed to scotty
. This is why scotty comes with a helper command called beam
.
Beam pushes everything it reads from stdin to scotty. Just be aware that things printed to stderr won't work..but we can
redirect stderr
to stdout
using 2>&1
.
cat uss_enterprise_engine.log | beam -d engine-service
This above command cats the uss_enterprise_engine.log
to stdout which is then piped to the stdin of beam
. Note the beam's first argument
will be the name referenced in scotty.
go run -race cmd/my/application.go 2>&1 | beam my-application
Here application.go
produces logs printed to stderr this is why we need to add 2>&1
to redirect the output to stdout. The pipe to beam
stays unchanged.
Especially when logs are structured we humans have it hard to read the unformatted JSON. Hit the :
key and type the line number of the log you want to format.
Hint: once the log line is displayed use the arrow keys for up and down (or j
, k
) to parse the previous or next line
When you need to only look at certain logs form a subset of streams your can apply a filter. Hit ctrl+f
followed by a comma separated list of the streams you want to focus on.
While the filter is applied you can browse through the subset of logs as usual with : <index>
.
To remove set filters hit the q
key
Currently beam
only allows to pipe data through unix sockets..however beam
as well as scotty
are build such that both will support piping
data via a tcp:ip connection which enables you to beam logs from for example docker instances to scotty
:)
Since scotty
is still under active development panics within the program might happen. In such case you might need to delete the create unix socket before restarting scotty. The default path for the socket scotty is using is /tmp/scotty.sock
. This does not apply if you used tcp:ip