add log rotation config
This commit is contained in:
parent
bd7da26c42
commit
15d0a33716
@ -43,9 +43,33 @@ func SetGlobal(c *Config) {
|
||||
}
|
||||
|
||||
type LogConfig struct {
|
||||
Output string `yaml:",omitempty" json:"output,omitempty"`
|
||||
Level string `yaml:",omitempty" json:"level,omitempty"`
|
||||
Format string `yaml:",omitempty" json:"format,omitempty"`
|
||||
Output string `yaml:",omitempty" json:"output,omitempty"`
|
||||
Level string `yaml:",omitempty" json:"level,omitempty"`
|
||||
Format string `yaml:",omitempty" json:"format,omitempty"`
|
||||
Rotation *LogRotationConfig `yaml:",omitempty" json:"rotation,omitempty"`
|
||||
}
|
||||
|
||||
type LogRotationConfig struct {
|
||||
// MaxSize is the maximum size in megabytes of the log file before it gets
|
||||
// rotated. It defaults to 100 megabytes.
|
||||
MaxSize int `yaml:"maxSize,omitempty" json:"maxSize,omitempty"`
|
||||
// MaxAge is the maximum number of days to retain old log files based on the
|
||||
// timestamp encoded in their filename. Note that a day is defined as 24
|
||||
// hours and may not exactly correspond to calendar days due to daylight
|
||||
// savings, leap seconds, etc. The default is not to remove old log files
|
||||
// based on age.
|
||||
MaxAge int `yaml:"maxAge,omitempty" json:"maxAge,omitempty"`
|
||||
// MaxBackups is the maximum number of old log files to retain. The default
|
||||
// is to retain all old log files (though MaxAge may still cause them to get
|
||||
// deleted.)
|
||||
MaxBackups int `yaml:"maxBackups,omitempty" json:"maxBackups,omitempty"`
|
||||
// LocalTime determines if the time used for formatting the timestamps in
|
||||
// backup files is the computer's local time. The default is to use UTC
|
||||
// time.
|
||||
LocalTime bool `yaml:"localTime,omitempty" json:"localTime,omitempty"`
|
||||
// Compress determines if the rotated log files should be compressed
|
||||
// using gzip. The default is not to perform compression.
|
||||
Compress bool `yaml:"compress,omitempty" json:"compress,omitempty"`
|
||||
}
|
||||
|
||||
type ProfilingConfig struct {
|
||||
|
@ -7,7 +7,6 @@ import (
|
||||
"runtime"
|
||||
|
||||
"github.com/go-gost/core/logger"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
|
@ -14,6 +14,7 @@ import (
|
||||
"github.com/go-gost/core/service"
|
||||
sx "github.com/go-gost/x/internal/util/selector"
|
||||
xmetrics "github.com/go-gost/x/metrics"
|
||||
"github.com/rs/xid"
|
||||
)
|
||||
|
||||
type options struct {
|
||||
@ -141,6 +142,7 @@ func (s *defaultService) Serve() error {
|
||||
|
||||
host, _, _ := net.SplitHostPort(conn.RemoteAddr().String())
|
||||
ctx := sx.ContextWithHash(context.Background(), &sx.Hash{Source: host})
|
||||
ctx = ContextWithSid(ctx, xid.New().String())
|
||||
|
||||
if err := s.handler.Handle(ctx, conn); err != nil {
|
||||
s.options.logger.Error(err)
|
||||
@ -152,3 +154,18 @@ func (s *defaultService) Serve() error {
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
type sidKey struct{}
|
||||
|
||||
var (
|
||||
ssid sidKey
|
||||
)
|
||||
|
||||
func ContextWithSid(ctx context.Context, sid string) context.Context {
|
||||
return context.WithValue(ctx, ssid, sid)
|
||||
}
|
||||
|
||||
func SidFromContext(ctx context.Context) string {
|
||||
v, _ := ctx.Value(ssid).(string)
|
||||
return v
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user