Skip to content

Commit 52ef68f

Browse files
committed
upkeep: byttet ut log med print
Unødvendig med dato og klokkeslett når man skal lage output fra Cli.
1 parent 60091ff commit 52ef68f

File tree

13 files changed

+32
-38
lines changed

13 files changed

+32
-38
lines changed

cmd/aivencmd/createcmd.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func createCommand() *cli.Command {
124124
return fmt.Errorf("an error occurred generating 'AivenApplication': %v", err)
125125
}
126126

127-
fmt.Printf("use the following command to generate configuration secrets:\nnais aiven get %v %v %v\n", service.Name(), aivenApp.Spec.SecretName, aivenApp.Namespace)
127+
fmt.Printf("Use the following command to generate configuration secrets:\n\tnais aiven get %v %v %v\n", service.Name(), aivenApp.Spec.SecretName, aivenApp.Namespace)
128128

129129
return nil
130130
},

cmd/cmd.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
package cmd
22

33
import (
4-
"log"
4+
"fmt"
55
"os"
66
"os/exec"
77

8-
"github.com/nais/cli/cmd/debugcmd"
9-
108
"github.com/nais/cli/cmd/aivencmd"
9+
"github.com/nais/cli/cmd/debugcmd"
1110
"github.com/nais/cli/cmd/devicecmd"
1211
"github.com/nais/cli/cmd/kubeconfigcmd"
1312
"github.com/nais/cli/cmd/postgrescmd"
1413
"github.com/nais/cli/cmd/rootcmd"
1514
"github.com/nais/cli/cmd/validatecmd"
16-
m "github.com/nais/cli/pkg/metrics"
15+
"github.com/nais/cli/pkg/metrics"
1716
"github.com/urfave/cli/v2"
1817
)
1918

@@ -47,7 +46,7 @@ func Run() {
4746
Commands: commands(),
4847
}
4948

50-
m.CollectCommandHistogram(app.Commands)
49+
metrics.CollectCommandHistogram(app.Commands)
5150

5251
// first, before running the cli propper we check if the argv[1] contains a
5352
// thing that is named nais-argv[1]. if so, we run that with the rest of the
@@ -65,7 +64,8 @@ func Run() {
6564

6665
err := app.Run(os.Args)
6766
if err != nil {
68-
log.Fatal(err)
67+
fmt.Println(err)
68+
os.Exit(1)
6969
}
7070
}
7171

cmd/devicecmd/doctor.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package devicecmd
22

33
import (
44
"fmt"
5-
"log"
65

76
"github.com/mitchellh/go-ps"
87
"github.com/nais/cli/pkg/doctor"
@@ -59,7 +58,7 @@ func kolideWorker(checkName string) doctor.Worker {
5958
func isRunning(desiredProc string) (bool, error) {
6059
runningProcs, err := ps.Processes()
6160
if err != nil {
62-
log.Printf("process listing failed: %v\n", err)
61+
fmt.Printf("Process listing failed: %v\n", err)
6362
return false, err
6463
}
6564
for _, runningProc := range runningProcs {

pkg/aiven/aiven.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package aiven
33
import (
44
"context"
55
"fmt"
6-
"log"
76
"strings"
87
"time"
98

@@ -110,7 +109,7 @@ func (a Aiven) createOrUpdate(aivenApp *aiven_nais_io_v1.AivenApplication) error
110109
if err != nil {
111110
return err
112111
}
113-
log.Default().Printf("AivenApplication: '%v' created.", aivenApp.Name)
112+
fmt.Printf("AivenApplication: '%v' created.", aivenApp.Name)
114113
}
115114
} else {
116115
if len(existingAivenApp.GetObjectMeta().GetOwnerReferences()) > 0 {
@@ -122,7 +121,7 @@ func (a Aiven) createOrUpdate(aivenApp *aiven_nais_io_v1.AivenApplication) error
122121
if err != nil {
123122
return err
124123
}
125-
log.Default().Printf("AivenApplication: '%v' updated.", aivenApp.Name)
124+
fmt.Printf("AivenApplication: '%v' updated.", aivenApp.Name)
126125
}
127126
return nil
128127
}

pkg/aiven/secret.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package aiven
33
import (
44
"context"
55
"fmt"
6-
"log"
76
"os"
87

98
"github.com/nais/cli/pkg/aiven/aiven_config"
@@ -57,11 +56,11 @@ func ExtractAndGenerateConfig(service aiven_services.Service, secretName, namesp
5756

5857
if secret.Service.Is(&aiven_services.OpenSearch{}) {
5958
data := secret.Secret.Data
60-
log.Default().Printf("OpenSearch dashboard: https://%s (username: %s, password: %s)",
59+
fmt.Printf("OpenSearch dashboard: https://%s (username: %s, password: %s)",
6160
data[aiven_config.OpenSearchHostKey], data[aiven_config.OpenSearchUsernameKey], data[aiven_config.OpenSearchPasswordKey])
6261
}
6362

64-
log.Default().Printf("configurations from secret '%s' found here:\n%s", existingSecret.Name, dest)
63+
fmt.Printf("Configurations from secret '%s' found here:\n%s", existingSecret.Name, dest)
6564
return nil
6665
}
6766

@@ -113,7 +112,7 @@ func (s *Secret) CreateOpenSearchConfigs() error {
113112
}
114113

115114
func (s *Secret) generateConfig() error {
116-
log.Default().Printf("generating %v config from secret %v", s.Service.Name(), s.Secret.Name)
115+
fmt.Printf("Generating %v config from secret %v", s.Service.Name(), s.Secret.Name)
117116
return s.Service.Generate(s)
118117
}
119118

pkg/aiven/tidy.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ func TidyLocalSecrets() error {
1919
func tidy(folders []string) error {
2020
if len(folders) > 0 {
2121
for _, folder := range folders {
22-
fmt.Printf("deleting: %s\n", folder)
22+
fmt.Printf("Deleting: %s\n", folder)
2323
err := os.RemoveAll(folder)
2424
if err != nil {
2525
return fmt.Errorf("failed deleting %v: %v", folder, err)
2626
}
2727
}
2828
} else {
29-
fmt.Println("all tidy")
29+
fmt.Println("All tidy")
3030
}
3131
return nil
3232
}

pkg/doctor/doctor.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type Examination struct {
2828
}
2929

3030
func (e Examination) Run() map[string]CheckReport {
31-
fmt.Printf("running %d check(s)\n", len(e.Checks))
31+
fmt.Printf("Running %d check(s)\n", len(e.Checks))
3232
resultQueue := make(chan CheckReport, len(e.Checks))
3333
results := make(map[string]CheckReport)
3434
for _, check := range e.Checks {

pkg/k8s/client.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@ import (
66
"log/slog"
77
"os"
88

9-
"k8s.io/client-go/kubernetes"
10-
119
"github.com/go-logr/logr"
1210
liberatorscheme "github.com/nais/liberator/pkg/scheme"
1311
"k8s.io/apimachinery/pkg/runtime"
12+
"k8s.io/client-go/kubernetes"
1413
"k8s.io/client-go/rest"
1514
"k8s.io/client-go/tools/clientcmd"
1615
ctrl "sigs.k8s.io/controller-runtime/pkg/client"

pkg/kubeconfig/gcpcluster.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func getClusters(ctx context.Context, projects []project, options filterOptions)
5858
var clusters []k8sCluster
5959
for _, project := range projects {
6060
if options.verbose {
61-
fmt.Println("getting clusters for", project.ID)
61+
fmt.Println("Getting clusters for", project.ID)
6262
}
6363
var cluster []k8sCluster
6464
var err error

pkg/kubeconfig/gcpproject.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func getProjects(ctx context.Context, tenant string, options filterOptions) ([]p
4545
}
4646

4747
if options.verbose {
48-
fmt.Printf("filter: %s\n", filter)
48+
fmt.Printf("Filter: %s\n", filter)
4949
}
5050

5151
call := svc.Projects.Search().Query(filter)
@@ -73,7 +73,7 @@ func getProjects(ctx context.Context, tenant string, options filterOptions) ([]p
7373
call.PageToken(response.NextPageToken)
7474
}
7575
if options.verbose {
76-
fmt.Printf("projects:\n")
76+
fmt.Printf("Projects:\n")
7777
for _, p := range projects {
7878
fmt.Printf("%s\t%s\t%s\t%v\n", p.ID, p.Tenant, p.Name, p.Kind)
7979
}

pkg/metrics/otel.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package metrics
22

33
import (
44
"context"
5-
"log"
5+
"fmt"
66
"os"
77
"strings"
88
"time"
@@ -98,7 +98,7 @@ func intersection(list1, list2 []string) []string {
9898
func CollectCommandHistogram(commands []*cli.Command) {
9999
doNotTrack := os.Getenv("DO_NOT_TRACK")
100100
if doNotTrack == "1" {
101-
log.Default().Println("DO_NOT_TRACK is set, not collecting metrics")
101+
fmt.Println("DO_NOT_TRACK is set, not collecting metrics")
102102
}
103103

104104
ctx := context.Background()

pkg/naisdevice/status.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func waitForConnectionState(ctx context.Context, client pb.DeviceAgentClient, wa
5757
if err != nil {
5858
return fmt.Errorf("error while receiving status: %w", err)
5959
}
60-
fmt.Printf("state: %s\n", status.ConnectionState)
60+
fmt.Printf("State: %s\n", status.ConnectionState)
6161
if status.ConnectionState == wantedAgentState {
6262
return nil
6363
}
@@ -105,7 +105,7 @@ func gatewayPrivileged(gw *pb.Gateway) string {
105105
}
106106

107107
func PrintVerboseStatus(status *pb.AgentStatus) {
108-
fmt.Printf("naisdevice status: %s\n", status.ConnectionStateString())
108+
fmt.Printf("Naisdevice status: %s\n", status.ConnectionStateString())
109109
if status.NewVersionAvailable {
110110
fmt.Printf("\nNew version of naisdevice available!\nSee https://doc.nais.io/device/update for upgrade instructions.\n")
111111
}

pkg/postgres/proxy.go

+8-10
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"errors"
66
"fmt"
77
"io"
8-
"log"
98
"net"
109
"os"
1110
"os/signal"
@@ -14,9 +13,8 @@ import (
1413
"syscall"
1514
"time"
1615

17-
"github.com/GoogleCloudPlatform/cloudsql-proxy/logging"
18-
1916
"cloud.google.com/go/cloudsqlconn"
17+
"github.com/GoogleCloudPlatform/cloudsql-proxy/logging"
2018
)
2119

2220
func RunProxy(ctx context.Context, appName, cluster, namespace, host string, port uint, verbose bool) error {
@@ -113,7 +111,7 @@ func runProxy(ctx context.Context, projectID, connectionName, address string, po
113111
<-ctx.Done()
114112
// TODO: Make this not panic listener.Accept()
115113
if err := listener.Close(); err != nil {
116-
log.Println("error closing listener", err)
114+
fmt.Println("error closing listener", err)
117115
}
118116
}()
119117

@@ -127,10 +125,10 @@ OUTER:
127125
break OUTER
128126
default:
129127
}
130-
log.Println("error accepting connection", err)
128+
fmt.Println("error accepting connection", err)
131129
continue
132130
}
133-
log.Println("New connection", conn.RemoteAddr())
131+
fmt.Println("New connection", conn.RemoteAddr())
134132
wg.Add(1)
135133
go func() {
136134
defer wg.Done()
@@ -141,13 +139,13 @@ OUTER:
141139
go func() {
142140
<-ctx.Done()
143141
if err := conn.Close(); err != nil {
144-
log.Println("error closing connection", err)
142+
fmt.Println("error closing connection", err)
145143
}
146144
}()
147145

148146
conn2, err := d.Dial(ctx, connectionName)
149147
if err != nil {
150-
log.Println("error dialing connection", err)
148+
fmt.Println("error dialing connection", err)
151149
return
152150
}
153151
defer conn2.Close()
@@ -156,7 +154,7 @@ OUTER:
156154
go copy(closer, conn2, conn)
157155
go copy(closer, conn, conn2)
158156
<-closer
159-
log.Println("Connection complete", conn.RemoteAddr())
157+
fmt.Println("Connection complete", conn.RemoteAddr())
160158
}()
161159
}
162160

@@ -178,7 +176,7 @@ func checkPostgresqlPassword() error {
178176

179177
dirname, err := os.UserHomeDir()
180178
if err != nil {
181-
log.Println("could not get home directory, can not check for .pgpass file")
179+
fmt.Println("could not get home directory, can not check for .pgpass file")
182180
return nil
183181
}
184182

0 commit comments

Comments
 (0)