本文整理匯總了Golang中github.com/apex/log.Interface.WithFields方法的典型用法代碼示例。如果您正苦於以下問題:Golang Interface.WithFields方法的具體用法?Golang Interface.WithFields怎麽用?Golang Interface.WithFields使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/apex/log.Interface
的用法示例。
在下文中一共展示了Interface.WithFields方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: NewServer
// NewServer sets up a new server instance.
func NewServer(ctx log.Interface, address, templateFilename string) Server {
return Server{
Log: ctx.WithFields(log.Fields{
"module": "Server",
"address": address,
}),
IndexTemplate: template.Must(template.ParseFiles(templateFilename)),
Address: address,
Hub: NewGameHub(ctx),
}
}
示例2: NewGame
// NewGame creates a new game instance.
func NewGame(ctx log.Interface, id string) Game {
gs := NewGameState(ctx)
cp := NewCommandProcessor(&gs)
return Game{
Log: ctx.WithFields(log.Fields{
"module": "Game",
"id": id,
}),
State: &gs,
CommandProcessor: &cp,
register: make(chan *User),
unregister: make(chan *User),
commands: make(chan Command),
}
}
示例3: New
// New creates a new Component
func New(ctx log.Interface, serviceName string, announcedAddress string) (*Component, error) {
go func() {
memstats := new(runtime.MemStats)
for range time.Tick(time.Minute) {
runtime.ReadMemStats(memstats)
ctx.WithFields(log.Fields{
"Goroutines": runtime.NumGoroutine(),
"Memory": float64(memstats.Alloc) / 1000000,
}).Debugf("Stats")
}
}()
// Disable gRPC tracing
// SEE: https://github.com/grpc/grpc-go/issues/695
grpc.EnableTracing = false
component := &Component{
Config: ConfigFromViper(),
Ctx: ctx,
Identity: &pb_discovery.Announcement{
Id: viper.GetString("id"),
Description: viper.GetString("description"),
ServiceName: serviceName,
ServiceVersion: fmt.Sprintf("%s-%s (%s)", viper.GetString("version"), viper.GetString("gitCommit"), viper.GetString("buildDate")),
NetAddress: announcedAddress,
Public: viper.GetBool("public"),
},
AccessToken: viper.GetString("auth-token"),
}
if err := component.InitAuth(); err != nil {
return nil, err
}
if serviceName != "discovery" && serviceName != "networkserver" {
var err error
component.Discovery, err = pb_discovery.NewClient(
viper.GetString("discovery-address"),
component.Identity,
func() string {
token, _ := component.BuildJWT()
return token
},
)
if err != nil {
return nil, err
}
}
if healthPort := viper.GetInt("health-port"); healthPort > 0 {
http.HandleFunc("/healthz", func(w http.ResponseWriter, req *http.Request) {
switch component.GetStatus() {
case StatusHealthy:
w.WriteHeader(200)
w.Write([]byte("Status is HEALTHY"))
return
case StatusUnhealthy:
w.WriteHeader(503)
w.Write([]byte("Status is UNHEALTHY"))
return
}
})
go http.ListenAndServe(fmt.Sprintf(":%d", healthPort), nil)
}
if monitors := viper.GetStringMapString("monitor-servers"); len(monitors) != 0 {
component.Monitors = make(map[string]*pb_monitor.Client)
for name, addr := range monitors {
var err error
component.Monitors[name], err = pb_monitor.NewClient(ctx.WithField("Monitor", name), addr)
if err != nil {
return nil, err
}
}
}
return component, nil
}
示例4: Execute
BufferSize: 10,
}), logLevel))
}
ctx = &log.Logger{
Handler: multiHandler.New(logHandlers...),
}
// Set the API/gRPC logger
ttnlog.Set(apex.Wrap(ctx))
grpclog.SetLogger(grpc.Wrap(ttnlog.Get()))
ctx.WithFields(log.Fields{
"ComponentID": viper.GetString("id"),
"Description": viper.GetString("description"),
"Discovery Server Address": viper.GetString("discovery-address"),
"Auth Servers": viper.GetStringMapString("auth-servers"),
"Monitors": viper.GetStringMapString("monitor-servers"),
}).Info("Initializing The Things Network")
},
PersistentPostRun: func(cmd *cobra.Command, args []string) {
if logFile != nil {
logFile.Close()
}
},
}
// Execute adds all child commands to the root command sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
defer func() {