@@ -42,18 +42,6 @@ func rootCommand() *cobra.Command {
42
42
machines are controlled with libvirt, with qcow2 chained images for storage
43
43
and cloud-init for basic access configuration. This allows for fast cloning
44
44
and resetting, for a stable test environment.` ,
45
- PersistentPreRun : func (cmd * cobra.Command , args []string ) {
46
- level , err := log .ParseLevel (logLevel )
47
- if err != nil {
48
- log .Fatal (err )
49
- }
50
- log .SetLevel (level )
51
- if logFormat == "short" {
52
- shortFormatter := new (ShortFormatter )
53
- shortFormatter .LevelDesc = []string {"PANC" , "FATL" , "ERRO" , "WARN" , "INFO" , "DEBG" }
54
- log .SetFormatter (shortFormatter )
55
- }
56
- },
57
45
}
58
46
59
47
configName := filepath .Join (configPath (), "virter.toml" )
@@ -69,12 +57,25 @@ and resetting, for a stable test environment.`,
69
57
return rootCmd
70
58
}
71
59
60
+ func initLogging () {
61
+ level , err := log .ParseLevel (logLevel )
62
+ if err != nil {
63
+ log .Fatal (err )
64
+ }
65
+ log .SetLevel (level )
66
+ if logFormat == "short" {
67
+ shortFormatter := new (ShortFormatter )
68
+ shortFormatter .LevelDesc = []string {"PANC" , "FATL" , "ERRO" , "WARN" , "INFO" , "DEBG" }
69
+ log .SetFormatter (shortFormatter )
70
+ }
71
+ }
72
+
72
73
// Execute adds all child commands to the root command and sets flags appropriately
73
74
func Execute () {
74
75
ctx , cancel := signal .NotifyContext (context .Background (), syscall .SIGINT , syscall .SIGTERM )
75
76
defer cancel ()
76
77
77
- cobra .OnInitialize (initConfig , initSSHFromConfig )
78
+ cobra .OnInitialize (initLogging , initConfig , initSSHFromConfig )
78
79
79
80
if err := rootCommand ().ExecuteContext (ctx ); err != nil {
80
81
log .Fatal (err )
0 commit comments