You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by ti...@apache.org on 2020/01/17 06:46:32 UTC
[servicecomb-service-center] branch master updated: [SCB-1729]
recover logs also output to stderr (#625)
This is an automated email from the ASF dual-hosted git repository.
tianxiaoliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-service-center.git
The following commit(s) were added to refs/heads/master by this push:
new c1b43ad [SCB-1729] recover logs also output to stderr (#625)
c1b43ad is described below
commit c1b43ad0514ac4bdbbe08461ded62caf2a7aeee5
Author: humingcheng <hu...@163.com>
AuthorDate: Fri Jan 17 14:46:23 2020 +0800
[SCB-1729] recover logs also output to stderr (#625)
---
pkg/log/zap.go | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/pkg/log/zap.go b/pkg/log/zap.go
index e5e9fc1..3040c6e 100644
--- a/pkg/log/zap.go
+++ b/pkg/log/zap.go
@@ -19,15 +19,17 @@ package log
import (
"fmt"
- "github.com/apache/servicecomb-service-center/pkg/util"
- "github.com/natefinch/lumberjack"
- "go.uber.org/zap"
- "go.uber.org/zap/zapcore"
"os"
"runtime"
"runtime/debug"
"strings"
"time"
+
+ "github.com/apache/servicecomb-service-center/pkg/util"
+
+ "github.com/natefinch/lumberjack"
+ "go.uber.org/zap"
+ "go.uber.org/zap/zapcore"
)
const (
@@ -201,6 +203,12 @@ func (l *Logger) Recover(r interface{}, callerSkip int) {
Caller: zapcore.NewEntryCaller(runtime.Caller(callerSkip + 1)),
Stack: zap.Stack("stack").String,
}
+ // recover logs also output to stderr
+ fmt.Fprintf(StderrSyncer, "%s\tPANIC\t%s\t%s\n%v\n",
+ e.Time.Format("2006-01-02T15:04:05.000Z0700"),
+ e.Caller.TrimmedPath(),
+ r,
+ e.Stack)
if err := l.zapLogger.Core().With([]zap.Field{zap.Reflect("recover", r)}).Write(e, nil); err != nil {
fmt.Fprintf(StderrSyncer, "%s\tERROR\t%v\n", time.Now().Format("2006-01-02T15:04:05.000Z0700"), err)
fmt.Fprintln(StderrSyncer, util.BytesToStringWithNoCopy(debug.Stack()))