Changed TODO comments to reflect new ideas

new/better WIP TODOs

wrote a note for fatal logging
This commit is contained in:
miampf 2024-01-08 16:22:36 +01:00
parent 0b0d3f7441
commit d61f616c85
No known key found for this signature in database
GPG key ID: 376EAC0E5307A669
4 changed files with 9 additions and 8 deletions

View file

@ -94,6 +94,9 @@ func (l *grpcLogger) Errorf(format string, args ...interface{}) {
} }
// TODO(miampf): Find a way to log on a fatal level, not an error level? // TODO(miampf): Find a way to log on a fatal level, not an error level?
// A ReplaceAttr function could be implemented in the logger package, however
// this would increase it's complexity again (look [here](https://pkg.go.dev/log/slog#HandlerOptions)
// for a reference implementation.
func (l *grpcLogger) Fatal(args ...interface{}) { func (l *grpcLogger) Fatal(args ...interface{}) {
var pcs [1]uintptr var pcs [1]uintptr

View file

@ -50,12 +50,6 @@ import (
"google.golang.org/grpc" "google.golang.org/grpc"
) )
// TODO(miampf): maybe rewrite as a solution for increasing log level?
// WithIncreasedLevel returns a logger with increased logging level.
// func (l *Logger) WithIncreasedLevel(level zapcore.Level) *Logger {
// return &Logger{logger: l.getZapLogger().WithOptions(zap.IncreaseLevel(level)).Sugar()}
// }
// ReplaceGRPCLogger replaces grpc's internal logger with the given logger. // ReplaceGRPCLogger replaces grpc's internal logger with the given logger.
func ReplaceGRPCLogger(l *slog.Logger) { func ReplaceGRPCLogger(l *slog.Logger) {
replaceGRPCLogger(l) replaceGRPCLogger(l)

View file

@ -51,8 +51,11 @@ func (s *Server) Run(port string) error {
server := grpc.NewServer(logger.GetServerUnaryInterceptor(s.log.WithGroup("gRPC"))) server := grpc.NewServer(logger.GetServerUnaryInterceptor(s.log.WithGroup("gRPC")))
keyserviceproto.RegisterAPIServer(server, s) keyserviceproto.RegisterAPIServer(server, s)
// TODO(miampf): Find out a good way to pass an increased Level to slog // TODO(miampf): Find out a good way to pass an increased Level to slog.
s.log.WithGroup("gRPC").WithIncreasedLevel(zapcore.WarnLevel).ReplaceGRPCLogger() // A reference implementation for something like that exists
// [here](https://pkg.go.dev/log/slog#Handler), however, this would
// utilise structs in the logger package again which is not optimal.
logger.ReplaceGRPCLogger(s.log.WithGroup("gRPC").WithIncreasedLevel(zapcore.WarnLevel))
// start the server // start the server
s.log.Info("Starting Constellation key management service on %s", listener.Addr().String()) s.log.Info("Starting Constellation key management service on %s", listener.Addr().String())

View file

@ -75,6 +75,7 @@ func main() {
flag.BoolVar(&enableLeaderElection, "leader-elect", false, flag.BoolVar(&enableLeaderElection, "leader-elect", false,
"Enable leader election for controller manager. "+ "Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.") "Enabling this will ensure there is only one active controller manager.")
// TODO(miampf): Find out what is going on here and reimplement it in log/slog.
opts := zap.Options{ opts := zap.Options{
Development: true, Development: true,
} }