Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ var createCmd = &cobra.Command{

func init() {
cmd.RootCmd.AddCommand(createCmd)

}
23 changes: 17 additions & 6 deletions cmd/deploy/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"errors"
"google.golang.org/grpc/status"
"os"
"regexp"

Expand All @@ -15,6 +16,11 @@ import (
"github.com/spf13/cobra"
)

const (
Red = "\033[31m" // Red color for errors
Reset = "\033[0m" // Reset to default
)

var env string
var definitionFile string
var provisioningFile string
Expand Down Expand Up @@ -92,23 +98,20 @@ func deployUsingFiles(ctx context.Context) {
})

if err != nil {
log.Fatal("Failed to deploy service ", err)
handleDeployServiceError(err)
}
}

func deployUsingServiceNameAndVersion(ctx context.Context) {
log.Info("deploying service :", serviceName, ":", serviceVersion, " in env :", env)
err := serviceClient.DeployReleasedService(&ctx, &serviceProto.DeployReleasedServiceRequest{
_ = serviceClient.DeployReleasedService(&ctx, &serviceProto.DeployReleasedServiceRequest{
EnvName: env,
ServiceIdentifier: &serviceProto.ServiceIdentifier{
ServiceName: serviceName,
ServiceVersion: serviceVersion,
},
})

if err != nil {
log.Fatal("Failed to deploy service ", err)
}
}

func deployUsingServiceNameAndLabels(ctx context.Context) {
Expand All @@ -122,7 +125,7 @@ func deployUsingServiceNameAndLabels(ctx context.Context) {
})

if err != nil {
log.Fatal("Failed to deploy service ", err)
handleDeployServiceError(err)
}
}

Expand All @@ -137,3 +140,11 @@ func validateLabels(labels string) error {
}
return nil
}

func handleDeployServiceError(err error) {
if st, ok := status.FromError(err); ok {
log.Fatalf("%s %s: %s %s", Red, st.Message(), Reset)
} else {
log.Fatalf("%s %s: %s %v", Red, err, Reset)
}
}
31 changes: 19 additions & 12 deletions internal/ui/logger.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
package ui

import (
"github.com/dream11/odin/pkg/constant"
"github.com/dream11/odin/pkg/util"
log "github.com/sirupsen/logrus"
)
import log "github.com/sirupsen/logrus"

func init() {
type CustomTextFormatter struct {
BaseFormatter *log.TextFormatter
}

func (f *CustomTextFormatter) Format(entry *log.Entry) ([]byte, error) {
// Return only the log message, ignoring the log level and timestamp
return []byte(entry.Message + "\n"), nil
}

log.SetFormatter(&log.TextFormatter{
ForceColors: true,
DisableColors: false,
TimestampFormat: "2006-01-02 15:04:05", // Custom format
FullTimestamp: true,
func init() {
log.SetFormatter(&CustomTextFormatter{
BaseFormatter: &log.TextFormatter{
ForceColors: true,
DisableColors: false,
DisableTimestamp: true,
DisableLevelTruncation: true,
},
})
level, err := log.ParseLevel(util.GetEnvOrDefault(constant.LogLevelKey, "info"))

level, err := log.ParseLevel("info")
if err != nil {
log.Warning("Invalid log level. Allowed values are: panic, fatal, error, warn, info, debug, trace")
log.SetLevel(log.InfoLevel)
Expand Down