mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Add support for json formatted logs (#1245)
This commit is contained in:
committed by
Reed Allman
parent
3920e15769
commit
4d30b9de09
@@ -48,6 +48,9 @@ const (
|
||||
// forcing usage through WithXxx configuration methods and documenting there vs.
|
||||
// expecting users to use os.SetEnv(EnvLogLevel, "debug") // why ?
|
||||
|
||||
// EnvLogFormat sets the stderr logging format, text or json only
|
||||
EnvLogFormat = "FN_LOG_FORMAT"
|
||||
|
||||
// EnvLogLevel sets the stderr logging level
|
||||
EnvLogLevel = "FN_LOG_LEVEL"
|
||||
|
||||
@@ -116,6 +119,9 @@ const (
|
||||
// EnvMaxRequestSize sets the limit in bytes for any API request's length.
|
||||
EnvMaxRequestSize = "FN_MAX_REQUEST_SIZE"
|
||||
|
||||
// DefaultLogFormat is text
|
||||
DefaultLogFormat = "text"
|
||||
|
||||
// DefaultLogLevel is info
|
||||
DefaultLogLevel = "info"
|
||||
|
||||
@@ -246,6 +252,7 @@ func NewFromEnv(ctx context.Context, opts ...Option) *Server {
|
||||
}
|
||||
opts = append(opts, WithWebPort(getEnvInt(EnvPort, DefaultPort)))
|
||||
opts = append(opts, WithGRPCPort(getEnvInt(EnvGRPCPort, DefaultGRPCPort)))
|
||||
opts = append(opts, WithLogFormat(getEnv(EnvLogFormat, DefaultLogFormat)))
|
||||
opts = append(opts, WithLogLevel(getEnv(EnvLogLevel, DefaultLogLevel)))
|
||||
opts = append(opts, WithLogDest(getEnv(EnvLogDest, DefaultLogDest), getEnv(EnvLogPrefix, "")))
|
||||
opts = append(opts, WithZipkin(getEnv(EnvZipkinURL, "")))
|
||||
@@ -309,6 +316,14 @@ func WithGRPCPort(port int) Option {
|
||||
}
|
||||
}
|
||||
|
||||
// WithLogFormat maps EnvLogFormat
|
||||
func WithLogFormat(format string) Option {
|
||||
return func(ctx context.Context, s *Server) error {
|
||||
common.SetLogFormat(format)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// WithLogLevel maps EnvLogLevel
|
||||
func WithLogLevel(ll string) Option {
|
||||
return func(ctx context.Context, s *Server) error {
|
||||
|
||||
@@ -19,6 +19,7 @@ import (
|
||||
|
||||
func testServer(ds models.Datastore, mq models.MessageQueue, logDB models.LogStore, rnr agent.Agent, nodeType NodeType, opts ...Option) *Server {
|
||||
return New(context.Background(), append(opts,
|
||||
WithLogFormat("text"),
|
||||
WithLogLevel("debug"),
|
||||
WithDatastore(ds),
|
||||
WithMQ(mq),
|
||||
|
||||
Reference in New Issue
Block a user