node: avoid clobbering terminal with binary data
commit-id:222d1f31
This commit is contained in:
parent
7a9a5e6487
commit
b8c30314b5
|
@ -0,0 +1,28 @@
|
||||||
|
package guardiand
|
||||||
|
|
||||||
|
import (
|
||||||
|
"go.uber.org/zap/buffer"
|
||||||
|
"go.uber.org/zap/zapcore"
|
||||||
|
"unicode"
|
||||||
|
)
|
||||||
|
|
||||||
|
type consoleEncoder struct {
|
||||||
|
zapcore.Encoder
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e consoleEncoder) EncodeEntry(entry zapcore.Entry, fields []zapcore.Field) (*buffer.Buffer, error) {
|
||||||
|
buf, err := e.Encoder.EncodeEntry(entry, fields)
|
||||||
|
if err != nil {
|
||||||
|
buf.Free()
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
b := buf.Bytes()
|
||||||
|
for i := range b {
|
||||||
|
if unicode.IsControl(rune(b[i])) && !unicode.IsSpace(rune(b[i])) {
|
||||||
|
b[i] = '\x1A' // Substitute character
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return buf, nil
|
||||||
|
}
|
|
@ -245,12 +245,11 @@ func runNode(cmd *cobra.Command, args []string) {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg := zap.NewDevelopmentConfig()
|
logger := zap.New(zapcore.NewCore(
|
||||||
cfg.Level = zap.NewAtomicLevelAt(zapcore.Level(lvl))
|
consoleEncoder{zapcore.NewConsoleEncoder(
|
||||||
logger, err := cfg.Build()
|
zap.NewDevelopmentEncoderConfig())},
|
||||||
if err != nil {
|
zapcore.AddSync(zapcore.Lock(os.Stderr)),
|
||||||
panic(err)
|
zap.NewAtomicLevelAt(zapcore.Level(lvl))))
|
||||||
}
|
|
||||||
|
|
||||||
if *unsafeDevMode {
|
if *unsafeDevMode {
|
||||||
// Use the hostname as nodeName. For production, we don't want to do this to
|
// Use the hostname as nodeName. For production, we don't want to do this to
|
||||||
|
|
|
@ -293,7 +293,7 @@ func Run(obsvC chan *gossipv1.SignedObservation, sendC chan []byte, signedInC ch
|
||||||
err = proto.Unmarshal(envelope.Data, &msg)
|
err = proto.Unmarshal(envelope.Data, &msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Info("received invalid message",
|
logger.Info("received invalid message",
|
||||||
zap.String("data", string(envelope.Data)),
|
zap.Binary("data", envelope.Data),
|
||||||
zap.String("from", envelope.GetFrom().String()))
|
zap.String("from", envelope.GetFrom().String()))
|
||||||
p2pMessagesReceived.WithLabelValues("invalid").Inc()
|
p2pMessagesReceived.WithLabelValues("invalid").Inc()
|
||||||
continue
|
continue
|
||||||
|
|
Loading…
Reference in New Issue