45
func NewLoggerFromConfigString(s string) Logger {
50
methods := strings.Split(s, ",")
51
for _, method := range methods {
52
if err := l.fillMethodLoggerWithConfigString(method); err != nil {
53
grpclogLogger.Warningf("failed to parse binary log config: %v", err)
62
func (l *logger) fillMethodLoggerWithConfigString(config string) error {
65
return errors.New("empty string is not a valid method binary logging config")
70
s, m, suffix, err := parseMethodConfigAndSuffix(config[1:])
72
return fmt.Errorf("invalid config: %q, %v", config, err)
75
return fmt.Errorf("invalid config: %q, %v", config, "* not allowed in blacklist config")
78
return fmt.Errorf("invalid config: %q, %v", config, "header/message limit not allowed in blacklist config")
80
if err := l.setBlacklist(s + "/" + m); err != nil {
81
return fmt.Errorf("invalid config: %v", err)
88
hdr, msg, err := parseHeaderMessageLengthConfig(config[1:])
90
return fmt.Errorf("invalid config: %q, %v", config, err)
92
if err := l.setDefaultMethodLogger(&methodLoggerConfig{hdr: hdr, msg: msg}); err != nil {
93
return fmt.Errorf("invalid config: %v", err)
98
s, m, suffix, err := parseMethodConfigAndSuffix(config)
100
return fmt.Errorf("invalid config: %q, %v", config, err)
102
hdr, msg, err := parseHeaderMessageLengthConfig(suffix)
104
return fmt.Errorf("invalid header/message length config: %q, %v", suffix, err)
107
if err := l.setServiceMethodLogger(s, &methodLoggerConfig{hdr: hdr, msg: msg}); err != nil {
108
return fmt.Errorf("invalid config: %v", err)
111
if err := l.setMethodMethodLogger(s+"/"+m, &methodLoggerConfig{hdr: hdr, msg: msg}); err != nil {
112
return fmt.Errorf("invalid config: %v", err)
125
longMethodConfigRegexpStr = `^([\w./]+)/((?:\w+)|[*])(.+)?$`
128
optionalLengthRegexpStr = `(?::(\d+))?`
129
headerConfigRegexpStr = `^{h` + optionalLengthRegexpStr + `}$`
130
messageConfigRegexpStr = `^{m` + optionalLengthRegexpStr + `}$`
131
headerMessageConfigRegexpStr = `^{h` + optionalLengthRegexpStr + `;m` + optionalLengthRegexpStr + `}$`
135
longMethodConfigRegexp = regexp.MustCompile(longMethodConfigRegexpStr)
136
headerConfigRegexp = regexp.MustCompile(headerConfigRegexpStr)
137
messageConfigRegexp = regexp.MustCompile(messageConfigRegexpStr)
138
headerMessageConfigRegexp = regexp.MustCompile(headerMessageConfigRegexpStr)
142
func parseMethodConfigAndSuffix(c string) (service, method, suffix string, _ error) {
147
match := longMethodConfigRegexp.FindStringSubmatch(c)
149
return "", "", "", fmt.Errorf("%q contains invalid substring", c)
160
func parseHeaderMessageLengthConfig(c string) (hdrLenStr, msgLenStr uint64, err error) {
162
return maxUInt, maxUInt, nil
165
if match := headerConfigRegexp.FindStringSubmatch(c); match != nil {
166
if s := match[1]; s != "" {
167
hdrLenStr, err = strconv.ParseUint(s, 10, 64)
169
return 0, 0, fmt.Errorf("failed to convert %q to uint", s)
171
return hdrLenStr, 0, nil
173
return maxUInt, 0, nil
177
if match := messageConfigRegexp.FindStringSubmatch(c); match != nil {
178
if s := match[1]; s != "" {
179
msgLenStr, err = strconv.ParseUint(s, 10, 64)
181
return 0, 0, fmt.Errorf("failed to convert %q to uint", s)
183
return 0, msgLenStr, nil
185
return 0, maxUInt, nil
189
if match := headerMessageConfigRegexp.FindStringSubmatch(c); match != nil {
193
if s := match[1]; s != "" {
194
hdrLenStr, err = strconv.ParseUint(s, 10, 64)
196
return 0, 0, fmt.Errorf("failed to convert %q to uint", s)
199
if s := match[2]; s != "" {
200
msgLenStr, err = strconv.ParseUint(s, 10, 64)
202
return 0, 0, fmt.Errorf("failed to convert %q to uint", s)
205
return hdrLenStr, msgLenStr, nil
207
return 0, 0, fmt.Errorf("%q contains invalid substring", c)