Skip to content

Commit

Permalink
added more changes for logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Shoaeb Jindani committed Apr 4, 2024
1 parent e16d7cc commit dabab1f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
14 changes: 12 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
package main

import (
"fmt"
"os"
"path/filepath"
"time"

Expand All @@ -27,6 +29,7 @@ import (
cainit "github.com/IBM-Blockchain/fabric-operator/pkg/initializer/ca"
ordererinit "github.com/IBM-Blockchain/fabric-operator/pkg/initializer/orderer"
peerinit "github.com/IBM-Blockchain/fabric-operator/pkg/initializer/peer"
"github.com/IBM-Blockchain/fabric-operator/pkg/util"

logf "sigs.k8s.io/controller-runtime/pkg/log"

Expand Down Expand Up @@ -71,13 +74,19 @@ func main() {
setDefaultConsoleDefinitions(operatorCfg)

operatorCfg.Operator.SetDefaults()

zaplogger, err := util.SetupLogging("DEBUG")
operatorCfg.Logger = zaplogger
if err != nil {
fmt.Print("error initiating the logger", err)
fmt.Print("Will exit Operator", err)
os.Exit(1)
}
if err := command.Operator(operatorCfg); err != nil {
log.Error(err, "failed to start operator")
time.Sleep(15 * time.Second)
}

// TODO
// // TODO
// if err = (&ibpca.IBPCAReconciler{
// Client: mgr.GetClient(),
// Log: ctrl.Log.WithName("controllers").WithName("IBPCA"),
Expand Down Expand Up @@ -114,6 +123,7 @@ func main() {
}

func setDefaultCADefinitions(cfg *config.Config) {

cfg.CAInitConfig = &cainit.Config{
CADefaultConfigPath: filepath.Join(defaultConfigs, "ca/ca.yaml"),
TLSCADefaultConfigPath: filepath.Join(defaultConfigs, "ca/tlsca.yaml"),
Expand Down
24 changes: 14 additions & 10 deletions pkg/command/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,27 +169,31 @@ func OperatorWithSignal(operatorCfg *oconfig.Config, signalHandler context.Conte
}
flag.Parse()

cfg := uberzap.NewProductionConfig()
cfg.OutputPaths = []string{"stdout"}

cfg.Level.SetLevel(zapcore.DebugLevel)

zapLogger, err := cfg.Build()
// Create a new logger with UTC format
config := uberzap.NewProductionConfig()
config.EncoderConfig.TimeKey = "timestamp"
config.EncoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
logger, err := config.Build()
if err != nil {
panic("failed to create logger: " + err.Error())
panic(fmt.Sprintf("failed to initialize logger: %v", err))
}
log := zapr.NewLogger(logger)

// Log some messages
log.Info("Logging in UTC format", "time", time.Now().UTC())

logger := zapr.NewLogger(zapLogger)
// Example of logging with additional context
log.Info("Example with additional context", "key", "value")

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
mgr, err := ctrl.New(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
MetricsBindAddress: metricsAddr,
Port: 9443,
// LeaderElection: enableLeaderElection,
LeaderElectionID: "c30dd930.ibp.com",
LeaderElectionNamespace: operatorNamespace,
Namespace: watchNamespace,
Logger: logger,
Logger: log,
})
if err != nil {
setupLog.Error(err, "unable to start manager")
Expand Down

0 comments on commit dabab1f

Please sign in to comment.