mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-05-01 01:44:15 +00:00
v1.0.0
This commit is contained in:
parent
47d23e9972
commit
c7f7c08ead
711 changed files with 82154 additions and 2 deletions
53
app/log/log_creator.go
Normal file
53
app/log/log_creator.go
Normal file
|
@ -0,0 +1,53 @@
|
|||
// +build !confonly
|
||||
|
||||
package log
|
||||
|
||||
import (
|
||||
"github.com/xtls/xray-core/v1/common"
|
||||
"github.com/xtls/xray-core/v1/common/log"
|
||||
)
|
||||
|
||||
type HandlerCreatorOptions struct {
|
||||
Path string
|
||||
}
|
||||
|
||||
type HandlerCreator func(LogType, HandlerCreatorOptions) (log.Handler, error)
|
||||
|
||||
var (
|
||||
handlerCreatorMap = make(map[LogType]HandlerCreator)
|
||||
)
|
||||
|
||||
func RegisterHandlerCreator(logType LogType, f HandlerCreator) error {
|
||||
if f == nil {
|
||||
return newError("nil HandlerCreator")
|
||||
}
|
||||
|
||||
handlerCreatorMap[logType] = f
|
||||
return nil
|
||||
}
|
||||
|
||||
func createHandler(logType LogType, options HandlerCreatorOptions) (log.Handler, error) {
|
||||
creator, found := handlerCreatorMap[logType]
|
||||
if !found {
|
||||
return nil, newError("unable to create log handler for ", logType)
|
||||
}
|
||||
return creator(logType, options)
|
||||
}
|
||||
|
||||
func init() {
|
||||
common.Must(RegisterHandlerCreator(LogType_Console, func(lt LogType, options HandlerCreatorOptions) (log.Handler, error) {
|
||||
return log.NewLogger(log.CreateStdoutLogWriter()), nil
|
||||
}))
|
||||
|
||||
common.Must(RegisterHandlerCreator(LogType_File, func(lt LogType, options HandlerCreatorOptions) (log.Handler, error) {
|
||||
creator, err := log.CreateFileLogWriter(options.Path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return log.NewLogger(creator), nil
|
||||
}))
|
||||
|
||||
common.Must(RegisterHandlerCreator(LogType_None, func(lt LogType, options HandlerCreatorOptions) (log.Handler, error) {
|
||||
return nil, nil
|
||||
}))
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue