Skip to content

Commit 7cc8c85

Browse files
committed
**log:** log.Info("a","b") print "a b" instead of "ab"
1 parent 64d222b commit 7cc8c85

File tree

3 files changed

+26
-25
lines changed

3 files changed

+26
-25
lines changed

Diff for: log/log.go

+12-12
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func RedirectStdLogAt(logger Logger, level zapcore.Level) (func(), error) {
9696
return nil, errors.New("log: only supports redirecting std logs to trpc zap logger")
9797
}
9898

99-
// Trace logs to TRACE log. Arguments are handled in the manner of fmt.Print.
99+
// Trace logs to TRACE log. Arguments are handled in the manner of fmt.Println.
100100
func Trace(args ...interface{}) {
101101
if traceEnabled {
102102
GetDefaultLogger().Trace(args...)
@@ -110,7 +110,7 @@ func Tracef(format string, args ...interface{}) {
110110
}
111111
}
112112

113-
// TraceContext logs to TRACE log. Arguments are handled in the manner of fmt.Print.
113+
// TraceContext logs to TRACE log. Arguments are handled in the manner of fmt.Println.
114114
func TraceContext(ctx context.Context, args ...interface{}) {
115115
if !traceEnabled {
116116
return
@@ -134,7 +134,7 @@ func TraceContextf(ctx context.Context, format string, args ...interface{}) {
134134
GetDefaultLogger().Tracef(format, args...)
135135
}
136136

137-
// Debug logs to DEBUG log. Arguments are handled in the manner of fmt.Print.
137+
// Debug logs to DEBUG log. Arguments are handled in the manner of fmt.Println.
138138
func Debug(args ...interface{}) {
139139
GetDefaultLogger().Debug(args...)
140140
}
@@ -144,7 +144,7 @@ func Debugf(format string, args ...interface{}) {
144144
GetDefaultLogger().Debugf(format, args...)
145145
}
146146

147-
// Info logs to INFO log. Arguments are handled in the manner of fmt.Print.
147+
// Info logs to INFO log. Arguments are handled in the manner of fmt.Println.
148148
func Info(args ...interface{}) {
149149
GetDefaultLogger().Info(args...)
150150
}
@@ -154,7 +154,7 @@ func Infof(format string, args ...interface{}) {
154154
GetDefaultLogger().Infof(format, args...)
155155
}
156156

157-
// Warn logs to WARNING log. Arguments are handled in the manner of fmt.Print.
157+
// Warn logs to WARNING log. Arguments are handled in the manner of fmt.Println.
158158
func Warn(args ...interface{}) {
159159
GetDefaultLogger().Warn(args...)
160160
}
@@ -164,7 +164,7 @@ func Warnf(format string, args ...interface{}) {
164164
GetDefaultLogger().Warnf(format, args...)
165165
}
166166

167-
// Error logs to ERROR log. Arguments are handled in the manner of fmt.Print.
167+
// Error logs to ERROR log. Arguments are handled in the manner of fmt.Println.
168168
func Error(args ...interface{}) {
169169
GetDefaultLogger().Error(args...)
170170
}
@@ -174,7 +174,7 @@ func Errorf(format string, args ...interface{}) {
174174
GetDefaultLogger().Errorf(format, args...)
175175
}
176176

177-
// Fatal logs to ERROR log. Arguments are handled in the manner of fmt.Print.
177+
// Fatal logs to ERROR log. Arguments are handled in the manner of fmt.Println.
178178
// All Fatal logs will exit by calling os.Exit(1).
179179
// Implementations may also call os.Exit() with a non-zero exit code.
180180
func Fatal(args ...interface{}) {
@@ -211,7 +211,7 @@ func WithContextFields(ctx context.Context, fields ...string) context.Context {
211211
return ctx
212212
}
213213

214-
// DebugContext logs to DEBUG log. Arguments are handled in the manner of fmt.Print.
214+
// DebugContext logs to DEBUG log. Arguments are handled in the manner of fmt.Println.
215215
func DebugContext(ctx context.Context, args ...interface{}) {
216216
if l, ok := codec.Message(ctx).Logger().(Logger); ok {
217217
l.Debug(args...)
@@ -229,7 +229,7 @@ func DebugContextf(ctx context.Context, format string, args ...interface{}) {
229229
GetDefaultLogger().Debugf(format, args...)
230230
}
231231

232-
// InfoContext logs to INFO log. Arguments are handled in the manner of fmt.Print.
232+
// InfoContext logs to INFO log. Arguments are handled in the manner of fmt.Println.
233233
func InfoContext(ctx context.Context, args ...interface{}) {
234234
if l, ok := codec.Message(ctx).Logger().(Logger); ok {
235235
l.Info(args...)
@@ -247,7 +247,7 @@ func InfoContextf(ctx context.Context, format string, args ...interface{}) {
247247
GetDefaultLogger().Infof(format, args...)
248248
}
249249

250-
// WarnContext logs to WARNING log. Arguments are handled in the manner of fmt.Print.
250+
// WarnContext logs to WARNING log. Arguments are handled in the manner of fmt.Println.
251251
func WarnContext(ctx context.Context, args ...interface{}) {
252252
if l, ok := codec.Message(ctx).Logger().(Logger); ok {
253253
l.Warn(args...)
@@ -266,7 +266,7 @@ func WarnContextf(ctx context.Context, format string, args ...interface{}) {
266266

267267
}
268268

269-
// ErrorContext logs to ERROR log. Arguments are handled in the manner of fmt.Print.
269+
// ErrorContext logs to ERROR log. Arguments are handled in the manner of fmt.Println.
270270
func ErrorContext(ctx context.Context, args ...interface{}) {
271271
if l, ok := codec.Message(ctx).Logger().(Logger); ok {
272272
l.Error(args...)
@@ -284,7 +284,7 @@ func ErrorContextf(ctx context.Context, format string, args ...interface{}) {
284284
GetDefaultLogger().Errorf(format, args...)
285285
}
286286

287-
// FatalContext logs to ERROR log. Arguments are handled in the manner of fmt.Print.
287+
// FatalContext logs to ERROR log. Arguments are handled in the manner of fmt.Println.
288288
// All Fatal logs will exit by calling os.Exit(1).
289289
// Implementations may also call os.Exit() with a non-zero exit code.
290290
func FatalContext(ctx context.Context, args ...interface{}) {

Diff for: log/logger.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -74,27 +74,27 @@ type Field struct {
7474

7575
// Logger is the underlying logging work for tRPC framework.
7676
type Logger interface {
77-
// Trace logs to TRACE log. Arguments are handled in the manner of fmt.Print.
77+
// Trace logs to TRACE log. Arguments are handled in the manner of fmt.Println.
7878
Trace(args ...interface{})
7979
// Tracef logs to TRACE log. Arguments are handled in the manner of fmt.Printf.
8080
Tracef(format string, args ...interface{})
81-
// Debug logs to DEBUG log. Arguments are handled in the manner of fmt.Print.
81+
// Debug logs to DEBUG log. Arguments are handled in the manner of fmt.Println.
8282
Debug(args ...interface{})
8383
// Debugf logs to DEBUG log. Arguments are handled in the manner of fmt.Printf.
8484
Debugf(format string, args ...interface{})
85-
// Info logs to INFO log. Arguments are handled in the manner of fmt.Print.
85+
// Info logs to INFO log. Arguments are handled in the manner of fmt.Println.
8686
Info(args ...interface{})
8787
// Infof logs to INFO log. Arguments are handled in the manner of fmt.Printf.
8888
Infof(format string, args ...interface{})
89-
// Warn logs to WARNING log. Arguments are handled in the manner of fmt.Print.
89+
// Warn logs to WARNING log. Arguments are handled in the manner of fmt.Println.
9090
Warn(args ...interface{})
9191
// Warnf logs to WARNING log. Arguments are handled in the manner of fmt.Printf.
9292
Warnf(format string, args ...interface{})
93-
// Error logs to ERROR log. Arguments are handled in the manner of fmt.Print.
93+
// Error logs to ERROR log. Arguments are handled in the manner of fmt.Println.
9494
Error(args ...interface{})
9595
// Errorf logs to ERROR log. Arguments are handled in the manner of fmt.Printf.
9696
Errorf(format string, args ...interface{})
97-
// Fatal logs to ERROR log. Arguments are handled in the manner of fmt.Print.
97+
// Fatal logs to ERROR log. Arguments are handled in the manner of fmt.Println.
9898
// All Fatal logs will exit by calling os.Exit(1).
9999
// Implementations may also call os.Exit() with a non-zero exit code.
100100
Fatal(args ...interface{})

Diff for: log/zaplogger.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,8 @@ func (l *zapLog) With(fields ...Field) Logger {
282282
}
283283

284284
func getLogMsg(args ...interface{}) string {
285-
msg := fmt.Sprint(args...)
285+
msg := fmt.Sprintln(args...)
286+
msg = msg[:len(msg)-1]
286287
report.LogWriteSize.IncrBy(float64(len(msg)))
287288
return msg
288289
}
@@ -293,7 +294,7 @@ func getLogMsgf(format string, args ...interface{}) string {
293294
return msg
294295
}
295296

296-
// Trace logs to TRACE log. Arguments are handled in the manner of fmt.Print.
297+
// Trace logs to TRACE log. Arguments are handled in the manner of fmt.Println.
297298
func (l *zapLog) Trace(args ...interface{}) {
298299
if l.logger.Core().Enabled(zapcore.DebugLevel) {
299300
l.logger.Debug(getLogMsg(args...))
@@ -307,7 +308,7 @@ func (l *zapLog) Tracef(format string, args ...interface{}) {
307308
}
308309
}
309310

310-
// Debug logs to DEBUG log. Arguments are handled in the manner of fmt.Print.
311+
// Debug logs to DEBUG log. Arguments are handled in the manner of fmt.Println.
311312
func (l *zapLog) Debug(args ...interface{}) {
312313
if l.logger.Core().Enabled(zapcore.DebugLevel) {
313314
l.logger.Debug(getLogMsg(args...))
@@ -321,7 +322,7 @@ func (l *zapLog) Debugf(format string, args ...interface{}) {
321322
}
322323
}
323324

324-
// Info logs to INFO log. Arguments are handled in the manner of fmt.Print.
325+
// Info logs to INFO log. Arguments are handled in the manner of fmt.Println.
325326
func (l *zapLog) Info(args ...interface{}) {
326327
if l.logger.Core().Enabled(zapcore.InfoLevel) {
327328
l.logger.Info(getLogMsg(args...))
@@ -335,7 +336,7 @@ func (l *zapLog) Infof(format string, args ...interface{}) {
335336
}
336337
}
337338

338-
// Warn logs to WARNING log. Arguments are handled in the manner of fmt.Print.
339+
// Warn logs to WARNING log. Arguments are handled in the manner of fmt.Println.
339340
func (l *zapLog) Warn(args ...interface{}) {
340341
if l.logger.Core().Enabled(zapcore.WarnLevel) {
341342
l.logger.Warn(getLogMsg(args...))
@@ -349,7 +350,7 @@ func (l *zapLog) Warnf(format string, args ...interface{}) {
349350
}
350351
}
351352

352-
// Error logs to ERROR log. Arguments are handled in the manner of fmt.Print.
353+
// Error logs to ERROR log. Arguments are handled in the manner of fmt.Println.
353354
func (l *zapLog) Error(args ...interface{}) {
354355
if l.logger.Core().Enabled(zapcore.ErrorLevel) {
355356
l.logger.Error(getLogMsg(args...))
@@ -363,7 +364,7 @@ func (l *zapLog) Errorf(format string, args ...interface{}) {
363364
}
364365
}
365366

366-
// Fatal logs to FATAL log. Arguments are handled in the manner of fmt.Print.
367+
// Fatal logs to FATAL log. Arguments are handled in the manner of fmt.Println.
367368
func (l *zapLog) Fatal(args ...interface{}) {
368369
if l.logger.Core().Enabled(zapcore.FatalLevel) {
369370
l.logger.Fatal(getLogMsg(args...))

0 commit comments

Comments
 (0)