properly set config logger
@@ -217,7 +217,7 @@ func New() *Config {
nil,
nil,
nil,
- log.New(ioutil.Discard, configLogPrefix, log.LstdFlags|log.Lmicroseconds),
+ log.New(ioutil.Discard, configLogPrefix, log.LstdFlags|log.Lmicroseconds|log.Lmsgprefix),
nil,
make(map[string]interface{}),
}
@@ -254,25 +254,30 @@ func (c *Config) Load() error {
return c.expandOSPathFlagValues()
}
-func (c *Config) SetLogger() {
+func (c *Config) SetLogger() (io.Writer, int, error) {
+ var f io.Writer = ioutil.Discard
+ var loggingFlags = c.logger.Flags()
+ var err error
+
if c.LogFile != "" {
- f, err := os.OpenFile(c.LogFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
+ f, err = os.OpenFile(c.LogFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
- return
+ return nil, 0, err
}
- c.logger.SetOutput(f)
} else {
if c.Debug {
c.Log = true
}
if c.Log {
- c.logger.SetOutput(os.Stderr)
+ f = os.Stderr
}
}
if c.Debug {
- loggingFlags := c.logger.Flags() | log.Llongfile
- c.logger.SetFlags(loggingFlags)
+ loggingFlags = loggingFlags | log.Llongfile
}
+ c.logger.SetOutput(f)
+ c.logger.SetFlags(loggingFlags)
+ return f, loggingFlags, nil
}
func (c *Config) SetPersistantFlagsFromFile(cmd *cobra.Command) {
@@ -913,14 +918,6 @@ func (c *Config) ValidateSetInput() error {
return nil
}
-func (c *Config) LogOutput() io.Writer {
- return c.logger.Writer()
-}
-
-func (c *Config) LogFlags() int {
- return c.logger.Flags()
-}
-
func ExpandOSPaths(paths []string) ([]string, error) {
var err error
for i := range paths {
