mirror of
https://github.com/SagerNet/sing-box.git
synced 2025-04-04 20:37:37 +03:00
Refactor log
This commit is contained in:
parent
b47f3adbb3
commit
4fc763cfa2
46 changed files with 760 additions and 457 deletions
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue