diff options
Diffstat (limited to 'vendor/google.golang.org/grpc/grpclog')
| -rw-r--r-- | vendor/google.golang.org/grpc/grpclog/component.go | 117 | ||||
| -rw-r--r-- | vendor/google.golang.org/grpc/grpclog/grpclog.go | 132 | ||||
| -rw-r--r-- | vendor/google.golang.org/grpc/grpclog/logger.go | 87 | ||||
| -rw-r--r-- | vendor/google.golang.org/grpc/grpclog/loggerv2.go | 259 | 
4 files changed, 595 insertions, 0 deletions
diff --git a/vendor/google.golang.org/grpc/grpclog/component.go b/vendor/google.golang.org/grpc/grpclog/component.go new file mode 100644 index 0000000..8358dd6 --- /dev/null +++ b/vendor/google.golang.org/grpc/grpclog/component.go @@ -0,0 +1,117 @@ +/* + * + * Copyright 2020 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + *     http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package grpclog + +import ( +	"fmt" + +	"google.golang.org/grpc/internal/grpclog" +) + +// componentData records the settings for a component. +type componentData struct { +	name string +} + +var cache = map[string]*componentData{} + +func (c *componentData) InfoDepth(depth int, args ...interface{}) { +	args = append([]interface{}{"[" + string(c.name) + "]"}, args...) +	grpclog.InfoDepth(depth+1, args...) +} + +func (c *componentData) WarningDepth(depth int, args ...interface{}) { +	args = append([]interface{}{"[" + string(c.name) + "]"}, args...) +	grpclog.WarningDepth(depth+1, args...) +} + +func (c *componentData) ErrorDepth(depth int, args ...interface{}) { +	args = append([]interface{}{"[" + string(c.name) + "]"}, args...) +	grpclog.ErrorDepth(depth+1, args...) +} + +func (c *componentData) FatalDepth(depth int, args ...interface{}) { +	args = append([]interface{}{"[" + string(c.name) + "]"}, args...) +	grpclog.FatalDepth(depth+1, args...) +} + +func (c *componentData) Info(args ...interface{}) { +	c.InfoDepth(1, args...) +} + +func (c *componentData) Warning(args ...interface{}) { +	c.WarningDepth(1, args...) +} + +func (c *componentData) Error(args ...interface{}) { +	c.ErrorDepth(1, args...) +} + +func (c *componentData) Fatal(args ...interface{}) { +	c.FatalDepth(1, args...) +} + +func (c *componentData) Infof(format string, args ...interface{}) { +	c.InfoDepth(1, fmt.Sprintf(format, args...)) +} + +func (c *componentData) Warningf(format string, args ...interface{}) { +	c.WarningDepth(1, fmt.Sprintf(format, args...)) +} + +func (c *componentData) Errorf(format string, args ...interface{}) { +	c.ErrorDepth(1, fmt.Sprintf(format, args...)) +} + +func (c *componentData) Fatalf(format string, args ...interface{}) { +	c.FatalDepth(1, fmt.Sprintf(format, args...)) +} + +func (c *componentData) Infoln(args ...interface{}) { +	c.InfoDepth(1, args...) +} + +func (c *componentData) Warningln(args ...interface{}) { +	c.WarningDepth(1, args...) +} + +func (c *componentData) Errorln(args ...interface{}) { +	c.ErrorDepth(1, args...) +} + +func (c *componentData) Fatalln(args ...interface{}) { +	c.FatalDepth(1, args...) +} + +func (c *componentData) V(l int) bool { +	return V(l) +} + +// Component creates a new component and returns it for logging. If a component +// with the name already exists, nothing will be created and it will be +// returned. SetLoggerV2 will panic if it is called with a logger created by +// Component. +func Component(componentName string) DepthLoggerV2 { +	if cData, ok := cache[componentName]; ok { +		return cData +	} +	c := &componentData{componentName} +	cache[componentName] = c +	return c +} diff --git a/vendor/google.golang.org/grpc/grpclog/grpclog.go b/vendor/google.golang.org/grpc/grpclog/grpclog.go new file mode 100644 index 0000000..c8bb2be --- /dev/null +++ b/vendor/google.golang.org/grpc/grpclog/grpclog.go @@ -0,0 +1,132 @@ +/* + * + * Copyright 2017 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + *     http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// Package grpclog defines logging for grpc. +// +// All logs in transport and grpclb packages only go to verbose level 2. +// All logs in other packages in grpc are logged in spite of the verbosity level. +// +// In the default logger, +// severity level can be set by environment variable GRPC_GO_LOG_SEVERITY_LEVEL, +// verbosity level can be set by GRPC_GO_LOG_VERBOSITY_LEVEL. +package grpclog // import "google.golang.org/grpc/grpclog" + +import ( +	"os" + +	"google.golang.org/grpc/internal/grpclog" +) + +func init() { +	SetLoggerV2(newLoggerV2()) +} + +// V reports whether verbosity level l is at least the requested verbose level. +func V(l int) bool { +	return grpclog.Logger.V(l) +} + +// Info logs to the INFO log. +func Info(args ...interface{}) { +	grpclog.Logger.Info(args...) +} + +// Infof logs to the INFO log. Arguments are handled in the manner of fmt.Printf. +func Infof(format string, args ...interface{}) { +	grpclog.Logger.Infof(format, args...) +} + +// Infoln logs to the INFO log. Arguments are handled in the manner of fmt.Println. +func Infoln(args ...interface{}) { +	grpclog.Logger.Infoln(args...) +} + +// Warning logs to the WARNING log. +func Warning(args ...interface{}) { +	grpclog.Logger.Warning(args...) +} + +// Warningf logs to the WARNING log. Arguments are handled in the manner of fmt.Printf. +func Warningf(format string, args ...interface{}) { +	grpclog.Logger.Warningf(format, args...) +} + +// Warningln logs to the WARNING log. Arguments are handled in the manner of fmt.Println. +func Warningln(args ...interface{}) { +	grpclog.Logger.Warningln(args...) +} + +// Error logs to the ERROR log. +func Error(args ...interface{}) { +	grpclog.Logger.Error(args...) +} + +// Errorf logs to the ERROR log. Arguments are handled in the manner of fmt.Printf. +func Errorf(format string, args ...interface{}) { +	grpclog.Logger.Errorf(format, args...) +} + +// Errorln logs to the ERROR log. Arguments are handled in the manner of fmt.Println. +func Errorln(args ...interface{}) { +	grpclog.Logger.Errorln(args...) +} + +// Fatal logs to the FATAL log. Arguments are handled in the manner of fmt.Print. +// It calls os.Exit() with exit code 1. +func Fatal(args ...interface{}) { +	grpclog.Logger.Fatal(args...) +	// Make sure fatal logs will exit. +	os.Exit(1) +} + +// Fatalf logs to the FATAL log. Arguments are handled in the manner of fmt.Printf. +// It calls os.Exit() with exit code 1. +func Fatalf(format string, args ...interface{}) { +	grpclog.Logger.Fatalf(format, args...) +	// Make sure fatal logs will exit. +	os.Exit(1) +} + +// Fatalln logs to the FATAL log. Arguments are handled in the manner of fmt.Println. +// It calle os.Exit()) with exit code 1. +func Fatalln(args ...interface{}) { +	grpclog.Logger.Fatalln(args...) +	// Make sure fatal logs will exit. +	os.Exit(1) +} + +// Print prints to the logger. Arguments are handled in the manner of fmt.Print. +// +// Deprecated: use Info. +func Print(args ...interface{}) { +	grpclog.Logger.Info(args...) +} + +// Printf prints to the logger. Arguments are handled in the manner of fmt.Printf. +// +// Deprecated: use Infof. +func Printf(format string, args ...interface{}) { +	grpclog.Logger.Infof(format, args...) +} + +// Println prints to the logger. Arguments are handled in the manner of fmt.Println. +// +// Deprecated: use Infoln. +func Println(args ...interface{}) { +	grpclog.Logger.Infoln(args...) +} diff --git a/vendor/google.golang.org/grpc/grpclog/logger.go b/vendor/google.golang.org/grpc/grpclog/logger.go new file mode 100644 index 0000000..ef06a48 --- /dev/null +++ b/vendor/google.golang.org/grpc/grpclog/logger.go @@ -0,0 +1,87 @@ +/* + * + * Copyright 2015 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + *     http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package grpclog + +import "google.golang.org/grpc/internal/grpclog" + +// Logger mimics golang's standard Logger as an interface. +// +// Deprecated: use LoggerV2. +type Logger interface { +	Fatal(args ...interface{}) +	Fatalf(format string, args ...interface{}) +	Fatalln(args ...interface{}) +	Print(args ...interface{}) +	Printf(format string, args ...interface{}) +	Println(args ...interface{}) +} + +// SetLogger sets the logger that is used in grpc. Call only from +// init() functions. +// +// Deprecated: use SetLoggerV2. +func SetLogger(l Logger) { +	grpclog.Logger = &loggerWrapper{Logger: l} +} + +// loggerWrapper wraps Logger into a LoggerV2. +type loggerWrapper struct { +	Logger +} + +func (g *loggerWrapper) Info(args ...interface{}) { +	g.Logger.Print(args...) +} + +func (g *loggerWrapper) Infoln(args ...interface{}) { +	g.Logger.Println(args...) +} + +func (g *loggerWrapper) Infof(format string, args ...interface{}) { +	g.Logger.Printf(format, args...) +} + +func (g *loggerWrapper) Warning(args ...interface{}) { +	g.Logger.Print(args...) +} + +func (g *loggerWrapper) Warningln(args ...interface{}) { +	g.Logger.Println(args...) +} + +func (g *loggerWrapper) Warningf(format string, args ...interface{}) { +	g.Logger.Printf(format, args...) +} + +func (g *loggerWrapper) Error(args ...interface{}) { +	g.Logger.Print(args...) +} + +func (g *loggerWrapper) Errorln(args ...interface{}) { +	g.Logger.Println(args...) +} + +func (g *loggerWrapper) Errorf(format string, args ...interface{}) { +	g.Logger.Printf(format, args...) +} + +func (g *loggerWrapper) V(l int) bool { +	// Returns true for all verbose level. +	return true +} diff --git a/vendor/google.golang.org/grpc/grpclog/loggerv2.go b/vendor/google.golang.org/grpc/grpclog/loggerv2.go new file mode 100644 index 0000000..b5560b4 --- /dev/null +++ b/vendor/google.golang.org/grpc/grpclog/loggerv2.go @@ -0,0 +1,259 @@ +/* + * + * Copyright 2017 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + *     http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package grpclog + +import ( +	"encoding/json" +	"fmt" +	"io" +	"io/ioutil" +	"log" +	"os" +	"strconv" +	"strings" + +	"google.golang.org/grpc/internal/grpclog" +) + +// LoggerV2 does underlying logging work for grpclog. +type LoggerV2 interface { +	// Info logs to INFO log. Arguments are handled in the manner of fmt.Print. +	Info(args ...interface{}) +	// Infoln logs to INFO log. Arguments are handled in the manner of fmt.Println. +	Infoln(args ...interface{}) +	// Infof logs to INFO log. Arguments are handled in the manner of fmt.Printf. +	Infof(format string, args ...interface{}) +	// Warning logs to WARNING log. Arguments are handled in the manner of fmt.Print. +	Warning(args ...interface{}) +	// Warningln logs to WARNING log. Arguments are handled in the manner of fmt.Println. +	Warningln(args ...interface{}) +	// Warningf logs to WARNING log. Arguments are handled in the manner of fmt.Printf. +	Warningf(format string, args ...interface{}) +	// Error logs to ERROR log. Arguments are handled in the manner of fmt.Print. +	Error(args ...interface{}) +	// Errorln logs to ERROR log. Arguments are handled in the manner of fmt.Println. +	Errorln(args ...interface{}) +	// Errorf logs to ERROR log. Arguments are handled in the manner of fmt.Printf. +	Errorf(format string, args ...interface{}) +	// Fatal logs to ERROR log. Arguments are handled in the manner of fmt.Print. +	// gRPC ensures that all Fatal logs will exit with os.Exit(1). +	// Implementations may also call os.Exit() with a non-zero exit code. +	Fatal(args ...interface{}) +	// Fatalln logs to ERROR log. Arguments are handled in the manner of fmt.Println. +	// gRPC ensures that all Fatal logs will exit with os.Exit(1). +	// Implementations may also call os.Exit() with a non-zero exit code. +	Fatalln(args ...interface{}) +	// Fatalf logs to ERROR log. Arguments are handled in the manner of fmt.Printf. +	// gRPC ensures that all Fatal logs will exit with os.Exit(1). +	// Implementations may also call os.Exit() with a non-zero exit code. +	Fatalf(format string, args ...interface{}) +	// V reports whether verbosity level l is at least the requested verbose level. +	V(l int) bool +} + +// SetLoggerV2 sets logger that is used in grpc to a V2 logger. +// Not mutex-protected, should be called before any gRPC functions. +func SetLoggerV2(l LoggerV2) { +	if _, ok := l.(*componentData); ok { +		panic("cannot use component logger as grpclog logger") +	} +	grpclog.Logger = l +	grpclog.DepthLogger, _ = l.(grpclog.DepthLoggerV2) +} + +const ( +	// infoLog indicates Info severity. +	infoLog int = iota +	// warningLog indicates Warning severity. +	warningLog +	// errorLog indicates Error severity. +	errorLog +	// fatalLog indicates Fatal severity. +	fatalLog +) + +// severityName contains the string representation of each severity. +var severityName = []string{ +	infoLog:    "INFO", +	warningLog: "WARNING", +	errorLog:   "ERROR", +	fatalLog:   "FATAL", +} + +// loggerT is the default logger used by grpclog. +type loggerT struct { +	m          []*log.Logger +	v          int +	jsonFormat bool +} + +// NewLoggerV2 creates a loggerV2 with the provided writers. +// Fatal logs will be written to errorW, warningW, infoW, followed by exit(1). +// Error logs will be written to errorW, warningW and infoW. +// Warning logs will be written to warningW and infoW. +// Info logs will be written to infoW. +func NewLoggerV2(infoW, warningW, errorW io.Writer) LoggerV2 { +	return newLoggerV2WithConfig(infoW, warningW, errorW, loggerV2Config{}) +} + +// NewLoggerV2WithVerbosity creates a loggerV2 with the provided writers and +// verbosity level. +func NewLoggerV2WithVerbosity(infoW, warningW, errorW io.Writer, v int) LoggerV2 { +	return newLoggerV2WithConfig(infoW, warningW, errorW, loggerV2Config{verbose: v}) +} + +type loggerV2Config struct { +	verbose    int +	jsonFormat bool +} + +func newLoggerV2WithConfig(infoW, warningW, errorW io.Writer, c loggerV2Config) LoggerV2 { +	var m []*log.Logger +	flag := log.LstdFlags +	if c.jsonFormat { +		flag = 0 +	} +	m = append(m, log.New(infoW, "", flag)) +	m = append(m, log.New(io.MultiWriter(infoW, warningW), "", flag)) +	ew := io.MultiWriter(infoW, warningW, errorW) // ew will be used for error and fatal. +	m = append(m, log.New(ew, "", flag)) +	m = append(m, log.New(ew, "", flag)) +	return &loggerT{m: m, v: c.verbose, jsonFormat: c.jsonFormat} +} + +// newLoggerV2 creates a loggerV2 to be used as default logger. +// All logs are written to stderr. +func newLoggerV2() LoggerV2 { +	errorW := ioutil.Discard +	warningW := ioutil.Discard +	infoW := ioutil.Discard + +	logLevel := os.Getenv("GRPC_GO_LOG_SEVERITY_LEVEL") +	switch logLevel { +	case "", "ERROR", "error": // If env is unset, set level to ERROR. +		errorW = os.Stderr +	case "WARNING", "warning": +		warningW = os.Stderr +	case "INFO", "info": +		infoW = os.Stderr +	} + +	var v int +	vLevel := os.Getenv("GRPC_GO_LOG_VERBOSITY_LEVEL") +	if vl, err := strconv.Atoi(vLevel); err == nil { +		v = vl +	} + +	jsonFormat := strings.EqualFold(os.Getenv("GRPC_GO_LOG_FORMATTER"), "json") + +	return newLoggerV2WithConfig(infoW, warningW, errorW, loggerV2Config{ +		verbose:    v, +		jsonFormat: jsonFormat, +	}) +} + +func (g *loggerT) output(severity int, s string) { +	sevStr := severityName[severity] +	if !g.jsonFormat { +		g.m[severity].Output(2, fmt.Sprintf("%v: %v", sevStr, s)) +		return +	} +	// TODO: we can also include the logging component, but that needs more +	// (API) changes. +	b, _ := json.Marshal(map[string]string{ +		"severity": sevStr, +		"message":  s, +	}) +	g.m[severity].Output(2, string(b)) +} + +func (g *loggerT) Info(args ...interface{}) { +	g.output(infoLog, fmt.Sprint(args...)) +} + +func (g *loggerT) Infoln(args ...interface{}) { +	g.output(infoLog, fmt.Sprintln(args...)) +} + +func (g *loggerT) Infof(format string, args ...interface{}) { +	g.output(infoLog, fmt.Sprintf(format, args...)) +} + +func (g *loggerT) Warning(args ...interface{}) { +	g.output(warningLog, fmt.Sprint(args...)) +} + +func (g *loggerT) Warningln(args ...interface{}) { +	g.output(warningLog, fmt.Sprintln(args...)) +} + +func (g *loggerT) Warningf(format string, args ...interface{}) { +	g.output(warningLog, fmt.Sprintf(format, args...)) +} + +func (g *loggerT) Error(args ...interface{}) { +	g.output(errorLog, fmt.Sprint(args...)) +} + +func (g *loggerT) Errorln(args ...interface{}) { +	g.output(errorLog, fmt.Sprintln(args...)) +} + +func (g *loggerT) Errorf(format string, args ...interface{}) { +	g.output(errorLog, fmt.Sprintf(format, args...)) +} + +func (g *loggerT) Fatal(args ...interface{}) { +	g.output(fatalLog, fmt.Sprint(args...)) +	os.Exit(1) +} + +func (g *loggerT) Fatalln(args ...interface{}) { +	g.output(fatalLog, fmt.Sprintln(args...)) +	os.Exit(1) +} + +func (g *loggerT) Fatalf(format string, args ...interface{}) { +	g.output(fatalLog, fmt.Sprintf(format, args...)) +	os.Exit(1) +} + +func (g *loggerT) V(l int) bool { +	return l <= g.v +} + +// DepthLoggerV2 logs at a specified call frame. If a LoggerV2 also implements +// DepthLoggerV2, the below functions will be called with the appropriate stack +// depth set for trivial functions the logger may ignore. +// +// # Experimental +// +// Notice: This type is EXPERIMENTAL and may be changed or removed in a +// later release. +type DepthLoggerV2 interface { +	LoggerV2 +	// InfoDepth logs to INFO log at the specified depth. Arguments are handled in the manner of fmt.Println. +	InfoDepth(depth int, args ...interface{}) +	// WarningDepth logs to WARNING log at the specified depth. Arguments are handled in the manner of fmt.Println. +	WarningDepth(depth int, args ...interface{}) +	// ErrorDepth logs to ERROR log at the specified depth. Arguments are handled in the manner of fmt.Println. +	ErrorDepth(depth int, args ...interface{}) +	// FatalDepth logs to FATAL log at the specified depth. Arguments are handled in the manner of fmt.Println. +	FatalDepth(depth int, args ...interface{}) +}  | 
