ceremonyclient/node/consensus/tracing/zap_tracer.go
Cassandra Heart c797d482f9
v2.1.0.5 (#457)
* wip: conversion of hotstuff from flow into Q-oriented model

* bulk of tests

* remaining non-integration tests

* add integration test, adjust log interface, small tweaks

* further adjustments, restore full pacemaker shape

* add component lifecycle management+supervisor

* further refinements

* resolve timeout hanging

* mostly finalized state for consensus

* bulk of engine swap out

* lifecycle-ify most types

* wiring nearly complete, missing needed hooks for proposals

* plugged in, vetting message validation paths

* global consensus, plugged in and verified

* app shard now wired in too

* do not decode empty keys.yml (#456)

* remove obsolete engine.maxFrames config parameter (#454)

* default to Info log level unless debug is enabled (#453)

* respect config's  "logging" section params, remove obsolete single-file logging (#452)

* Trivial code cleanup aiming to reduce Go compiler warnings (#451)

* simplify range traversal

* simplify channel read for single select case

* delete rand.Seed() deprecated in Go 1.20 and no-op as of Go 1.24

* simplify range traversal

* simplify channel read for single select case

* remove redundant type from array

* simplify range traversal

* simplify channel read for single select case

* RC slate

* finalize 2.1.0.5

* Update comments in StrictMonotonicCounter

Fix comment formatting and clarify description.

---------

Co-authored-by: Black Swan <3999712+blacks1ne@users.noreply.github.com>
2025-11-11 05:00:17 -06:00

74 lines
1.8 KiB
Go

package tracing
import (
"slices"
"time"
"go.uber.org/zap"
"source.quilibrium.com/quilibrium/monorepo/consensus"
)
type ZapTracer struct {
logger *zap.Logger
params []consensus.LogParam
}
// Error implements consensus.TraceLogger.
func (z *ZapTracer) Error(
message string,
err error,
params ...consensus.LogParam,
) {
combined := logParamsToZap(z.params)
combined = append(combined, logParamsToZap(params)...)
combined = append(combined, zap.Error(err))
z.logger.WithOptions(zap.AddCallerSkip(1)).Error(message, combined...)
}
// Trace implements consensus.TraceLogger.
func (z *ZapTracer) Trace(message string, params ...consensus.LogParam) {
combined := logParamsToZap(z.params)
combined = append(combined, logParamsToZap(params)...)
z.logger.WithOptions(zap.AddCallerSkip(1)).Info(message, combined...)
}
// With implements consensus.TraceLogger.
func (z *ZapTracer) With(params ...consensus.LogParam) consensus.TraceLogger {
return &ZapTracer{
logger: z.logger,
params: slices.Concat(z.params, params),
}
}
func NewZapTracer(logger *zap.Logger) *ZapTracer {
return &ZapTracer{logger: logger}
}
func logParamsToZap(params []consensus.LogParam) []zap.Field {
fs := []zap.Field{}
for _, p := range params {
fs = append(fs, logParamToZap(p))
}
return fs
}
func logParamToZap(p consensus.LogParam) zap.Field {
switch p.GetKind() {
case "uint64":
return zap.Uint64(p.GetKey(), p.GetValue().(uint64))
case "uint32":
return zap.Uint32(p.GetKey(), p.GetValue().(uint32))
case "int64":
return zap.Int64(p.GetKey(), p.GetValue().(int64))
case "int32":
return zap.Int32(p.GetKey(), p.GetValue().(int32))
case "string":
return zap.String(p.GetKey(), p.GetValue().(string))
case "time":
return zap.Time(p.GetKey(), p.GetValue().(time.Time))
}
return zap.Any(p.GetKey(), p.GetValue())
}
var _ consensus.TraceLogger = (*ZapTracer)(nil)