Documentation ¶
Overview ¶
Package spec provides a zap.Logger creation function NewStandardLogger() for applications to use and write logs with.
NewStandardLogger() can be used like so:
package main import "go.uber.org/zap" import "github.com/skuid/spec" func init() { l, err := spec.NewStandardLogger() // handle error zap.ReplaceGlobals(l) } func main() { zap.L().Debug("A debug message") zap.L().Info("An info message") zap.L().Info( "An info message with values", zap.String("key", "value"), ) zap.L().Error("An error message") err := errors.New("some error") zap.L().Error("An error message", zap.Error(err)) }
Index ¶
- func GetLogLevel(level string) zapcore.Level
- func LevelPflag(name string, defaultLevel zapcore.Level, usage string) (*pflag.Flag, *zapcore.Level)
- func LevelPflagCommandLine(name string, defaultLevel zapcore.Level, usage string) *zapcore.Level
- func LevelPflagP(name, shorthand string, defaultLevel zapcore.Level, usage string) (*pflag.Flag, *zapcore.Level)
- func LevelPflagPCommandLine(name, shorthand string, defaultLevel zapcore.Level, usage string) *zapcore.Level
- func MetricsServer(port int)
- func NewStandardLevelLogger(level zapcore.Level) (l *zap.Logger, err error)
- func NewStandardLogger() (l *zap.Logger, err error)
- type SelectorSet
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetLogLevel ¶ added in v1.0.18
GetLogLevel get a zapcore level from an string
levels can be debug, info, warning, error, dpanic, panic, fatal
func LevelPflag ¶ added in v1.0.4
func LevelPflag(name string, defaultLevel zapcore.Level, usage string) (*pflag.Flag, *zapcore.Level)
LevelPflag returns a *pflag.Flag and a *zapcore.Level for the given flag arguments
fset := pflag.CommandLine lflag, level := spec.LevelPflag("level", zapcore.InfoLevel, "Log level") fset.AddFlag(lflag)
func LevelPflagCommandLine ¶ added in v1.0.4
LevelPflagCommandLine returns a *zapcore.Level for the given flag arguments. The flag is added to the pflag.CommandLine flagset
level := spec.LevelPflagCommandLine("level", zapcore.InfoLevel, "Log level")
func LevelPflagP ¶ added in v1.0.4
func LevelPflagP(name, shorthand string, defaultLevel zapcore.Level, usage string) (*pflag.Flag, *zapcore.Level)
LevelPflagP returns a *pflag.Flag and a *zapcore.Level for the given flag arguments
fset := pflag.CommandLine lflag, level := spec.LevelPflagP("level","l", zapcore.InfoLevel, "Log level") fset.AddFlag(lflag)
func LevelPflagPCommandLine ¶ added in v1.0.4
func LevelPflagPCommandLine(name, shorthand string, defaultLevel zapcore.Level, usage string) *zapcore.Level
LevelPflagPCommandLine returns a *zapcore.Level for the given flag arguments. The flag is added to the pflag.CommandLine flagset
level := spec.LevelPflagPCommandLine("level", "l", zapcore.InfoLevel, "Log level")
func MetricsServer ¶ added in v1.0.5
func MetricsServer(port int)
MetricsServer is a convenience function for handling metrics and healthchecks. It listens on the provided port without authentication.
go spec.MetricsServer(3001)
func NewStandardLevelLogger ¶ added in v1.0.4
NewStandardLevelLogger creates a new zap.Logger based on common configuration. It accepts a zapcore.Level as the level to filter logs on.
This is intended to be used with zap.ReplaceGlobals() in an application's main.go.
func NewStandardLogger ¶
NewStandardLogger creates a new zap.Logger based on common configuration
This is intended to be used with zap.ReplaceGlobals() in an application's main.go.
Example ¶
package main import ( "github.com/skuid/spec" "go.uber.org/zap" ) func main() { l, _ := spec.NewStandardLogger() // handle error zap.ReplaceGlobals(l) }
Output:
Types ¶
type SelectorSet ¶
type SelectorSet []string
SelectorSet is a custom flag that takes key-value pairs joined by equal signs and separated by commas. The flag may be specified multiple times and the values will be merged.
Ex:
mycmd -flag key=value,key2=value2 -flag key3=value3
Calling ToMap() results in:
map[string]string{ "key": "value", "key2": "value2", "key3": "value3", }
func (*SelectorSet) Set ¶
func (ss *SelectorSet) Set(selector string) error
Set satisfies the flag.Value interface
func (*SelectorSet) String ¶
func (ss *SelectorSet) String() string
String satisfies the flag.Value interface
func (SelectorSet) ToMap ¶
func (ss SelectorSet) ToMap() map[string]string
ToMap returns a map representation of the SelectorSet
func (*SelectorSet) Type ¶
func (ss *SelectorSet) Type() string
Type returns the type of the flag as a string
Directories ¶
Path | Synopsis |
---|---|
Package example contains an example web application that uses packages contained in this project.
|
Package example contains an example web application that uses packages contained in this project. |
Package lifecycle provides variables for controlling an application's lifecycle, and a function for gracefully shutting down an http.Server.
|
Package lifecycle provides variables for controlling an application's lifecycle, and a function for gracefully shutting down an http.Server. |
Package middlewares provides middleware function for decorating HTTP handlers.
|
Package middlewares provides middleware function for decorating HTTP handlers. |
Package redis adds built-in Redis support with our common configuration.
|
Package redis adds built-in Redis support with our common configuration. |