Skip to content

Commit

Permalink
Allow the server's logger to be passed in via the ServeConfig (#51)
Browse files Browse the repository at this point in the history
* Allow the server's logger to be passed in via the serve options

* Add comment about the server's logger
  • Loading branch information
briankassouf committed Jan 11, 2018
1 parent e2fbc68 commit e37881a
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ type ServeConfig struct {
// the gRPC health checking service. This is not optional since go-plugin
// relies on this to implement Ping().
GRPCServer func([]grpc.ServerOption) *grpc.Server

// Logger is used to pass a logger into the server. If none is provided the
// server will create a default logger.
Logger hclog.Logger
}

// Protocol returns the protocol that this server should speak.
Expand Down Expand Up @@ -106,12 +110,15 @@ func Serve(opts *ServeConfig) {
// Logging goes to the original stderr
log.SetOutput(os.Stderr)

// internal logger to os.Stderr
logger := hclog.New(&hclog.LoggerOptions{
Level: hclog.Trace,
Output: os.Stderr,
JSONFormat: true,
})
logger := opts.Logger
if logger == nil {
// internal logger to os.Stderr
logger = hclog.New(&hclog.LoggerOptions{
Level: hclog.Trace,
Output: os.Stderr,
JSONFormat: true,
})
}

// Create our new stdout, stderr files. These will override our built-in
// stdout/stderr so that it works across the stream boundary.
Expand Down

0 comments on commit e37881a

Please sign in to comment.