Skip to content

Commit

Permalink
Update the zap logger dependency
Browse files Browse the repository at this point in the history
The previous sha was taken from a revision on a devel branch that I
thought would continue staying in the tree after it was merged. That
revision was rebased away and the API was changed for the logger.

This updates the usage of the logger and adds a simple package for
constructing the base logger.
  • Loading branch information
jsternberg committed Nov 4, 2017
1 parent c1da954 commit 43a2622
Show file tree
Hide file tree
Showing 53 changed files with 212 additions and 237 deletions.
5 changes: 3 additions & 2 deletions Godeps
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ github.com/philhofer/fwd 1612a298117663d7bc9a760ae20d383413859798
github.com/retailnext/hllpp 38a7bb71b483e855d35010808143beaf05b67f9d
github.com/spaolacci/murmur3 0d12bf811670bf6a1a63828dfbd003eded177fce
github.com/tinylib/msgp ad0ff2e232ad2e37faf67087fb24bf8d04a8ce20
github.com/uber-go/atomic 74ca5ec650841aee9f289dce76e928313a37cbc6
github.com/uber-go/zap fbae0281ffd546fa6d1959fec6075ac5da7fb577
github.com/xlab/treeprint 06dfc6fa17cdde904617990a0c2d89e3e332dbb3
go.uber.org/atomic 54f72d32435d760d5604f17a82e2435b28dc4ba5
go.uber.org/multierr fb7d312c2c04c34f0ad621048bbb953b168f9ff6
go.uber.org/zap 35aad584952c3e7020db7b839f6b102de6271f89
golang.org/x/crypto 9477e0b78b9ac3d0b03822fd95422e2fe07627cd
golang.org/x/sys 062cd7e4e68206d8bab9b18396626e855c992658
golang.org/x/text a71fd10341b064c10f4a81ceac72bcf70f26ea34
5 changes: 3 additions & 2 deletions LICENSE_OF_DEPENDENCIES.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
- github.com/tinylib/msgp [MIT LICENSE](https://github.com/tinylib/msgp/blob/master/LICENSE)
- github.com/rakyll/statik [APACHE LICENSE](https://github.com/rakyll/statik/blob/master/LICENSE)
- github.com/retailnext/hllpp [BSD LICENSE](https://github.com/retailnext/hllpp/blob/master/LICENSE)
- github.com/uber-go/atomic [MIT LICENSE](https://github.com/uber-go/atomic/blob/master/LICENSE.txt)
- github.com/uber-go/zap [MIT LICENSE](https://github.com/uber-go/zap/blob/master/LICENSE.txt)
- go.uber.org/atomic [MIT LICENSE](https://github.com/uber-go/atomic/blob/master/LICENSE.txt)
- go.uber.org/multierr [MIT LICENSE](https://github.com/uber-go/multierr/blob/master/LICENSE.txt)
- go.uber.org/zap [MIT LICENSE](https://github.com/uber-go/zap/blob/master/LICENSE.txt)
- golang.org/x/crypto [BSD LICENSE](https://github.com/golang/crypto/blob/master/LICENSE)
- golang.org/x/text [BSD LICENSE](https://github.com/golang/text/blob/master/LICENSE)
- jquery 2.1.4 [MIT LICENSE](https://github.com/jquery/jquery/blob/master/LICENSE.txt)
Expand Down
18 changes: 7 additions & 11 deletions cmd/influx_inspect/inmem2tsi/inmem2tsi.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,28 @@ import (
"os"
"path/filepath"

"github.com/influxdata/influxdb/logger"
"github.com/influxdata/influxdb/models"
"github.com/influxdata/influxdb/tsdb"
"github.com/influxdata/influxdb/tsdb/engine/tsm1"
"github.com/influxdata/influxdb/tsdb/index/tsi1"
"github.com/uber-go/zap"
"go.uber.org/zap"
)

// Command represents the program execution for "influx_inspect inmem2tsi".
type Command struct {
Stderr io.Writer
Stdout io.Writer

Stderr io.Writer
Stdout io.Writer
Verbose bool
Logger zap.Logger
Logger *zap.Logger
}

// NewCommand returns a new instance of Command.
func NewCommand() *Command {
return &Command{
Stderr: os.Stderr,
Stdout: os.Stdout,
Logger: zap.New(zap.NullEncoder()),
Logger: zap.NewNop(),
}
}

Expand All @@ -47,11 +47,7 @@ func (cmd *Command) Run(args ...string) error {
} else if fs.NArg() > 0 || *dataDir == "" || *walDir == "" {
return flag.ErrHelp
}

cmd.Logger = zap.New(
zap.NewTextEncoder(),
zap.Output(os.Stderr),
)
cmd.Logger = logger.New(os.Stderr)

return cmd.run(*dataDir, *walDir)
}
Expand Down
10 changes: 4 additions & 6 deletions cmd/influxd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import (
"github.com/influxdata/influxdb/cmd/influxd/help"
"github.com/influxdata/influxdb/cmd/influxd/restore"
"github.com/influxdata/influxdb/cmd/influxd/run"
"github.com/uber-go/zap"
"github.com/influxdata/influxdb/logger"
"go.uber.org/zap"
)

// These variables are populated via the Go linker.
Expand Down Expand Up @@ -51,7 +52,7 @@ func main() {

// Main represents the program execution.
type Main struct {
Logger zap.Logger
Logger *zap.Logger

Stdin io.Reader
Stdout io.Writer
Expand All @@ -61,10 +62,7 @@ type Main struct {
// NewMain return a new instance of Main.
func NewMain() *Main {
return &Main{
Logger: zap.New(
zap.NewTextEncoder(),
zap.Output(os.Stderr),
),
Logger: logger.New(os.Stderr),
Stdin: os.Stdin,
Stdout: os.Stdout,
Stderr: os.Stderr,
Expand Down
6 changes: 3 additions & 3 deletions cmd/influxd/run/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"strconv"
"time"

"github.com/uber-go/zap"
"go.uber.org/zap"
)

const logo = `
Expand Down Expand Up @@ -42,7 +42,7 @@ type Command struct {
Stdin io.Reader
Stdout io.Writer
Stderr io.Writer
Logger zap.Logger
Logger *zap.Logger

Server *Server

Expand All @@ -58,7 +58,7 @@ func NewCommand() *Command {
Stdin: os.Stdin,
Stdout: os.Stdout,
Stderr: os.Stderr,
Logger: zap.New(zap.NullEncoder()),
Logger: zap.NewNop(),
}
}

Expand Down
14 changes: 6 additions & 8 deletions cmd/influxd/run/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/influxdata/influxdb"
"github.com/influxdata/influxdb/coordinator"
"github.com/influxdata/influxdb/logger"
"github.com/influxdata/influxdb/models"
"github.com/influxdata/influxdb/monitor"
"github.com/influxdata/influxdb/query"
Expand All @@ -30,7 +31,7 @@ import (
"github.com/influxdata/influxdb/tcp"
"github.com/influxdata/influxdb/tsdb"
client "github.com/influxdata/usage-client/v1"
"github.com/uber-go/zap"
"go.uber.org/zap"

// Initialize the engine & index packages
"github.com/influxdata/influxdb/services/storage"
Expand Down Expand Up @@ -64,7 +65,7 @@ type Server struct {
BindAddress string
Listener net.Listener

Logger zap.Logger
Logger *zap.Logger

MetaClient *meta.Client

Expand Down Expand Up @@ -142,10 +143,7 @@ func NewServer(c *Config, buildInfo *BuildInfo) (*Server, error) {

BindAddress: bind,

Logger: zap.New(
zap.NewTextEncoder(),
zap.Output(os.Stderr),
),
Logger: logger.New(os.Stderr),

MetaClient: meta.NewClient(c.Meta),

Expand Down Expand Up @@ -234,7 +232,7 @@ func (s *Server) appendSnapshotterService() {
// SetLogOutput sets the logger used for all messages. It must not be called
// after the Open method has been called.
func (s *Server) SetLogOutput(w io.Writer) {
s.Logger = zap.New(zap.NewTextEncoder(), zap.Output(zap.AddSync(w)))
s.Logger = logger.New(w)
}

func (s *Server) appendMonitorService() {
Expand Down Expand Up @@ -563,7 +561,7 @@ func (s *Server) reportServer() {

// Service represents a service attached to the server.
type Service interface {
WithLogger(log zap.Logger)
WithLogger(log *zap.Logger)
Open() error
Close() error
}
Expand Down
10 changes: 4 additions & 6 deletions cmd/store/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import (
"github.com/influxdata/influxdb/cmd"
"github.com/influxdata/influxdb/cmd/store/help"
"github.com/influxdata/influxdb/cmd/store/query"
"github.com/influxdata/influxdb/logger"
_ "github.com/influxdata/influxdb/tsdb/engine"
"github.com/uber-go/zap"
"go.uber.org/zap"
)

func main() {
Expand All @@ -23,7 +24,7 @@ func main() {

// Main represents the program execution.
type Main struct {
Logger zap.Logger
Logger *zap.Logger

Stdin io.Reader
Stdout io.Writer
Expand All @@ -33,10 +34,7 @@ type Main struct {
// NewMain returns a new instance of Main.
func NewMain() *Main {
return &Main{
Logger: zap.New(
zap.NewTextEncoder(),
zap.Output(os.Stderr),
),
Logger: logger.New(os.Stderr),
Stdin: os.Stdin,
Stdout: os.Stdout,
Stderr: os.Stderr,
Expand Down
10 changes: 4 additions & 6 deletions cmd/store/query/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,30 @@ package query
import (
"bufio"
"context"
"errors"
"flag"
"fmt"
"io"
"os"
"path/filepath"
"strconv"
"time"

"errors"

"strings"
"time"

"github.com/gogo/protobuf/proto"
"github.com/influxdata/influxdb/models"
"github.com/influxdata/influxdb/services/storage"
"github.com/influxdata/influxql"
"github.com/influxdata/yarpc"
"github.com/uber-go/zap"
"go.uber.org/zap"
)

// Command represents the program execution for "influx_inspect export".
type Command struct {
// Standard input/output, overridden for testing.
Stderr io.Writer
Stdout io.Writer
Logger zap.Logger
Logger *zap.Logger

addr string
cpuProfile string
Expand Down
8 changes: 4 additions & 4 deletions coordinator/points_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/influxdata/influxdb/models"
"github.com/influxdata/influxdb/services/meta"
"github.com/influxdata/influxdb/tsdb"
"github.com/uber-go/zap"
"go.uber.org/zap"
)

// The keys for statistics generated by the "write" module.
Expand Down Expand Up @@ -45,7 +45,7 @@ type PointsWriter struct {
mu sync.RWMutex
closing chan struct{}
WriteTimeout time.Duration
Logger zap.Logger
Logger *zap.Logger

Node *influxdb.Node

Expand Down Expand Up @@ -88,7 +88,7 @@ func NewPointsWriter() *PointsWriter {
return &PointsWriter{
closing: make(chan struct{}),
WriteTimeout: DefaultWriteTimeout,
Logger: zap.New(zap.NullEncoder()),
Logger: zap.NewNop(),
stats: &WriteStatistics{},
}
}
Expand Down Expand Up @@ -148,7 +148,7 @@ func (w *PointsWriter) AddWriteSubscriber(c chan<- *WritePointsRequest) {
}

// WithLogger sets the Logger on w.
func (w *PointsWriter) WithLogger(log zap.Logger) {
func (w *PointsWriter) WithLogger(log *zap.Logger) {
w.Logger = log.With(zap.String("service", "write"))
}

Expand Down
7 changes: 2 additions & 5 deletions coordinator/statement_executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import (
"github.com/davecgh/go-spew/spew"
"github.com/influxdata/influxdb/coordinator"
"github.com/influxdata/influxdb/internal"
"github.com/influxdata/influxdb/logger"
"github.com/influxdata/influxdb/models"
"github.com/influxdata/influxdb/query"
"github.com/influxdata/influxdb/services/meta"
"github.com/influxdata/influxdb/tsdb"
"github.com/influxdata/influxql"
"github.com/uber-go/zap"
)

const (
Expand Down Expand Up @@ -288,10 +288,7 @@ func NewQueryExecutor() *QueryExecutor {
if testing.Verbose() {
out = io.MultiWriter(out, os.Stderr)
}
e.QueryExecutor.WithLogger(zap.New(
zap.NewTextEncoder(),
zap.Output(zap.AddSync(out)),
))
e.QueryExecutor.WithLogger(logger.New(out))

return e
}
Expand Down
6 changes: 3 additions & 3 deletions internal/tsdb_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/influxdata/influxdb/query"
"github.com/influxdata/influxdb/tsdb"
"github.com/influxdata/influxql"
"github.com/uber-go/zap"
"go.uber.org/zap"
)

// TSDBStoreMock is a mockable implementation of tsdb.Store.
Expand Down Expand Up @@ -42,7 +42,7 @@ type TSDBStoreMock struct {
ShardsFn func(ids []uint64) []*tsdb.Shard
StatisticsFn func(tags map[string]string) []models.Statistic
TagValuesFn func(auth query.Authorizer, database string, cond influxql.Expr) ([]tsdb.TagValues, error)
WithLoggerFn func(log zap.Logger)
WithLoggerFn func(log *zap.Logger)
WriteToShardFn func(shardID uint64, points []models.Point) error
}

Expand Down Expand Up @@ -131,7 +131,7 @@ func (s *TSDBStoreMock) Statistics(tags map[string]string) []models.Statistic {
func (s *TSDBStoreMock) TagValues(auth query.Authorizer, database string, cond influxql.Expr) ([]tsdb.TagValues, error) {
return s.TagValuesFn(auth, database, cond)
}
func (s *TSDBStoreMock) WithLogger(log zap.Logger) {
func (s *TSDBStoreMock) WithLogger(log *zap.Logger) {
s.WithLoggerFn(log)
}
func (s *TSDBStoreMock) WriteToShard(shardID uint64, points []models.Point) error {
Expand Down
21 changes: 21 additions & 0 deletions logger/logger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package logger

import (
"io"
"time"

"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)

func New(w io.Writer) *zap.Logger {
config := zap.NewProductionEncoderConfig()
config.EncodeTime = func(ts time.Time, encoder zapcore.PrimitiveArrayEncoder) {
encoder.AppendString(ts.UTC().Format(time.RFC3339))
}
return zap.New(zapcore.NewCore(
zapcore.NewConsoleEncoder(config),
zapcore.AddSync(w),
zapcore.DebugLevel,
))
}
Loading

0 comments on commit 43a2622

Please sign in to comment.