mirror of https://github.com/dnomd343/XProxy.git
Dnomd343
1 year ago
4 changed files with 156 additions and 14 deletions
@ -1,27 +1,26 @@ |
|||
github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8= |
|||
github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= |
|||
github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs= |
|||
github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= |
|||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= |
|||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= |
|||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= |
|||
github.com/go-http-utils/headers v0.0.0-20181008091004-fed159eddc2a h1:v6zMvHuY9yue4+QkG/HQ/W67wvtQmWJ4SDo9aK/GIno= |
|||
github.com/go-http-utils/headers v0.0.0-20181008091004-fed159eddc2a/go.mod h1:I79BieaU4fxrw4LMXby6q5OS9XnoR9UIKLOzDFjUmuw= |
|||
github.com/klauspost/compress v1.16.7 h1:2mk3MPGNzKyxErAw8YaohYh69+pa4sIQSC0fPGCFR9I= |
|||
github.com/gookit/color v1.5.4 h1:FZmqs7XOyGgCAxmWyPslpiok1k05wmY3SJTytgvYFs0= |
|||
github.com/gookit/color v1.5.4/go.mod h1:pZJOeOS8DM43rXbp4AZo1n9zCU2qjpcRko0b6/QJi9w= |
|||
github.com/klauspost/compress v1.16.7/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= |
|||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= |
|||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= |
|||
github.com/robfig/cron v1.2.0 h1:ZjScXvvxeQ63Dbyxy76Fj3AT3Ut0aKsyd2/tl3DTMuQ= |
|||
github.com/robfig/cron v1.2.0/go.mod h1:JGuDeoQd7Z6yL4zQhZ3OPEVHB7fL6Ka6skscFHfmt2k= |
|||
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= |
|||
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= |
|||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= |
|||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= |
|||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= |
|||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ= |
|||
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 h1:QldyIu/L63oPpyvQmHgvgickp1Yw510KJOqX7H24mg8= |
|||
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778/go.mod h1:2MuV+tbUrU1zIOPMxZ5EncGwgmMJsa+9ucAQZXxsObs= |
|||
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= |
|||
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= |
|||
go.uber.org/zap v1.25.0 h1:4Hvk6GtkucQ790dqmj7l1eEnRdKm3k3ZUrUMS2d5+5c= |
|||
go.uber.org/zap v1.25.0/go.mod h1:JIAUzQIH94IC4fOJQm7gMmBJP5k7wQfdcnYdPoEXJYk= |
|||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= |
|||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= |
|||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= |
|||
golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA= |
|||
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= |
|||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= |
|||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
|||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= |
|||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
|||
|
@ -0,0 +1,134 @@ |
|||
package logger |
|||
|
|||
import ( |
|||
"fmt" |
|||
"go.uber.org/zap" |
|||
"os" |
|||
"time" |
|||
) |
|||
import "go.uber.org/zap/zapcore" |
|||
|
|||
var Logger *zap.SugaredLogger |
|||
|
|||
const ( |
|||
logTmFmt = "2006-01-02 15:04:05" |
|||
) |
|||
|
|||
func init() { |
|||
|
|||
//coreConfig := zapcore.EncoderConfig{
|
|||
// TimeKey: "ts",
|
|||
// LevelKey: "level",
|
|||
// NameKey: "logger",
|
|||
// CallerKey: "caller",
|
|||
// FunctionKey: zapcore.OmitKey,
|
|||
// MessageKey: "msg",
|
|||
// StacktraceKey: "stacktrace",
|
|||
// LineEnding: zapcore.DefaultLineEnding, // 默认换行符"\n"
|
|||
// EncodeLevel: zapcore.CapitalColorLevelEncoder,
|
|||
// EncodeTime: zapcore.RFC3339TimeEncoder, // 日志时间格式显示
|
|||
// EncodeDuration: zapcore.MillisDurationEncoder, // 时间序列化,Duration为经过的浮点秒数
|
|||
// EncodeCaller: zapcore.ShortCallerEncoder, // 日志行号显示
|
|||
//}
|
|||
//
|
|||
//encoder := zapcore.NewConsoleEncoder(coreConfig)
|
|||
//
|
|||
//newCore := zapcore.NewCore(encoder, zapcore.AddSync(os.Stdout), zapcore.DebugLevel)
|
|||
//
|
|||
//logger := zap.New(newCore)
|
|||
//
|
|||
//Logger = logger.Sugar()
|
|||
|
|||
GetLogger() |
|||
|
|||
//log, err := zap.NewDevelopment()
|
|||
//if err != nil {
|
|||
// panic("log utils init failed")
|
|||
//}
|
|||
|
|||
// TODO: more zap logger configure
|
|||
// TODO: reserve raw logger handle
|
|||
|
|||
//Logger = log.Sugar()
|
|||
} |
|||
|
|||
func GetLogger() { |
|||
config := zapcore.EncoderConfig{ |
|||
MessageKey: "M", |
|||
LevelKey: "L", |
|||
TimeKey: "T", |
|||
NameKey: "N", |
|||
CallerKey: "C", |
|||
FunctionKey: "F", |
|||
StacktraceKey: "S", |
|||
SkipLineEnding: false, |
|||
LineEnding: "\n", |
|||
|
|||
EncodeLevel: logEncodeLevel, |
|||
//EncodeLevel: zapcore.CapitalColorLevelEncoder,
|
|||
EncodeTime: logEncodeTime, |
|||
EncodeDuration: zapcore.StringDurationEncoder, |
|||
//EncodeCaller: logEncodeCaller,
|
|||
EncodeCaller: zapcore.ShortCallerEncoder, |
|||
|
|||
//EncodeName: logEncodeName,
|
|||
ConsoleSeparator: " ", |
|||
} |
|||
|
|||
//var zc = zap.Config{
|
|||
// Level: zap.NewAtomicLevelAt(zapcore.DebugLevel),
|
|||
// Development: false,
|
|||
// DisableCaller: false,
|
|||
// DisableStacktrace: false,
|
|||
// Sampling: nil,
|
|||
// Encoding: "json",
|
|||
// EncoderConfig: config,
|
|||
// OutputPaths: []string{"stdout"},
|
|||
// ErrorOutputPaths: []string{"stderr"},
|
|||
// InitialFields: map[string]interface{}{"app": "zapdex"},
|
|||
//}
|
|||
|
|||
newCore := zapcore.NewCore(zapcore.NewConsoleEncoder(config), zapcore.Lock(os.Stderr), zapcore.DebugLevel) |
|||
//newCore := zapcore.NewCore(zapcore.NewJSONEncoder(config), zapcore.Lock(os.Stderr), zapcore.DebugLevel)
|
|||
logger := zap.New(newCore, zap.AddCaller()) |
|||
//logger := zap.New(newCore)
|
|||
//logger, _ := zc.Build()
|
|||
//logger.Named("123")
|
|||
//fmt.Println(logger.Name())
|
|||
|
|||
zap.ReplaceGlobals(logger) |
|||
Logger = logger.Sugar() |
|||
} |
|||
|
|||
func logEncodeLevel(level zapcore.Level, enc zapcore.PrimitiveArrayEncoder) { |
|||
enc.AppendString(func(level zapcore.Level) string { |
|||
levelStr := level.CapitalString() |
|||
// TODO: using shell codes map
|
|||
switch level { |
|||
case zapcore.DebugLevel: |
|||
return fmt.Sprintf("\x1b[39m[%s]\x1b[0m", levelStr) |
|||
case zapcore.InfoLevel: |
|||
return fmt.Sprintf("\x1b[32m[%s]\x1b[0m", levelStr) |
|||
case zapcore.WarnLevel: |
|||
return fmt.Sprintf("\x1b[33m[%s]\x1b[0m", levelStr) |
|||
case zapcore.ErrorLevel: |
|||
return fmt.Sprintf("\x1b[31m[%s]\x1b[0m", levelStr) |
|||
case zapcore.PanicLevel: |
|||
return fmt.Sprintf("\x1b[95m[%s]\x1b[0m", levelStr) |
|||
default: |
|||
return fmt.Sprintf("[%s]", levelStr) |
|||
} |
|||
}(level)) |
|||
} |
|||
|
|||
func logEncodeTime(t time.Time, enc zapcore.PrimitiveArrayEncoder) { |
|||
// TODO: using `2006-01-02 15:04:05.xxx` format
|
|||
enc.AppendString(fmt.Sprintf( |
|||
"\x1b[36m%s\x1b[0m \x1b[90m%s\x1b[0m", |
|||
"[XProxy]", t.Format("2006-01-02 15:04:05"), |
|||
)) |
|||
} |
|||
|
|||
func logEncodeCaller(caller zapcore.EntryCaller, enc zapcore.PrimitiveArrayEncoder) { |
|||
enc.AppendString("{" + caller.TrimmedPath() + "}") |
|||
} |
Loading…
Reference in new issue