Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 696f2b5

Browse files
authored
Merge pull request #66 from chris-crone/iss-28
Use logrus for logging
2 parents cb3d019 + 7222a84 commit 696f2b5

File tree

8 files changed

+24
-13
lines changed

8 files changed

+24
-13
lines changed

Gopkg.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@
3838
name = "github.com/gotestyourself/gotestyourself"
3939
branch = "master"
4040

41+
[[constraint]]
42+
name = "github.com/sirupsen/logrus"
43+
version = "v1.0.5"
44+
4145
[[override]]
4246
name = "k8s.io/kubernetes"
4347
revision = "v1.8.2"

cmd/build.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package cmd
22

33
import (
4-
"fmt"
5-
64
"github.com/docker/lunchbox/internal"
5+
log "github.com/sirupsen/logrus"
76
"github.com/spf13/cobra"
87
)
98

@@ -12,7 +11,7 @@ var buildCmd = &cobra.Command{
1211
Use: "build <app-name>",
1312
Short: "Compile an app package from locally available data",
1413
Run: func(cmd *cobra.Command, args []string) {
15-
fmt.Println("build called")
14+
log.Info("build called")
1615
},
1716
}
1817

cmd/deploy.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package cmd
22

33
import (
4-
"fmt"
5-
64
"github.com/docker/lunchbox/internal"
5+
log "github.com/sirupsen/logrus"
76
"github.com/spf13/cobra"
87
)
98

@@ -12,7 +11,7 @@ var deployCmd = &cobra.Command{
1211
Use: "deploy <app-name>",
1312
Short: "Deploy the specified app on the connected cluster",
1413
Run: func(cmd *cobra.Command, args []string) {
15-
fmt.Println("deploy called")
14+
log.Info("deploy called")
1615
},
1716
}
1817

cmd/init.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package cmd
22

33
import (
4-
"fmt"
5-
64
"github.com/docker/cli/cli"
75
"github.com/docker/lunchbox/packager"
86
"github.com/spf13/cobra"
@@ -14,7 +12,6 @@ var initCmd = &cobra.Command{
1412
Short: "Initialize an app package in the current working directory",
1513
Args: cli.ExactArgs(1),
1614
RunE: func(cmd *cobra.Command, args []string) error {
17-
fmt.Println("init called")
1815
return packager.Init(args[0], composeFile)
1916
},
2017
}

cmd/root.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package cmd
33
import (
44
"os"
55

6+
"github.com/docker/lunchbox/internal"
7+
log "github.com/sirupsen/logrus"
68
"github.com/spf13/cobra"
79
)
810

@@ -12,6 +14,12 @@ var rootCmd = &cobra.Command{
1214
Short: "Docker App Packages",
1315
Long: "",
1416
SilenceUsage: true,
17+
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
18+
if internal.Debug {
19+
log.SetLevel(log.DebugLevel)
20+
}
21+
return nil
22+
},
1523
}
1624

1725
func firstOrEmpty(list []string) string {
@@ -32,6 +40,8 @@ func Execute() {
3240
func init() {
3341
cobra.OnInitialize(initConfig)
3442

43+
rootCmd.PersistentFlags().BoolVar(&internal.Debug, "debug", false, "Enable debug mode")
44+
3545
// Here you will define your flags and configuration settings.
3646
// Cobra supports persistent flags, which, if defined here,
3747
// will be global for your application.

internal/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package internal
22

33
var (
4+
// Debug enables debug logging and features
5+
Debug = false
46
// Experimental enables experimental features if set to "on"
57
Experimental = "on"
68
)

packager/init.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package packager
33
import (
44
"fmt"
55
"io/ioutil"
6-
"log"
76
"os"
87
"os/user"
98
"path/filepath"
@@ -12,6 +11,7 @@ import (
1211
"github.com/docker/lunchbox/types"
1312
"github.com/docker/lunchbox/utils"
1413
"github.com/pkg/errors"
14+
log "github.com/sirupsen/logrus"
1515
"gopkg.in/yaml.v2"
1616
)
1717

@@ -49,7 +49,7 @@ func Init(name string, composeFile string) error {
4949
}
5050

5151
func initFromScratch(name string) error {
52-
log.Println("init from scratch")
52+
log.Debug("init from scratch")
5353
composeData, err := composeFileFromScratch()
5454
if err != nil {
5555
return err
@@ -152,7 +152,7 @@ func extractVariables(composeRaw string) ([]string, error) {
152152
}
153153

154154
func initFromComposeFile(name string, composeFile string) error {
155-
log.Println("init from compose")
155+
log.Debug("init from compose")
156156

157157
dirName := utils.DirNameFromAppName(name)
158158
composeRaw, err := ioutil.ReadFile(composeFile)

0 commit comments

Comments
 (0)