The Logger provides a system-wide, common way to record log messages. The log messages are stored in Elasticsearch. This is done though an HTTP API.
Before building and running the pz-logger project, please ensure that the following components are available and/or installed, as necessary:
- Git (for checking out repository source)
- Go v1.7 or later
- Glide
- ElasticSearch
For additional details on prerequisites, please refer to the Piazza Developer's Guide repository content for Core Overview or Piazza Logger sections. Also refer to the prerequisites for using Piazza section for additional details.
Create the directory the repository must live in:
$ mkdir -p $GOPATH/src/github.com/venicegeo
$ cd $GOPATH/src/github.com/venicegeo
$ git clone git@github.com:venicegeo/pz-logger.git
$ cd pz-logger
Set up Go environment variables
To function right, Go must have some environment variables set. Run the go env
command to list all relevant environment variables. The two most important
variables to look for are GOROOT
and GOPATH
.
GOROOT
must point to the base directory at which Go is installedGOPATH
must point to a directory that is to serve as your development environment. This is where this code and dependencies will live.
To quickly verify these variables are set, run the command from terminal:
$ go env | egrep "GOPATH|GOROOT"
In order for pz-logger to successfully start it needs access to running, local ElasticSearch instance. If not currently available, it can be downloaded and documentation can be found here.
Additionally, the environment variable LOGGER_INDEX
must be set; the value of this will be the name of the index in ElasticSearch containing logs.
This project manages dependencies by populating a vendor/
directory using the
glide tool. If the tool is already installed, in the code repository, run:
$ glide install -v
This will retrieve all the relevant dependencies at their appropriate versions
and place them in vendor/
, which enables Go to use those versions in building
rather than the default (which is the newest revision in Github).
Adding new dependencies. When adding new dependencies, simply installing them with
go get <package>
will fetch their latest version and place it in$GOPATH/src
. This is undesirable, since it is not repeatable for others. Instead, to add a dependency, useglide get <package>
, which will place it invendor/
and updateglide.yaml
andglide.lock
to remember its version.
To build pz-logger
, run go install
from the project directory. To build it from elsewhere, run:
$ go install github.com/venicegeo/pz-logger
This will build and place a statically-linked Go executable at $GOPATH/bin/pz-logger
.
$ go build
$ ./pz-logger
To run pz-logger
, unit tests, run the command shown below. This
will run the unit tests for pz-logger
and all its subpackages and print
coverage summaries.
$ go test -cover github.com/venicegeo/pz-logger/logger
An example response should look similar to
ok github.com/venicegeo/pz-logger/logger 4.064s coverage: 76.8% of statements