Skip to content

Commit

Permalink
warn log message unicode encoding is converted to utf8
Browse files Browse the repository at this point in the history
Signed-off-by: zhuhyc <zzhniy.163.niy@163.com>
  • Loading branch information
zhuhyc authored and awzhgw committed Jul 4, 2019
1 parent 8cf3447 commit 1bbdc2b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion util/ump/ump.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ var (
}}
)

func InitUmp(module, dataDir string) (err error) {
func InitUmp(module, dataDir string)(err error) {
runtime.GOMAXPROCS(runtime.NumCPU())
if err := initLogName(module, dataDir); err != nil {
return err
Expand Down
18 changes: 15 additions & 3 deletions util/ump/ump_async_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"net"
"os"
"strings"
"bytes"
)

type FunctionTp struct {
Expand Down Expand Up @@ -73,6 +74,8 @@ type LogWrite struct {
logSufixx string
logFp *os.File
sigCh chan bool
bf *bytes.Buffer
jsonEncoder *json.Encoder
}

func (lw *LogWrite) initLogFp(sufixx string) (err error) {
Expand All @@ -81,6 +84,9 @@ func (lw *LogWrite) initLogFp(sufixx string) (err error) {
lw.sigCh = make(chan bool, 1)
lw.logSufixx = sufixx
lw.logName = fmt.Sprintf("%s%s%s", UmpDataDir, "ump_", lw.logSufixx)
lw.bf = bytes.NewBuffer([]byte{})
lw.jsonEncoder = json.NewEncoder(lw.bf)
lw.jsonEncoder.SetEscapeHTML(false)
if lw.logFp, err = os.OpenFile(lw.logName, LogFileOpt, 0666); err != nil {
return
}
Expand Down Expand Up @@ -131,15 +137,21 @@ func (lw *LogWrite) backGroundWrite(umpType string) {
switch umpType {
case FunctionTpType:
tp := obj.(*FunctionTp)
body, _ = json.Marshal(tp)
lw.jsonEncoder.Encode(tp)
body = append(body, lw.bf.Bytes()...)
lw.bf.Reset()
FunctionTpPool.Put(tp)
case SystemAliveType:
alive := obj.(*SystemAlive)
body, _ = json.Marshal(alive)
lw.jsonEncoder.Encode(alive)
body = append(body, lw.bf.Bytes()...)
lw.bf.Reset()
SystemAlivePool.Put(alive)
case BusinessAlarmType:
alarm := obj.(*BusinessAlarm)
body, _ = json.Marshal(alarm)
lw.jsonEncoder.Encode(alarm)
body = append(body, lw.bf.Bytes()...)
lw.bf.Reset()
AlarmPool.Put(alarm)
}
if lw.backGroundCheckFile() != nil {
Expand Down

0 comments on commit 1bbdc2b

Please sign in to comment.