Skip to content

Commit

Permalink
Convert logging in build.assets/tooling to use slog
Browse files Browse the repository at this point in the history
  • Loading branch information
rosstimothy committed Jan 7, 2025
1 parent 8255a69 commit e6ad66a
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 639 deletions.
134 changes: 0 additions & 134 deletions build.assets/tooling/cmd/notarize-apple-binaries/gon_wrapper.go

This file was deleted.

48 changes: 0 additions & 48 deletions build.assets/tooling/cmd/notarize-apple-binaries/logger_config.go

This file was deleted.

135 changes: 0 additions & 135 deletions build.assets/tooling/cmd/notarize-apple-binaries/main.go

This file was deleted.

7 changes: 4 additions & 3 deletions build.assets/tooling/cmd/protoc-gen-eventschema/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,26 @@ package main
// inspect what is happening inside the plugin.

import (
"context"
"io"
"log/slog"
"os"

"github.com/gogo/protobuf/proto"
"github.com/gogo/protobuf/protoc-gen-gogo/generator"
plugin "github.com/gogo/protobuf/protoc-gen-gogo/plugin"
"github.com/gravitational/trace"
log "github.com/sirupsen/logrus"
)

const pluginInputPathEnvironment = "TELEPORT_PROTOC_READ_FILE"

func readRequest() (*plugin.CodeGeneratorRequest, error) {
inputPath := os.Getenv(pluginInputPathEnvironment)
if inputPath == "" {
log.Error(trace.BadParameter("When built with the 'debug' tag, the input path must be set through the environment variable: %s", pluginInputPathEnvironment))
slog.ErrorContext(context.Background(), "When built with the 'debug' tag, the input path must be set through the TELEPORT_PROTOC_READ_FILE environment variable")
os.Exit(-1)
}
log.Infof("This is a debug build, the protoc request is read from the file: '%s'", inputPath)
slog.InfoContext(context.Background(), "This is a debug build, the protoc request is read from provided file", "file", inputPath)

req, err := readRequestFromFile(inputPath)
if err != nil {
Expand Down
14 changes: 8 additions & 6 deletions build.assets/tooling/cmd/protoc-gen-eventschema/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,23 @@
package main

import (
"context"
"log/slog"
"os"

log "github.com/sirupsen/logrus"
)

func main() {
log.SetLevel(log.DebugLevel)
log.SetOutput(os.Stderr)
logger := slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: slog.LevelDebug}))
slog.SetDefault(logger)

ctx := context.Background()
req, err := readRequest()
if err != nil {
log.WithError(err).Error("Failed to read request")
logger.ErrorContext(ctx, "Failed to read request", "error", err)
os.Exit(-1)
}
if err := handleRequest(req); err != nil {
log.WithError(err).Error("Failed to generate schema")
logger.ErrorContext(ctx, "Failed to generate schema", "error", err)
os.Exit(-1)
}
}
Loading

0 comments on commit e6ad66a

Please sign in to comment.