Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

Commit

Permalink
Merge pull request #110 from weaveworks/logging
Browse files Browse the repository at this point in the history
Add structured logging
  • Loading branch information
luxas authored Jul 9, 2019
2 parents 628afb7 + 24835bd commit a6cfd52
Show file tree
Hide file tree
Showing 41 changed files with 141 additions and 76 deletions.
42 changes: 17 additions & 25 deletions api/meta.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
* [type TypeMeta](#TypeMeta)
* [func (t *TypeMeta) GetKind() Kind](#TypeMeta.GetKind)
* [func (t *TypeMeta) GetTypeMeta() *TypeMeta](#TypeMeta.GetTypeMeta)
* [func (t *TypeMeta) SetKind(kind Kind)](#TypeMeta.SetKind)
* [type UID](#UID)
* [func (u UID) String() string](#UID.String)

Expand Down Expand Up @@ -211,7 +210,7 @@ func (i IPAddresses) String() string



## <a name="Kind">type</a> [Kind](/pkg/apis/meta/v1alpha1/meta.go?s=1284:1300#L63)
## <a name="Kind">type</a> [Kind](/pkg/apis/meta/v1alpha1/meta.go?s=1218:1234#L59)
``` go
type Kind string
```
Expand All @@ -224,7 +223,7 @@ type Kind string



### <a name="Kind.Lower">func</a> (Kind) [Lower](/pkg/apis/meta/v1alpha1/meta.go?s=1710:1738#L85)
### <a name="Kind.Lower">func</a> (Kind) [Lower](/pkg/apis/meta/v1alpha1/meta.go?s=1644:1672#L81)
``` go
func (k Kind) Lower() string
```
Expand All @@ -233,7 +232,7 @@ Returns a lowercase string representation of the Kind



### <a name="Kind.String">func</a> (Kind) [String](/pkg/apis/meta/v1alpha1/meta.go?s=1403:1432#L68)
### <a name="Kind.String">func</a> (Kind) [String](/pkg/apis/meta/v1alpha1/meta.go?s=1337:1366#L64)
``` go
func (k Kind) String() string
```
Expand All @@ -242,7 +241,7 @@ Returns a string representation of the Kind suitable for sentences



### <a name="Kind.Title">func</a> (Kind) [Title](/pkg/apis/meta/v1alpha1/meta.go?s=1601:1629#L80)
### <a name="Kind.Title">func</a> (Kind) [Title](/pkg/apis/meta/v1alpha1/meta.go?s=1535:1563#L76)
``` go
func (k Kind) Title() string
```
Expand Down Expand Up @@ -299,7 +298,7 @@ func (i *OCIImageRef) UnmarshalJSON(b []byte) error



## <a name="Object">type</a> [Object](/pkg/apis/meta/v1alpha1/meta.go?s=3801:4148#L169)
## <a name="Object">type</a> [Object](/pkg/apis/meta/v1alpha1/meta.go?s=3735:4082#L165)
``` go
type Object interface {
runtime.Object
Expand Down Expand Up @@ -337,7 +336,7 @@ extra GetName() and GetUID() methods from ObjectMeta



## <a name="ObjectMeta">type</a> [ObjectMeta](/pkg/apis/meta/v1alpha1/meta.go?s=1945:2247#L92)
## <a name="ObjectMeta">type</a> [ObjectMeta](/pkg/apis/meta/v1alpha1/meta.go?s=1879:2181#L88)
``` go
type ObjectMeta struct {
Name string `json:"name"`
Expand All @@ -361,7 +360,7 @@ implement the Object interface



### <a name="ObjectMeta.GetAnnotation">func</a> (\*ObjectMeta) [GetAnnotation](/pkg/apis/meta/v1alpha1/meta.go?s=3356:3409#L152)
### <a name="ObjectMeta.GetAnnotation">func</a> (\*ObjectMeta) [GetAnnotation](/pkg/apis/meta/v1alpha1/meta.go?s=3290:3343#L148)
``` go
func (o *ObjectMeta) GetAnnotation(key string) string
```
Expand All @@ -370,7 +369,7 @@ GetAnnotation returns the label value for the key



### <a name="ObjectMeta.GetCreated">func</a> (\*ObjectMeta) [GetCreated](/pkg/apis/meta/v1alpha1/meta.go?s=2792:2831#L126)
### <a name="ObjectMeta.GetCreated">func</a> (\*ObjectMeta) [GetCreated](/pkg/apis/meta/v1alpha1/meta.go?s=2726:2765#L122)
``` go
func (o *ObjectMeta) GetCreated() *Time
```
Expand All @@ -379,7 +378,7 @@ GetCreated returns when the Object was created



### <a name="ObjectMeta.GetLabel">func</a> (\*ObjectMeta) [GetLabel](/pkg/apis/meta/v1alpha1/meta.go?s=3014:3062#L136)
### <a name="ObjectMeta.GetLabel">func</a> (\*ObjectMeta) [GetLabel](/pkg/apis/meta/v1alpha1/meta.go?s=2948:2996#L132)
``` go
func (o *ObjectMeta) GetLabel(key string) string
```
Expand All @@ -388,7 +387,7 @@ GetLabel returns the label value for the key



### <a name="ObjectMeta.GetName">func</a> (\*ObjectMeta) [GetName](/pkg/apis/meta/v1alpha1/meta.go?s=2398:2435#L106)
### <a name="ObjectMeta.GetName">func</a> (\*ObjectMeta) [GetName](/pkg/apis/meta/v1alpha1/meta.go?s=2332:2369#L102)
``` go
func (o *ObjectMeta) GetName() string
```
Expand All @@ -397,7 +396,7 @@ GetName returns the name of the Object



### <a name="ObjectMeta.GetObjectMeta">func</a> (\*ObjectMeta) [GetObjectMeta](/pkg/apis/meta/v1alpha1/meta.go?s=2292:2340#L101)
### <a name="ObjectMeta.GetObjectMeta">func</a> (\*ObjectMeta) [GetObjectMeta](/pkg/apis/meta/v1alpha1/meta.go?s=2226:2274#L97)
``` go
func (o *ObjectMeta) GetObjectMeta() *ObjectMeta
```
Expand All @@ -406,7 +405,7 @@ This is a helper for APIType generation



### <a name="ObjectMeta.GetUID">func</a> (\*ObjectMeta) [GetUID](/pkg/apis/meta/v1alpha1/meta.go?s=2597:2630#L116)
### <a name="ObjectMeta.GetUID">func</a> (\*ObjectMeta) [GetUID](/pkg/apis/meta/v1alpha1/meta.go?s=2531:2564#L112)
``` go
func (o *ObjectMeta) GetUID() UID
```
Expand All @@ -415,7 +414,7 @@ GetUID returns the UID of the Object



### <a name="ObjectMeta.SetAnnotation">func</a> (\*ObjectMeta) [SetAnnotation](/pkg/apis/meta/v1alpha1/meta.go?s=3530:3583#L160)
### <a name="ObjectMeta.SetAnnotation">func</a> (\*ObjectMeta) [SetAnnotation](/pkg/apis/meta/v1alpha1/meta.go?s=3464:3517#L156)
``` go
func (o *ObjectMeta) SetAnnotation(key, value string)
```
Expand All @@ -424,7 +423,7 @@ SetAnnotation sets a label value for a key



### <a name="ObjectMeta.SetCreated">func</a> (\*ObjectMeta) [SetCreated](/pkg/apis/meta/v1alpha1/meta.go?s=2905:2945#L131)
### <a name="ObjectMeta.SetCreated">func</a> (\*ObjectMeta) [SetCreated](/pkg/apis/meta/v1alpha1/meta.go?s=2839:2879#L127)
``` go
func (o *ObjectMeta) SetCreated(t *Time)
```
Expand All @@ -433,7 +432,7 @@ SetCreated returns when the Object was created



### <a name="ObjectMeta.SetLabel">func</a> (\*ObjectMeta) [SetLabel](/pkg/apis/meta/v1alpha1/meta.go?s=3168:3216#L144)
### <a name="ObjectMeta.SetLabel">func</a> (\*ObjectMeta) [SetLabel](/pkg/apis/meta/v1alpha1/meta.go?s=3102:3150#L140)
``` go
func (o *ObjectMeta) SetLabel(key, value string)
```
Expand All @@ -442,7 +441,7 @@ SetLabel sets a label value for a key



### <a name="ObjectMeta.SetName">func</a> (\*ObjectMeta) [SetName](/pkg/apis/meta/v1alpha1/meta.go?s=2495:2536#L111)
### <a name="ObjectMeta.SetName">func</a> (\*ObjectMeta) [SetName](/pkg/apis/meta/v1alpha1/meta.go?s=2429:2470#L107)
``` go
func (o *ObjectMeta) SetName(name string)
```
Expand All @@ -451,7 +450,7 @@ SetName sets the name of the Object



### <a name="ObjectMeta.SetUID">func</a> (\*ObjectMeta) [SetUID](/pkg/apis/meta/v1alpha1/meta.go?s=2687:2723#L121)
### <a name="ObjectMeta.SetUID">func</a> (\*ObjectMeta) [SetUID](/pkg/apis/meta/v1alpha1/meta.go?s=2621:2657#L117)
``` go
func (o *ObjectMeta) SetUID(uid UID)
```
Expand Down Expand Up @@ -665,13 +664,6 @@ This is a helper for APIType generation



### <a name="TypeMeta.SetKind">func</a> (\*TypeMeta) [SetKind](/pkg/apis/meta/v1alpha1/meta.go?s=1218:1255#L59)
``` go
func (t *TypeMeta) SetKind(kind Kind)
```



## <a name="UID">type</a> [UID](/pkg/apis/meta/v1alpha1/uid.go?s=74:89#L6)
``` go
type UID string
Expand Down
28 changes: 28 additions & 0 deletions cmd/ignite/cmd/cmdutil/flags.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmdutil

import (
"github.com/sirupsen/logrus"
"github.com/spf13/pflag"
meta "github.com/weaveworks/ignite/pkg/apis/meta/v1alpha1"
)
Expand Down Expand Up @@ -77,3 +78,30 @@ func OCIImageRefVar(fs *pflag.FlagSet, ptr *meta.OCIImageRef, name string, defVa
func OCIImageRefVarP(fs *pflag.FlagSet, ptr *meta.OCIImageRef, name, shorthand string, defVal meta.OCIImageRef, usage string) {
fs.VarP(&OCIImageRefFlag{value: defVal}, name, shorthand, usage)
}

type LogLevelFlag struct {
value *logrus.Level
}

func (lf *LogLevelFlag) Set(val string) error {
var err error
*lf.value, err = logrus.ParseLevel(val)
return err
}

func (lf *LogLevelFlag) String() string {
if lf.value == nil {
return ""
}
return lf.value.String()
}

func (lf *LogLevelFlag) Type() string {
return "loglevel"
}

var _ pflag.Value = &LogLevelFlag{}

func LogLevelFlagVar(fs *pflag.FlagSet, ptr *logrus.Level) {
fs.Var(&LogLevelFlag{value: ptr}, "log-level", "Specify the loglevel for the program")
}
13 changes: 11 additions & 2 deletions cmd/ignite/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@ import (
"os"

"github.com/lithammer/dedent"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/weaveworks/ignite/cmd/ignite/cmd/cmdutil"
"github.com/weaveworks/ignite/cmd/ignite/cmd/imgcmd"
"github.com/weaveworks/ignite/cmd/ignite/cmd/kerncmd"
"github.com/weaveworks/ignite/cmd/ignite/cmd/vmcmd"
"github.com/weaveworks/ignite/pkg/logs"
"github.com/weaveworks/ignite/pkg/util"
)

var logLevel = logrus.InfoLevel

// NewIgniteCommand returns the root command for ignite
func NewIgniteCommand(in io.Reader, out, err io.Writer) *cobra.Command {
imageCmd := imgcmd.NewCmdImage(os.Stdout)
Expand All @@ -41,7 +45,7 @@ func NewIgniteCommand(in io.Reader, out, err io.Writer) *cobra.Command {
panic(err)
}

logs.InitLogs()
logs.InitLogs(logLevel)
},
Long: dedent.Dedent(fmt.Sprintf(`
Ignite is a containerized Firecracker microVM administration tool.
Expand Down Expand Up @@ -70,7 +74,7 @@ func NewIgniteCommand(in io.Reader, out, err io.Writer) *cobra.Command {
`, imageCmd.Short, kernelCmd.Short, vmCmd.Short)),
}

AddQuietFlag(root.PersistentFlags())
addGlobalFlags(root.PersistentFlags())

root.AddCommand(imageCmd)
root.AddCommand(kernelCmd)
Expand All @@ -95,6 +99,11 @@ func NewIgniteCommand(in io.Reader, out, err io.Writer) *cobra.Command {
return root
}

func addGlobalFlags(fs *pflag.FlagSet) {
AddQuietFlag(fs)
cmdutil.LogLevelFlagVar(fs, &logLevel)
}

// AddQuietFlag adds the quiet flag to a flagset
func AddQuietFlag(fs *pflag.FlagSet) {
fs.BoolVarP(&logs.Quiet, "quiet", "q", logs.Quiet, "The quiet mode allows for machine-parsable output, by printing only IDs")
Expand Down
5 changes: 3 additions & 2 deletions docs/cli/ignite.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ Example usage:
### Options

```
-h, --help help for ignite
-q, --quiet The quiet mode allows for machine-parsable output, by printing only IDs
-h, --help help for ignite
--log-level loglevel Specify the loglevel for the program (default info)
-q, --quiet The quiet mode allows for machine-parsable output, by printing only IDs
```

### SEE ALSO
Expand Down
3 changes: 2 additions & 1 deletion docs/cli/ignite_attach.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ ignite attach <vm> [flags]
### Options inherited from parent commands

```
-q, --quiet The quiet mode allows for machine-parsable output, by printing only IDs
--log-level loglevel Specify the loglevel for the program (default info)
-q, --quiet The quiet mode allows for machine-parsable output, by printing only IDs
```

### SEE ALSO
Expand Down
3 changes: 2 additions & 1 deletion docs/cli/ignite_completion.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ ignite completion [flags]
### Options inherited from parent commands

```
-q, --quiet The quiet mode allows for machine-parsable output, by printing only IDs
--log-level loglevel Specify the loglevel for the program (default info)
-q, --quiet The quiet mode allows for machine-parsable output, by printing only IDs
```

### SEE ALSO
Expand Down
3 changes: 2 additions & 1 deletion docs/cli/ignite_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ ignite create <OCI image> [flags]
### Options inherited from parent commands

```
-q, --quiet The quiet mode allows for machine-parsable output, by printing only IDs
--log-level loglevel Specify the loglevel for the program (default info)
-q, --quiet The quiet mode allows for machine-parsable output, by printing only IDs
```

### SEE ALSO
Expand Down
3 changes: 2 additions & 1 deletion docs/cli/ignite_gitops.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ ignite gitops [flags]
### Options inherited from parent commands

```
-q, --quiet The quiet mode allows for machine-parsable output, by printing only IDs
--log-level loglevel Specify the loglevel for the program (default info)
-q, --quiet The quiet mode allows for machine-parsable output, by printing only IDs
```

### SEE ALSO
Expand Down
3 changes: 2 additions & 1 deletion docs/cli/ignite_image.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ ignite image [flags]
### Options inherited from parent commands

```
-q, --quiet The quiet mode allows for machine-parsable output, by printing only IDs
--log-level loglevel Specify the loglevel for the program (default info)
-q, --quiet The quiet mode allows for machine-parsable output, by printing only IDs
```

### SEE ALSO
Expand Down
3 changes: 2 additions & 1 deletion docs/cli/ignite_image_import.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ ignite image import <OCI image> [flags]
### Options inherited from parent commands

```
-q, --quiet The quiet mode allows for machine-parsable output, by printing only IDs
--log-level loglevel Specify the loglevel for the program (default info)
-q, --quiet The quiet mode allows for machine-parsable output, by printing only IDs
```

### SEE ALSO
Expand Down
3 changes: 2 additions & 1 deletion docs/cli/ignite_image_ls.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ ignite image ls [flags]
### Options inherited from parent commands

```
-q, --quiet The quiet mode allows for machine-parsable output, by printing only IDs
--log-level loglevel Specify the loglevel for the program (default info)
-q, --quiet The quiet mode allows for machine-parsable output, by printing only IDs
```

### SEE ALSO
Expand Down
3 changes: 2 additions & 1 deletion docs/cli/ignite_image_rm.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ ignite image rm <image>... [flags]
### Options inherited from parent commands

```
-q, --quiet The quiet mode allows for machine-parsable output, by printing only IDs
--log-level loglevel Specify the loglevel for the program (default info)
-q, --quiet The quiet mode allows for machine-parsable output, by printing only IDs
```

### SEE ALSO
Expand Down
3 changes: 2 additions & 1 deletion docs/cli/ignite_inspect.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ ignite inspect <kind> <object> [flags]
### Options inherited from parent commands

```
-q, --quiet The quiet mode allows for machine-parsable output, by printing only IDs
--log-level loglevel Specify the loglevel for the program (default info)
-q, --quiet The quiet mode allows for machine-parsable output, by printing only IDs
```

### SEE ALSO
Expand Down
3 changes: 2 additions & 1 deletion docs/cli/ignite_kernel.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ ignite kernel [flags]
### Options inherited from parent commands

```
-q, --quiet The quiet mode allows for machine-parsable output, by printing only IDs
--log-level loglevel Specify the loglevel for the program (default info)
-q, --quiet The quiet mode allows for machine-parsable output, by printing only IDs
```

### SEE ALSO
Expand Down
3 changes: 2 additions & 1 deletion docs/cli/ignite_kernel_import.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ ignite kernel import <OCI image> [flags]
### Options inherited from parent commands

```
-q, --quiet The quiet mode allows for machine-parsable output, by printing only IDs
--log-level loglevel Specify the loglevel for the program (default info)
-q, --quiet The quiet mode allows for machine-parsable output, by printing only IDs
```

### SEE ALSO
Expand Down
3 changes: 2 additions & 1 deletion docs/cli/ignite_kernel_ls.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ ignite kernel ls [flags]
### Options inherited from parent commands

```
-q, --quiet The quiet mode allows for machine-parsable output, by printing only IDs
--log-level loglevel Specify the loglevel for the program (default info)
-q, --quiet The quiet mode allows for machine-parsable output, by printing only IDs
```

### SEE ALSO
Expand Down
Loading

0 comments on commit a6cfd52

Please sign in to comment.