Skip to content

Commit

Permalink
feat: add zap logger
Browse files Browse the repository at this point in the history
  • Loading branch information
hanshal101 authored and hanshal101 committed Jun 27, 2024
1 parent df6d72d commit 851694d
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ require (
go.opentelemetry.io/otel/sdk/metric v1.26.0
go.uber.org/goleak v1.3.0
go.uber.org/multierr v1.11.0
go.uber.org/zap v1.26.0
go.uber.org/zap v1.27.0
gopkg.in/yaml.v3 v3.0.1
)

Expand Down
2 changes: 2 additions & 0 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added main.exe
Binary file not shown.
20 changes: 17 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
package main

import (
"log"

"github.com/EinStack/glide/pkg/cmd"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)

var logger *zap.Logger

func init() {
config := zap.NewProductionConfig()
config.EncoderConfig.TimeKey = "timestamp"
config.EncoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
var err error
logger, err = config.Build()
if err != nil {
panic(err)
}
zap.ReplaceGlobals(logger)
}

// @title Glide
// @version 0.0.1
// @description API documentation for Glide, an open-source lightweight high-performance model gateway
Expand All @@ -27,6 +41,6 @@ func main() {
cli := cmd.NewCLI()

if err := cli.Execute(); err != nil {
log.Fatalf("💥Glide has finished with error: %v", err)
logger.Fatal("💥Glide has finished with error: %v", zap.Error(err))
}
}
3 changes: 3 additions & 0 deletions pkg/cmd/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"log"

"github.com/EinStack/glide/pkg/version"
"go.uber.org/zap"

"github.com/EinStack/glide/pkg/config"

Expand Down Expand Up @@ -46,6 +47,8 @@ func NewCLI() *cobra.Command {
RunE: func(cmd *cobra.Command, _ []string) error {
configProvider := config.NewProvider()

zap.L().Info("Glide command executed")

err := configProvider.LoadDotEnv(dotEnvFile)

if err != nil {
Expand Down

0 comments on commit 851694d

Please sign in to comment.