Documentation
¶
Overview ¶
Package compilelogger provides logging helpers for circuit compilation time. It deduplicates log messages within a single compilation run so that repeated gadget instantiations do not flood the output with identical warnings.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LogOnce ¶
LogOnce logs a message with the given level and identifier, but only the first time it is called with that identifier during a compilation run. Subsequent calls with the same identifier will not log anything.
Recommended identifier format is "component/feature" to allow filtering by component and grouping related messages together.
msg can be a format string and args are the corresponding arguments, as in logger.Logger().Msgf(msg, args...).
LogOnce panics if the api does not implement kvstore.Store, which should never happen since the compiler is expected to implement it.
Example ¶
package main
import (
"fmt"
"os"
"github.com/consensys/gnark/frontend"
"github.com/consensys/gnark/frontend/cs/r1cs"
"github.com/consensys/gnark/internal/compilelogger"
"github.com/consensys/gnark/logger"
"github.com/rs/zerolog"
"github.com/consensys/gnark-crypto/ecc"
)
// exampleCircuit emits two log calls with the same key and one with a distinct key.
type exampleCircuit struct{ X frontend.Variable }
func (c *exampleCircuit) Define(api frontend.API) error {
compiler := api.(frontend.Compiler)
compilelogger.LogOnce(compiler, zerolog.WarnLevel, "key-a", "warning A")
compilelogger.LogOnce(compiler, zerolog.WarnLevel, "key-a", "warning A")
compilelogger.LogOnce(compiler, zerolog.WarnLevel, "key-b", "warning B")
api.AssertIsEqual(c.X, c.X)
return nil
}
func main() {
// WarnLevel filters the framework's own info logs so only our messages appear.
logger.Set(zerolog.New(os.Stdout).Level(zerolog.WarnLevel))
defer logger.Disable()
_, err := frontend.Compile(ecc.BN254.ScalarField(), r1cs.NewBuilder, &exampleCircuit{})
if err != nil {
fmt.Println("compile error:", err)
}
}
Output: {"level":"warn","message":"warning A"} {"level":"warn","message":"warning B"}
Types ¶
This section is empty.