Refine log settings

This commit is contained in:
v2ray committed 2015-12-05 21:10:14 +01:00
1 parent 32c3565681
commit db7d48e48f
10 files changed
+229 -111

No files matched your search

+3
View File
@@ -2,6 +2,7 @@ package config
import (
routerconfig "github.com/v2ray/v2ray-core/app/router/config"
"github.com/v2ray/v2ray-core/common/log"
v2net "github.com/v2ray/v2ray-core/common/net"
)
@@ -12,6 +13,8 @@ type ConnectionConfig interface {
type LogConfig interface {
AccessLog() string
ErrorLog() string
LogLevel() log.LogLevel
}
type InboundDetourConfig interface {
+28 -2
View File
@@ -1,9 +1,35 @@
package json
import (
"strings"
"github.com/v2ray/v2ray-core/common/log"
)
type LogConfig struct {
AccessLogValue string `json:"access"`
ErrorLogValue string `json:"error"`
LogLevelValue string `json:"loglevel"`
}
func (config *LogConfig) AccessLog() string {
return config.AccessLogValue
func (this *LogConfig) AccessLog() string {
return this.AccessLogValue
}
func (this *LogConfig) ErrorLog() string {
return this.ErrorLogValue
}
func (this *LogConfig) LogLevel() log.LogLevel {
level := strings.ToLower(this.LogLevelValue)
switch level {
case "debug":
return log.DebugLevel
case "info":
return log.InfoLevel
case "error":
return log.ErrorLevel
default:
return log.WarningLevel
}
}
+15 -4
View File
@@ -3,6 +3,7 @@ package mocks
import (
routerconfig "github.com/v2ray/v2ray-core/app/router/config"
routertestingconfig "github.com/v2ray/v2ray-core/app/router/config/testing"
"github.com/v2ray/v2ray-core/common/log"
v2net "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/shell/point/config"
)
@@ -22,6 +23,20 @@ func (config *ConnectionConfig) Settings() interface{} {
type LogConfig struct {
AccessLogValue string
ErrorLogValue string
LogLevelValue log.LogLevel
}
func (config *LogConfig) AccessLog() string {
return config.AccessLogValue
}
func (this *LogConfig) ErrorLog() string {
return this.ErrorLogValue
}
func (this *LogConfig) LogLevel() log.LogLevel {
return this.LogLevelValue
}
type PortRange struct {
@@ -55,10 +70,6 @@ func (this *OutboundDetourConfig) Tag() string {
return this.TagValue
}
func (config *LogConfig) AccessLog() string {
return config.AccessLogValue
}
type Config struct {
PortValue v2net.Port
LogConfigValue *LogConfig
+19
View File
@@ -30,6 +30,25 @@ func NewPoint(pConfig config.PointConfig) (*Point, error) {
var vpoint = new(Point)
vpoint.port = pConfig.Port()
if pConfig.LogConfig() != nil {
logConfig := pConfig.LogConfig()
if len(logConfig.AccessLog()) > 0 {
err := log.InitAccessLogger(logConfig.AccessLog())
if err != nil {
return nil, err
}
}
if len(logConfig.ErrorLog()) > 0 {
err := log.InitErrorLogger(logConfig.ErrorLog())
if err != nil {
return nil, err
}
}
log.SetLogLevel(logConfig.LogLevel())
}
ichFactory := connhandler.GetInboundConnectionHandlerFactory(pConfig.InboundConfig().Protocol())
if ichFactory == nil {
log.Error("Unknown inbound connection handler factory %s", pConfig.InboundConfig().Protocol())