Skip to content

Commit 4782911

Browse files
arvind-choudhary-hHarness
authored andcommitted
Updated logging (#116)
* a41a3e []: updated logging
1 parent 0481b3e commit 4782911

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

cmd/artifact/command/list.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ package command
22

33
import (
44
"context"
5+
"fmt"
56

67
client "github.com/harness/harness-cli/internal/api/ar"
78
client2 "github.com/harness/harness-cli/util/client"
89
"github.com/harness/harness-cli/util/common/printer"
10+
"github.com/rs/zerolog/log"
911

1012
"github.com/spf13/cobra"
1113
)
@@ -41,6 +43,11 @@ func NewListArtifactCmd(c *client.ClientWithResponses) *cobra.Command {
4143
return err
4244
}
4345

46+
if response.JSON200 == nil || response.JSON200.Data.Artifacts == nil {
47+
log.Debug().Msgf("Unable to list artifacts")
48+
return fmt.Errorf("unable to list artifacts")
49+
}
50+
4451
err = printer.Print(response.JSON200.Data.Artifacts, *response.JSON200.Data.PageIndex,
4552
*response.JSON200.Data.PageCount, *response.JSON200.Data.ItemCount, true, [][]string{
4653
{"name", "Artifact"},

cmd/hc/main.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,10 @@ import (
1010
"runtime/pprof"
1111
"time"
1212

13-
"github.com/harness/harness-cli/cmd/api"
1413
"github.com/harness/harness-cli/cmd/artifact"
1514
"github.com/harness/harness-cli/cmd/auth"
16-
"github.com/harness/harness-cli/cmd/organisation"
17-
"github.com/harness/harness-cli/cmd/project"
1815
"github.com/harness/harness-cli/cmd/registry"
1916
"github.com/harness/harness-cli/config"
20-
"github.com/harness/harness-cli/module/ar/migrate/types"
2117
"github.com/harness/harness-cli/util/templates"
2218

2319
"github.com/rs/zerolog"
@@ -34,8 +30,9 @@ func main() {
3430
var verbose bool
3531

3632
rootCmd := &cobra.Command{
37-
Use: "hc",
38-
Short: "CLI tool for Harness",
33+
Use: "hc",
34+
Short: "CLI tool for Harness",
35+
SilenceUsage: true,
3936
Long: templates.LongDesc(`
4037
Harness CLI is a tool to interact with Harness Resources.
4138
@@ -69,14 +66,17 @@ func main() {
6966
}
7067
}
7168

72-
// Set up logging if verbose mode is enabled
69+
// Set up logging based on verbose flag
7370
if verbose {
7471
logWriter := zerolog.ConsoleWriter{
7572
Out: os.Stderr,
7673
TimeFormat: time.RFC3339,
7774
NoColor: false,
7875
}
79-
log.Logger = log.Output(logWriter).Hook(types.ErrorHook{})
76+
log.Logger = log.Output(logWriter)
77+
} else {
78+
// Disable logging when verbose is not enabled
79+
log.Logger = zerolog.Nop()
8080
}
8181

8282
return initProfiling()
@@ -131,16 +131,16 @@ func main() {
131131
rootCmd.AddCommand(auth.GetRootCmd())
132132
rootCmd.AddCommand(registry.GetRootCmd())
133133
rootCmd.AddCommand(artifact.GetRootCmd())
134-
rootCmd.AddCommand(project.GetRootCmd())
135-
rootCmd.AddCommand(organisation.GetRootCmd())
136-
rootCmd.AddCommand(api.GetRootCmd())
134+
//rootCmd.AddCommand(project.GetRootCmd())
135+
//rootCmd.AddCommand(organisation.GetRootCmd())
136+
//rootCmd.AddCommand(api.GetRootCmd())
137137
rootCmd.AddCommand(versionCmd())
138138
rootCmd.AddCommand(upgradeCmd())
139139

140140
flags := rootCmd.PersistentFlags()
141141

142142
addProfilingFlags(flags)
143-
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
143+
//zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
144144

145145
if err := rootCmd.Execute(); err != nil {
146146
fmt.Println(err)

util/common/printer/json.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func DefaultJsonOptions() JsonOptions {
3535
Indent: true,
3636
IndentPrefix: "",
3737
IndentSize: 2,
38-
ShowPagination: true,
38+
ShowPagination: false,
3939
}
4040
}
4141

0 commit comments

Comments
 (0)