Skip to content

Commit

Permalink
Merge pull request #9055 from influxdata/js-update-zap-logger
Browse files Browse the repository at this point in the history
Update the zap logger dependency
  • Loading branch information
jsternberg authored Nov 11, 2017
2 parents ef42c36 + 0b7c56b commit 7cae889
Show file tree
Hide file tree
Showing 54 changed files with 217 additions and 238 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## v1.5.0 [unreleased]

### Breaking changes

* The default logging format has been changed. See [#9055](https://github.com/influxdata/influxdb/pull/9055) for details.

### Bugfixes

- [#8538](https://github.com/influxdata/influxdb/pull/8538): Fix panic: runtime error: slice bounds out of range
Expand Down
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(cmd.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 @@ -302,10 +302,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 @@ -43,7 +43,7 @@ type TSDBStoreMock struct {
StatisticsFn func(tags map[string]string) []models.Statistic
TagKeysFn func(auth query.Authorizer, shardIDs []uint64, cond influxql.Expr) ([]tsdb.TagKeys, error)
TagValuesFn func(auth query.Authorizer, shardIDs []uint64, 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 @@ -135,7 +135,7 @@ func (s *TSDBStoreMock) TagKeys(auth query.Authorizer, shardIDs []uint64, cond i
func (s *TSDBStoreMock) TagValues(auth query.Authorizer, shardIDs []uint64, cond influxql.Expr) ([]tsdb.TagValues, error) {
return s.TagValuesFn(auth, shardIDs, 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 7cae889

Please sign in to comment.