Skip to content

Commit c9de41a

Browse files
jsilvelamnencia
andauthored
fix(logging): inject the logger into the Command context (#158)
Signed-off-by: Jaime Silvela <jaime.silvela@enterprisedb.com> Signed-off-by: Marco Nenciarini <marco.nenciarini@enterprisedb.com> Co-authored-by: Marco Nenciarini <marco.nenciarini@enterprisedb.com>
1 parent c80aa76 commit c9de41a

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

main.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ import (
1212
)
1313

1414
func main() {
15+
cobra.EnableTraverseRunHooks = true
16+
1517
logFlags := &log.Flags{}
1618
rootCmd := &cobra.Command{
1719
Use: "cnpg-i-hello-world",
1820
Short: "A plugin example",
19-
PersistentPreRunE: func(_ *cobra.Command, _ []string) error {
21+
PersistentPreRun: func(cmd *cobra.Command, _ []string) {
2022
logFlags.ConfigureLogging()
21-
return nil
23+
cmd.SetContext(log.IntoContext(cmd.Context(), log.GetLogger()))
2224
},
2325
}
2426

0 commit comments

Comments
 (0)