fix --log-* flags
Have each command create their own logger rather than using the one from `cmd.Context()`. This is because that one gets created "too early" when `--log-*` flags have not been parsed yet. Fixes #181 Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
parent
53e98e8ef5
commit
ad0fcfffeb
@ -3,9 +3,9 @@ package cmd
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"dagger.io/go/cmd/dagger/logger"
|
||||||
"dagger.io/go/dagger"
|
"dagger.io/go/dagger"
|
||||||
|
|
||||||
"github.com/rs/zerolog/log"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
@ -27,8 +27,8 @@ var computeCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
ctx := cmd.Context()
|
lg := logger.New()
|
||||||
lg := log.Ctx(ctx)
|
ctx := lg.WithContext(cmd.Context())
|
||||||
|
|
||||||
env, err := dagger.NewEnv()
|
env, err := dagger.NewEnv()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -44,9 +44,10 @@ func init() {
|
|||||||
|
|
||||||
func Execute() {
|
func Execute() {
|
||||||
var (
|
var (
|
||||||
|
ctx = appcontext.Context()
|
||||||
|
// `--log-*` flags have not been parsed yet at this point so we get a
|
||||||
|
// default logger. Therefore, we can't store the logger into the context.
|
||||||
lg = logger.New()
|
lg = logger.New()
|
||||||
ctx = lg.WithContext(appcontext.Context())
|
|
||||||
|
|
||||||
closer = logger.InitTracing()
|
closer = logger.InitTracing()
|
||||||
span opentracing.Span
|
span opentracing.Span
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user