Refactor log

This commit is contained in:
世界 2022-07-12 15:17:29 +08:00
parent b47f3adbb3
commit 4fc763cfa2
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
46 changed files with 760 additions and 457 deletions

View file

@ -7,31 +7,23 @@ import (
"github.com/sagernet/sing-box/option"
"github.com/sagernet/sing/common"
E "github.com/sagernet/sing/common/exceptions"
F "github.com/sagernet/sing/common/format"
)
func New(router adapter.Router, logger log.Logger, index int, options option.Outbound) (adapter.Outbound, error) {
func New(router adapter.Router, logger log.ContextLogger, options option.Outbound) (adapter.Outbound, error) {
if common.IsEmpty(options) {
return nil, E.New("empty outbound config")
}
var tag string
if options.Tag != "" {
tag = options.Tag
} else {
tag = F.ToString(index)
}
outboundLogger := logger.WithPrefix(F.ToString("outbound/", options.Type, "[", tag, "]: "))
switch options.Type {
case C.TypeDirect:
return NewDirect(router, outboundLogger, options.Tag, options.DirectOptions), nil
return NewDirect(router, logger, options.Tag, options.DirectOptions), nil
case C.TypeBlock:
return NewBlock(outboundLogger, options.Tag), nil
return NewBlock(logger, options.Tag), nil
case C.TypeSocks:
return NewSocks(router, outboundLogger, options.Tag, options.SocksOptions)
return NewSocks(router, logger, options.Tag, options.SocksOptions)
case C.TypeHTTP:
return NewHTTP(router, outboundLogger, options.Tag, options.HTTPOptions), nil
return NewHTTP(router, logger, options.Tag, options.HTTPOptions), nil
case C.TypeShadowsocks:
return NewShadowsocks(router, outboundLogger, options.Tag, options.ShadowsocksOptions)
return NewShadowsocks(router, logger, options.Tag, options.ShadowsocksOptions)
default:
return nil, E.New("unknown outbound type: ", options.Type)
}