rework protocol buffer log settings

This commit is contained in:
Shelikhoo 2021-10-02 22:29:37 +01:00
parent 36df3b035c
commit ee185a5824
No known key found for this signature in database
GPG Key ID: AA7BC347968E7DB1
13 changed files with 221 additions and 193 deletions

View File

@ -74,22 +74,82 @@ func (LogType) EnumDescriptor() ([]byte, []int) {
return file_app_log_config_proto_rawDescGZIP(), []int{0}
}
type LogSpecification struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Type LogType `protobuf:"varint,1,opt,name=type,proto3,enum=v2ray.core.app.log.LogType" json:"type,omitempty"`
Level log.Severity `protobuf:"varint,2,opt,name=level,proto3,enum=v2ray.core.common.log.Severity" json:"level,omitempty"`
Path string `protobuf:"bytes,3,opt,name=path,proto3" json:"path,omitempty"`
}
func (x *LogSpecification) Reset() {
*x = LogSpecification{}
if protoimpl.UnsafeEnabled {
mi := &file_app_log_config_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *LogSpecification) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*LogSpecification) ProtoMessage() {}
func (x *LogSpecification) ProtoReflect() protoreflect.Message {
mi := &file_app_log_config_proto_msgTypes[0]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use LogSpecification.ProtoReflect.Descriptor instead.
func (*LogSpecification) Descriptor() ([]byte, []int) {
return file_app_log_config_proto_rawDescGZIP(), []int{0}
}
func (x *LogSpecification) GetType() LogType {
if x != nil {
return x.Type
}
return LogType_None
}
func (x *LogSpecification) GetLevel() log.Severity {
if x != nil {
return x.Level
}
return log.Severity(0)
}
func (x *LogSpecification) GetPath() string {
if x != nil {
return x.Path
}
return ""
}
type Config struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
ErrorLogType LogType `protobuf:"varint,1,opt,name=error_log_type,json=errorLogType,proto3,enum=v2ray.core.app.log.LogType" json:"error_log_type,omitempty"`
ErrorLogLevel log.Severity `protobuf:"varint,2,opt,name=error_log_level,json=errorLogLevel,proto3,enum=v2ray.core.common.log.Severity" json:"error_log_level,omitempty"`
ErrorLogPath string `protobuf:"bytes,3,opt,name=error_log_path,json=errorLogPath,proto3" json:"error_log_path,omitempty"`
AccessLogType LogType `protobuf:"varint,4,opt,name=access_log_type,json=accessLogType,proto3,enum=v2ray.core.app.log.LogType" json:"access_log_type,omitempty"`
AccessLogPath string `protobuf:"bytes,5,opt,name=access_log_path,json=accessLogPath,proto3" json:"access_log_path,omitempty"`
Error *LogSpecification `protobuf:"bytes,6,opt,name=error,proto3" json:"error,omitempty"`
Access *LogSpecification `protobuf:"bytes,7,opt,name=access,proto3" json:"access,omitempty"`
}
func (x *Config) Reset() {
*x = Config{}
if protoimpl.UnsafeEnabled {
mi := &file_app_log_config_proto_msgTypes[0]
mi := &file_app_log_config_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@ -102,7 +162,7 @@ func (x *Config) String() string {
func (*Config) ProtoMessage() {}
func (x *Config) ProtoReflect() protoreflect.Message {
mi := &file_app_log_config_proto_msgTypes[0]
mi := &file_app_log_config_proto_msgTypes[1]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@ -115,42 +175,21 @@ func (x *Config) ProtoReflect() protoreflect.Message {
// Deprecated: Use Config.ProtoReflect.Descriptor instead.
func (*Config) Descriptor() ([]byte, []int) {
return file_app_log_config_proto_rawDescGZIP(), []int{0}
return file_app_log_config_proto_rawDescGZIP(), []int{1}
}
func (x *Config) GetErrorLogType() LogType {
func (x *Config) GetError() *LogSpecification {
if x != nil {
return x.ErrorLogType
return x.Error
}
return LogType_None
return nil
}
func (x *Config) GetErrorLogLevel() log.Severity {
func (x *Config) GetAccess() *LogSpecification {
if x != nil {
return x.ErrorLogLevel
return x.Access
}
return log.Severity(0)
}
func (x *Config) GetErrorLogPath() string {
if x != nil {
return x.ErrorLogPath
}
return ""
}
func (x *Config) GetAccessLogType() LogType {
if x != nil {
return x.AccessLogType
}
return LogType_None
}
func (x *Config) GetAccessLogPath() string {
if x != nil {
return x.AccessLogPath
}
return ""
return nil
}
var File_app_log_config_proto protoreflect.FileDescriptor
@ -162,36 +201,37 @@ var file_app_log_config_proto_rawDesc = []byte{
0x6f, 0x6e, 0x2f, 0x6c, 0x6f, 0x67, 0x2f, 0x6c, 0x6f, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x1a, 0x20, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x65, 0x78,
0x74, 0x2f, 0x65, 0x78, 0x74, 0x65, 0x6e, 0x73, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x22, 0xbf, 0x02, 0x0a, 0x06, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x41, 0x0a,
0x0e, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x5f, 0x6c, 0x6f, 0x67, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18,
0x74, 0x6f, 0x22, 0x8e, 0x01, 0x0a, 0x10, 0x4c, 0x6f, 0x67, 0x53, 0x70, 0x65, 0x63, 0x69, 0x66,
0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x2f, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18,
0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x1b, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f,
0x72, 0x65, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x6c, 0x6f, 0x67, 0x2e, 0x4c, 0x6f, 0x67, 0x54, 0x79,
0x70, 0x65, 0x52, 0x0c, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x4c, 0x6f, 0x67, 0x54, 0x79, 0x70, 0x65,
0x12, 0x47, 0x0a, 0x0f, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x5f, 0x6c, 0x6f, 0x67, 0x5f, 0x6c, 0x65,
0x76, 0x65, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x1f, 0x2e, 0x76, 0x32, 0x72, 0x61,
0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x6c, 0x6f,
0x67, 0x2e, 0x53, 0x65, 0x76, 0x65, 0x72, 0x69, 0x74, 0x79, 0x52, 0x0d, 0x65, 0x72, 0x72, 0x6f,
0x72, 0x4c, 0x6f, 0x67, 0x4c, 0x65, 0x76, 0x65, 0x6c, 0x12, 0x24, 0x0a, 0x0e, 0x65, 0x72, 0x72,
0x6f, 0x72, 0x5f, 0x6c, 0x6f, 0x67, 0x5f, 0x70, 0x61, 0x74, 0x68, 0x18, 0x03, 0x20, 0x01, 0x28,
0x09, 0x52, 0x0c, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x4c, 0x6f, 0x67, 0x50, 0x61, 0x74, 0x68, 0x12,
0x43, 0x0a, 0x0f, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x5f, 0x6c, 0x6f, 0x67, 0x5f, 0x74, 0x79,
0x70, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x1b, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79,
0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x6c, 0x6f, 0x67, 0x2e, 0x4c, 0x6f,
0x67, 0x54, 0x79, 0x70, 0x65, 0x52, 0x0d, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x4c, 0x6f, 0x67,
0x54, 0x79, 0x70, 0x65, 0x12, 0x26, 0x0a, 0x0f, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x5f, 0x6c,
0x6f, 0x67, 0x5f, 0x70, 0x61, 0x74, 0x68, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x61,
0x63, 0x63, 0x65, 0x73, 0x73, 0x4c, 0x6f, 0x67, 0x50, 0x61, 0x74, 0x68, 0x3a, 0x16, 0x82, 0xb5,
0x18, 0x09, 0x0a, 0x07, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x82, 0xb5, 0x18, 0x05, 0x12,
0x03, 0x6c, 0x6f, 0x67, 0x2a, 0x35, 0x0a, 0x07, 0x4c, 0x6f, 0x67, 0x54, 0x79, 0x70, 0x65, 0x12,
0x08, 0x0a, 0x04, 0x4e, 0x6f, 0x6e, 0x65, 0x10, 0x00, 0x12, 0x0b, 0x0a, 0x07, 0x43, 0x6f, 0x6e,
0x73, 0x6f, 0x6c, 0x65, 0x10, 0x01, 0x12, 0x08, 0x0a, 0x04, 0x46, 0x69, 0x6c, 0x65, 0x10, 0x02,
0x12, 0x09, 0x0a, 0x05, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x10, 0x03, 0x42, 0x57, 0x0a, 0x16, 0x63,
0x6f, 0x6d, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x61, 0x70,
0x70, 0x2e, 0x6c, 0x6f, 0x67, 0x50, 0x01, 0x5a, 0x26, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e,
0x63, 0x6f, 0x6d, 0x2f, 0x76, 0x32, 0x66, 0x6c, 0x79, 0x2f, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2d,
0x63, 0x6f, 0x72, 0x65, 0x2f, 0x76, 0x34, 0x2f, 0x61, 0x70, 0x70, 0x2f, 0x6c, 0x6f, 0x67, 0xaa,
0x02, 0x12, 0x56, 0x32, 0x52, 0x61, 0x79, 0x2e, 0x43, 0x6f, 0x72, 0x65, 0x2e, 0x41, 0x70, 0x70,
0x2e, 0x4c, 0x6f, 0x67, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x70, 0x65, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x35, 0x0a, 0x05, 0x6c, 0x65, 0x76, 0x65,
0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x1f, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e,
0x63, 0x6f, 0x72, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x6c, 0x6f, 0x67, 0x2e,
0x53, 0x65, 0x76, 0x65, 0x72, 0x69, 0x74, 0x79, 0x52, 0x05, 0x6c, 0x65, 0x76, 0x65, 0x6c, 0x12,
0x12, 0x0a, 0x04, 0x70, 0x61, 0x74, 0x68, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x70,
0x61, 0x74, 0x68, 0x22, 0xb8, 0x01, 0x0a, 0x06, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x3a,
0x0a, 0x05, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x24, 0x2e,
0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x6c,
0x6f, 0x67, 0x2e, 0x4c, 0x6f, 0x67, 0x53, 0x70, 0x65, 0x63, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74,
0x69, 0x6f, 0x6e, 0x52, 0x05, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x12, 0x3c, 0x0a, 0x06, 0x61, 0x63,
0x63, 0x65, 0x73, 0x73, 0x18, 0x07, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x24, 0x2e, 0x76, 0x32, 0x72,
0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x6c, 0x6f, 0x67, 0x2e,
0x4c, 0x6f, 0x67, 0x53, 0x70, 0x65, 0x63, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e,
0x52, 0x06, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x3a, 0x16, 0x82, 0xb5, 0x18, 0x09, 0x0a, 0x07,
0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x82, 0xb5, 0x18, 0x05, 0x12, 0x03, 0x6c, 0x6f, 0x67,
0x4a, 0x04, 0x08, 0x01, 0x10, 0x02, 0x4a, 0x04, 0x08, 0x02, 0x10, 0x03, 0x4a, 0x04, 0x08, 0x03,
0x10, 0x04, 0x4a, 0x04, 0x08, 0x04, 0x10, 0x05, 0x4a, 0x04, 0x08, 0x05, 0x10, 0x06, 0x2a, 0x35,
0x0a, 0x07, 0x4c, 0x6f, 0x67, 0x54, 0x79, 0x70, 0x65, 0x12, 0x08, 0x0a, 0x04, 0x4e, 0x6f, 0x6e,
0x65, 0x10, 0x00, 0x12, 0x0b, 0x0a, 0x07, 0x43, 0x6f, 0x6e, 0x73, 0x6f, 0x6c, 0x65, 0x10, 0x01,
0x12, 0x08, 0x0a, 0x04, 0x46, 0x69, 0x6c, 0x65, 0x10, 0x02, 0x12, 0x09, 0x0a, 0x05, 0x45, 0x76,
0x65, 0x6e, 0x74, 0x10, 0x03, 0x42, 0x57, 0x0a, 0x16, 0x63, 0x6f, 0x6d, 0x2e, 0x76, 0x32, 0x72,
0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x6c, 0x6f, 0x67, 0x50,
0x01, 0x5a, 0x26, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x76, 0x32,
0x66, 0x6c, 0x79, 0x2f, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2d, 0x63, 0x6f, 0x72, 0x65, 0x2f, 0x76,
0x34, 0x2f, 0x61, 0x70, 0x70, 0x2f, 0x6c, 0x6f, 0x67, 0xaa, 0x02, 0x12, 0x56, 0x32, 0x52, 0x61,
0x79, 0x2e, 0x43, 0x6f, 0x72, 0x65, 0x2e, 0x41, 0x70, 0x70, 0x2e, 0x4c, 0x6f, 0x67, 0x62, 0x06,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
@ -207,21 +247,23 @@ func file_app_log_config_proto_rawDescGZIP() []byte {
}
var file_app_log_config_proto_enumTypes = make([]protoimpl.EnumInfo, 1)
var file_app_log_config_proto_msgTypes = make([]protoimpl.MessageInfo, 1)
var file_app_log_config_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
var file_app_log_config_proto_goTypes = []interface{}{
(LogType)(0), // 0: v2ray.core.app.log.LogType
(*Config)(nil), // 1: v2ray.core.app.log.Config
(log.Severity)(0), // 2: v2ray.core.common.log.Severity
(LogType)(0), // 0: v2ray.core.app.log.LogType
(*LogSpecification)(nil), // 1: v2ray.core.app.log.LogSpecification
(*Config)(nil), // 2: v2ray.core.app.log.Config
(log.Severity)(0), // 3: v2ray.core.common.log.Severity
}
var file_app_log_config_proto_depIdxs = []int32{
0, // 0: v2ray.core.app.log.Config.error_log_type:type_name -> v2ray.core.app.log.LogType
2, // 1: v2ray.core.app.log.Config.error_log_level:type_name -> v2ray.core.common.log.Severity
0, // 2: v2ray.core.app.log.Config.access_log_type:type_name -> v2ray.core.app.log.LogType
3, // [3:3] is the sub-list for method output_type
3, // [3:3] is the sub-list for method input_type
3, // [3:3] is the sub-list for extension type_name
3, // [3:3] is the sub-list for extension extendee
0, // [0:3] is the sub-list for field type_name
0, // 0: v2ray.core.app.log.LogSpecification.type:type_name -> v2ray.core.app.log.LogType
3, // 1: v2ray.core.app.log.LogSpecification.level:type_name -> v2ray.core.common.log.Severity
1, // 2: v2ray.core.app.log.Config.error:type_name -> v2ray.core.app.log.LogSpecification
1, // 3: v2ray.core.app.log.Config.access:type_name -> v2ray.core.app.log.LogSpecification
4, // [4:4] is the sub-list for method output_type
4, // [4:4] is the sub-list for method input_type
4, // [4:4] is the sub-list for extension type_name
4, // [4:4] is the sub-list for extension extendee
0, // [0:4] is the sub-list for field type_name
}
func init() { file_app_log_config_proto_init() }
@ -231,6 +273,18 @@ func file_app_log_config_proto_init() {
}
if !protoimpl.UnsafeEnabled {
file_app_log_config_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*LogSpecification); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_app_log_config_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*Config); i {
case 0:
return &v.state
@ -249,7 +303,7 @@ func file_app_log_config_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_app_log_config_proto_rawDesc,
NumEnums: 1,
NumMessages: 1,
NumMessages: 2,
NumExtensions: 0,
NumServices: 0,
},

View File

@ -16,14 +16,18 @@ enum LogType {
Event = 3;
}
message LogSpecification {
LogType type = 1;
v2ray.core.common.log.Severity level = 2;
string path = 3;
}
message Config {
option (v2ray.core.common.protoext.message_opt).type = "service";
option (v2ray.core.common.protoext.message_opt).short_name = "log";
LogType error_log_type = 1;
v2ray.core.common.log.Severity error_log_level = 2;
string error_log_path = 3;
reserved 1,2,3,4,5;
LogType access_log_type = 4;
string access_log_path = 5;
LogSpecification error = 6;
LogSpecification access = 7;
}

View File

@ -23,6 +23,15 @@ type Instance struct {
// New creates a new log.Instance based on the given config.
func New(ctx context.Context, config *Config) (*Instance, error) {
if config.Error == nil {
config.Error = &LogSpecification{Type: LogType_Console, Level: log.Severity_Warning}
}
if config.Access == nil {
config.Access = &LogSpecification{Type: LogType_None}
}
g := &Instance{
config: config,
active: false,
@ -40,8 +49,8 @@ func New(ctx context.Context, config *Config) (*Instance, error) {
}
func (g *Instance) initAccessLogger() error {
handler, err := createHandler(g.config.AccessLogType, HandlerCreatorOptions{
Path: g.config.AccessLogPath,
handler, err := createHandler(g.config.Access.Type, HandlerCreatorOptions{
Path: g.config.Access.Path,
})
if err != nil {
return err
@ -51,8 +60,8 @@ func (g *Instance) initAccessLogger() error {
}
func (g *Instance) initErrorLogger() error {
handler, err := createHandler(g.config.ErrorLogType, HandlerCreatorOptions{
Path: g.config.ErrorLogPath,
handler, err := createHandler(g.config.Error.Type, HandlerCreatorOptions{
Path: g.config.Error.Path,
})
if err != nil {
return err
@ -127,7 +136,7 @@ func (g *Instance) Handle(msg log.Message) {
g.accessLogger.Handle(msg)
}
case *log.GeneralMessage:
if g.errorLogger != nil && msg.Severity <= g.config.ErrorLogLevel {
if g.errorLogger != nil && msg.Severity <= g.config.Error.Level {
g.errorLogger.Handle(msg)
}
default:

View File

@ -28,9 +28,8 @@ func TestCustomLogHandler(t *testing.T) {
})
logger, err := log.New(context.Background(), &log.Config{
ErrorLogLevel: clog.Severity_Debug,
ErrorLogType: log.LogType_Console,
AccessLogType: log.LogType_None,
Error: &log.LogSpecification{Type: log.LogType_Console, Level: clog.Severity_Debug},
Access: &log.LogSpecification{Type: log.LogType_None},
})
common.Must(err)

View File

@ -9,9 +9,8 @@ import (
func DefaultLogConfig() *log.Config {
return &log.Config{
AccessLogType: log.LogType_None,
ErrorLogType: log.LogType_Console,
ErrorLogLevel: clog.Severity_Warning,
Access: &log.LogSpecification{Type: log.LogType_None},
Error: &log.LogSpecification{Type: log.LogType_Console, Level: clog.Severity_Warning},
}
}
@ -26,36 +25,36 @@ func (v *LogConfig) Build() *log.Config {
return nil
}
config := &log.Config{
ErrorLogType: log.LogType_Console,
AccessLogType: log.LogType_Console,
Access: &log.LogSpecification{Type: log.LogType_Console},
Error: &log.LogSpecification{Type: log.LogType_Console},
}
if v.AccessLog == "none" {
config.AccessLogType = log.LogType_None
config.Access.Type = log.LogType_None
} else if len(v.AccessLog) > 0 {
config.AccessLogPath = v.AccessLog
config.AccessLogType = log.LogType_File
config.Access.Path = v.AccessLog
config.Access.Type = log.LogType_File
}
if v.ErrorLog == "none" {
config.ErrorLogType = log.LogType_None
config.Error.Type = log.LogType_None
} else if len(v.ErrorLog) > 0 {
config.ErrorLogPath = v.ErrorLog
config.ErrorLogType = log.LogType_File
config.Error.Path = v.ErrorLog
config.Error.Type = log.LogType_File
}
level := strings.ToLower(v.LogLevel)
switch level {
case "debug":
config.ErrorLogLevel = clog.Severity_Debug
config.Error.Level = clog.Severity_Debug
case "info":
config.ErrorLogLevel = clog.Severity_Info
config.Error.Level = clog.Severity_Info
case "error":
config.ErrorLogLevel = clog.Severity_Error
config.Error.Level = clog.Severity_Error
case "none":
config.ErrorLogType = log.LogType_None
config.AccessLogType = log.LogType_None
config.Error.Type = log.LogType_None
config.Error.Type = log.LogType_None
default:
config.ErrorLogLevel = clog.Severity_Warning
config.Error.Level = clog.Severity_Warning
}
return config
}

View File

@ -149,11 +149,15 @@ func TestV2RayConfig(t *testing.T) {
Output: &core.Config{
App: []*anypb.Any{
serial.ToTypedMessage(&log.Config{
ErrorLogType: log.LogType_File,
ErrorLogPath: "/var/log/v2ray/error.log",
ErrorLogLevel: clog.Severity_Error,
AccessLogType: log.LogType_File,
AccessLogPath: "/var/log/v2ray/access.log",
Error: &log.LogSpecification{
Type: log.LogType_File,
Level: clog.Severity_Error,
Path: "/var/log/v2ray/error.log",
},
Access: &log.LogSpecification{
Type: log.LogType_File,
Path: "/var/log/v2ray/access.log",
},
}),
serial.ToTypedMessage(&dispatcher.Config{}),
serial.ToTypedMessage(&proxyman.InboundConfig{}),

View File

@ -38,8 +38,7 @@ func TestDokodemoTCP(t *testing.T) {
serverConfig := &core.Config{
App: []*anypb.Any{
serial.ToTypedMessage(&log.Config{
ErrorLogLevel: clog.Severity_Debug,
ErrorLogType: log.LogType_Console,
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
}),
},
Inbound: []*core.InboundHandlerConfig{
@ -71,8 +70,7 @@ func TestDokodemoTCP(t *testing.T) {
clientConfig := &core.Config{
App: []*anypb.Any{
serial.ToTypedMessage(&log.Config{
ErrorLogLevel: clog.Severity_Debug,
ErrorLogType: log.LogType_Console,
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
}),
},
Inbound: []*core.InboundHandlerConfig{

View File

@ -617,8 +617,7 @@ func TestDomainSniffing(t *testing.T) {
},
}),
serial.ToTypedMessage(&log.Config{
ErrorLogLevel: clog.Severity_Debug,
ErrorLogType: log.LogType_Console,
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
}),
},
}
@ -661,8 +660,7 @@ func TestDialV2Ray(t *testing.T) {
serverConfig := &core.Config{
App: []*anypb.Any{
serial.ToTypedMessage(&log.Config{
ErrorLogLevel: clog.Severity_Debug,
ErrorLogType: log.LogType_Console,
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
}),
},
Inbound: []*core.InboundHandlerConfig{

View File

@ -210,8 +210,7 @@ func TestZeroBuffer(t *testing.T) {
clientConfig := &core.Config{
App: []*anypb.Any{
serial.ToTypedMessage(&log.Config{
ErrorLogLevel: clog.Severity_Debug,
ErrorLogType: log.LogType_Console,
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
}),
},
Inbound: []*core.InboundHandlerConfig{

View File

@ -216,8 +216,7 @@ func TestReverseProxyLongRunning(t *testing.T) {
serverConfig := &core.Config{
App: []*anypb.Any{
serial.ToTypedMessage(&log.Config{
ErrorLogLevel: clog.Severity_Warning,
ErrorLogType: log.LogType_Console,
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
}),
serial.ToTypedMessage(&policy.Config{
Level: map[uint32]*policy.Policy{
@ -299,8 +298,7 @@ func TestReverseProxyLongRunning(t *testing.T) {
clientConfig := &core.Config{
App: []*anypb.Any{
serial.ToTypedMessage(&log.Config{
ErrorLogLevel: clog.Severity_Warning,
ErrorLogType: log.LogType_Console,
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
}),
serial.ToTypedMessage(&policy.Config{
Level: map[uint32]*policy.Policy{

View File

@ -123,8 +123,7 @@ func TestShadowsocksAES256GCMTCP(t *testing.T) {
serverConfig := &core.Config{
App: []*anypb.Any{
serial.ToTypedMessage(&log.Config{
ErrorLogLevel: clog.Severity_Debug,
ErrorLogType: log.LogType_Console,
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
}),
},
Inbound: []*core.InboundHandlerConfig{
@ -153,8 +152,7 @@ func TestShadowsocksAES256GCMTCP(t *testing.T) {
clientConfig := &core.Config{
App: []*anypb.Any{
serial.ToTypedMessage(&log.Config{
ErrorLogLevel: clog.Severity_Debug,
ErrorLogType: log.LogType_Console,
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
}),
},
Inbound: []*core.InboundHandlerConfig{
@ -220,8 +218,7 @@ func TestShadowsocksAES128GCMUDP(t *testing.T) {
serverConfig := &core.Config{
App: []*anypb.Any{
serial.ToTypedMessage(&log.Config{
ErrorLogLevel: clog.Severity_Debug,
ErrorLogType: log.LogType_Console,
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
}),
},
Inbound: []*core.InboundHandlerConfig{
@ -250,8 +247,7 @@ func TestShadowsocksAES128GCMUDP(t *testing.T) {
clientConfig := &core.Config{
App: []*anypb.Any{
serial.ToTypedMessage(&log.Config{
ErrorLogLevel: clog.Severity_Debug,
ErrorLogType: log.LogType_Console,
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
}),
},
Inbound: []*core.InboundHandlerConfig{
@ -316,8 +312,7 @@ func TestShadowsocksAES128GCMUDPMux(t *testing.T) {
serverConfig := &core.Config{
App: []*anypb.Any{
serial.ToTypedMessage(&log.Config{
ErrorLogLevel: clog.Severity_Debug,
ErrorLogType: log.LogType_Console,
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
}),
},
Inbound: []*core.InboundHandlerConfig{
@ -346,8 +341,7 @@ func TestShadowsocksAES128GCMUDPMux(t *testing.T) {
clientConfig := &core.Config{
App: []*anypb.Any{
serial.ToTypedMessage(&log.Config{
ErrorLogLevel: clog.Severity_Debug,
ErrorLogType: log.LogType_Console,
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
}),
},
Inbound: []*core.InboundHandlerConfig{

View File

@ -263,8 +263,7 @@ func TestVMessQuic(t *testing.T) {
serverConfig := &core.Config{
App: []*anypb.Any{
serial.ToTypedMessage(&log.Config{
ErrorLogLevel: clog.Severity_Debug,
ErrorLogType: log.LogType_Console,
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
}),
},
Inbound: []*core.InboundHandlerConfig{
@ -310,8 +309,7 @@ func TestVMessQuic(t *testing.T) {
clientConfig := &core.Config{
App: []*anypb.Any{
serial.ToTypedMessage(&log.Config{
ErrorLogLevel: clog.Severity_Debug,
ErrorLogType: log.LogType_Console,
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
}),
},
Inbound: []*core.InboundHandlerConfig{

View File

@ -45,8 +45,7 @@ func TestVMessDynamicPort(t *testing.T) {
serverConfig := &core.Config{
App: []*anypb.Any{
serial.ToTypedMessage(&log.Config{
ErrorLogLevel: clog.Severity_Debug,
ErrorLogType: log.LogType_Console,
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
}),
},
Inbound: []*core.InboundHandlerConfig{
@ -125,8 +124,7 @@ func TestVMessDynamicPort(t *testing.T) {
clientConfig := &core.Config{
App: []*anypb.Any{
serial.ToTypedMessage(&log.Config{
ErrorLogLevel: clog.Severity_Debug,
ErrorLogType: log.LogType_Console,
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
}),
},
Inbound: []*core.InboundHandlerConfig{
@ -204,8 +202,7 @@ func TestVMessGCM(t *testing.T) {
serverConfig := &core.Config{
App: []*anypb.Any{
serial.ToTypedMessage(&log.Config{
ErrorLogLevel: clog.Severity_Debug,
ErrorLogType: log.LogType_Console,
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
}),
},
Inbound: []*core.InboundHandlerConfig{
@ -237,8 +234,7 @@ func TestVMessGCM(t *testing.T) {
clientConfig := &core.Config{
App: []*anypb.Any{
serial.ToTypedMessage(&log.Config{
ErrorLogLevel: clog.Severity_Debug,
ErrorLogType: log.LogType_Console,
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
}),
},
Inbound: []*core.InboundHandlerConfig{
@ -310,8 +306,7 @@ func TestVMessGCMReadv(t *testing.T) {
serverConfig := &core.Config{
App: []*anypb.Any{
serial.ToTypedMessage(&log.Config{
ErrorLogLevel: clog.Severity_Debug,
ErrorLogType: log.LogType_Console,
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
}),
},
Inbound: []*core.InboundHandlerConfig{
@ -343,8 +338,7 @@ func TestVMessGCMReadv(t *testing.T) {
clientConfig := &core.Config{
App: []*anypb.Any{
serial.ToTypedMessage(&log.Config{
ErrorLogLevel: clog.Severity_Debug,
ErrorLogType: log.LogType_Console,
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
}),
},
Inbound: []*core.InboundHandlerConfig{
@ -419,8 +413,7 @@ func TestVMessGCMUDP(t *testing.T) {
serverConfig := &core.Config{
App: []*anypb.Any{
serial.ToTypedMessage(&log.Config{
ErrorLogLevel: clog.Severity_Debug,
ErrorLogType: log.LogType_Console,
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
}),
},
Inbound: []*core.InboundHandlerConfig{
@ -452,8 +445,7 @@ func TestVMessGCMUDP(t *testing.T) {
clientConfig := &core.Config{
App: []*anypb.Any{
serial.ToTypedMessage(&log.Config{
ErrorLogLevel: clog.Severity_Debug,
ErrorLogType: log.LogType_Console,
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
}),
},
Inbound: []*core.InboundHandlerConfig{
@ -522,8 +514,7 @@ func TestVMessChacha20(t *testing.T) {
serverConfig := &core.Config{
App: []*anypb.Any{
serial.ToTypedMessage(&log.Config{
ErrorLogLevel: clog.Severity_Debug,
ErrorLogType: log.LogType_Console,
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
}),
},
Inbound: []*core.InboundHandlerConfig{
@ -555,8 +546,7 @@ func TestVMessChacha20(t *testing.T) {
clientConfig := &core.Config{
App: []*anypb.Any{
serial.ToTypedMessage(&log.Config{
ErrorLogLevel: clog.Severity_Debug,
ErrorLogType: log.LogType_Console,
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
}),
},
Inbound: []*core.InboundHandlerConfig{
@ -626,8 +616,7 @@ func TestVMessNone(t *testing.T) {
serverConfig := &core.Config{
App: []*anypb.Any{
serial.ToTypedMessage(&log.Config{
ErrorLogLevel: clog.Severity_Debug,
ErrorLogType: log.LogType_Console,
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
}),
},
Inbound: []*core.InboundHandlerConfig{
@ -659,8 +648,7 @@ func TestVMessNone(t *testing.T) {
clientConfig := &core.Config{
App: []*anypb.Any{
serial.ToTypedMessage(&log.Config{
ErrorLogLevel: clog.Severity_Debug,
ErrorLogType: log.LogType_Console,
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
}),
},
Inbound: []*core.InboundHandlerConfig{
@ -729,8 +717,7 @@ func TestVMessKCP(t *testing.T) {
serverConfig := &core.Config{
App: []*any.Any{
serial.ToTypedMessage(&log.Config{
ErrorLogLevel: clog.Severity_Debug,
ErrorLogType: log.LogType_Console,
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
}),
},
Inbound: []*core.InboundHandlerConfig{
@ -765,8 +752,7 @@ func TestVMessKCP(t *testing.T) {
clientConfig := &core.Config{
App: []*anypb.Any{
serial.ToTypedMessage(&log.Config{
ErrorLogLevel: clog.Severity_Debug,
ErrorLogType: log.LogType_Console,
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
}),
},
Inbound: []*core.InboundHandlerConfig{
@ -840,8 +826,7 @@ func TestVMessKCPLarge(t *testing.T) {
serverConfig := &core.Config{
App: []*anypb.Any{
serial.ToTypedMessage(&log.Config{
ErrorLogLevel: clog.Severity_Debug,
ErrorLogType: log.LogType_Console,
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
}),
},
Inbound: []*core.InboundHandlerConfig{
@ -895,8 +880,7 @@ func TestVMessKCPLarge(t *testing.T) {
clientConfig := &core.Config{
App: []*anypb.Any{
serial.ToTypedMessage(&log.Config{
ErrorLogLevel: clog.Severity_Debug,
ErrorLogType: log.LogType_Console,
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
}),
},
Inbound: []*core.InboundHandlerConfig{
@ -993,8 +977,7 @@ func TestVMessGCMMux(t *testing.T) {
serverConfig := &core.Config{
App: []*anypb.Any{
serial.ToTypedMessage(&log.Config{
ErrorLogLevel: clog.Severity_Debug,
ErrorLogType: log.LogType_Console,
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
}),
},
Inbound: []*core.InboundHandlerConfig{
@ -1026,8 +1009,7 @@ func TestVMessGCMMux(t *testing.T) {
clientConfig := &core.Config{
App: []*anypb.Any{
serial.ToTypedMessage(&log.Config{
ErrorLogLevel: clog.Severity_Debug,
ErrorLogType: log.LogType_Console,
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
}),
},
Inbound: []*core.InboundHandlerConfig{
@ -1112,8 +1094,7 @@ func TestVMessGCMMuxUDP(t *testing.T) {
serverConfig := &core.Config{
App: []*anypb.Any{
serial.ToTypedMessage(&log.Config{
ErrorLogLevel: clog.Severity_Debug,
ErrorLogType: log.LogType_Console,
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
}),
},
Inbound: []*core.InboundHandlerConfig{
@ -1146,8 +1127,7 @@ func TestVMessGCMMuxUDP(t *testing.T) {
clientConfig := &core.Config{
App: []*anypb.Any{
serial.ToTypedMessage(&log.Config{
ErrorLogLevel: clog.Severity_Debug,
ErrorLogType: log.LogType_Console,
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
}),
},
Inbound: []*core.InboundHandlerConfig{
@ -1243,8 +1223,7 @@ func TestVMessZero(t *testing.T) {
serverConfig := &core.Config{
App: []*anypb.Any{
serial.ToTypedMessage(&log.Config{
ErrorLogLevel: clog.Severity_Debug,
ErrorLogType: log.LogType_Console,
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
}),
},
Inbound: []*core.InboundHandlerConfig{
@ -1276,8 +1255,7 @@ func TestVMessZero(t *testing.T) {
clientConfig := &core.Config{
App: []*anypb.Any{
serial.ToTypedMessage(&log.Config{
ErrorLogLevel: clog.Severity_Debug,
ErrorLogType: log.LogType_Console,
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
}),
},
Inbound: []*core.InboundHandlerConfig{
@ -1346,8 +1324,7 @@ func TestVMessGCMLengthAuth(t *testing.T) {
serverConfig := &core.Config{
App: []*anypb.Any{
serial.ToTypedMessage(&log.Config{
ErrorLogLevel: clog.Severity_Debug,
ErrorLogType: log.LogType_Console,
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
}),
},
Inbound: []*core.InboundHandlerConfig{
@ -1379,8 +1356,7 @@ func TestVMessGCMLengthAuth(t *testing.T) {
clientConfig := &core.Config{
App: []*anypb.Any{
serial.ToTypedMessage(&log.Config{
ErrorLogLevel: clog.Severity_Debug,
ErrorLogType: log.LogType_Console,
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
}),
},
Inbound: []*core.InboundHandlerConfig{
@ -1453,8 +1429,7 @@ func TestVMessGCMLengthAuthPlusNoTerminationSignal(t *testing.T) {
serverConfig := &core.Config{
App: []*anypb.Any{
serial.ToTypedMessage(&log.Config{
ErrorLogLevel: clog.Severity_Debug,
ErrorLogType: log.LogType_Console,
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
}),
},
Inbound: []*core.InboundHandlerConfig{
@ -1487,8 +1462,7 @@ func TestVMessGCMLengthAuthPlusNoTerminationSignal(t *testing.T) {
clientConfig := &core.Config{
App: []*anypb.Any{
serial.ToTypedMessage(&log.Config{
ErrorLogLevel: clog.Severity_Debug,
ErrorLogType: log.LogType_Console,
Error: &log.LogSpecification{Level: clog.Severity_Debug, Type: log.LogType_Console},
}),
},
Inbound: []*core.InboundHandlerConfig{