add ability to log to file, update to v2.28.1 and fix 'first upgrade' issue
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package logging
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@@ -10,3 +13,33 @@ func init() {
|
||||
Log.SetLevel(logrus.InfoLevel)
|
||||
Log.SetFormatter(&logrus.TextFormatter{})
|
||||
}
|
||||
|
||||
func SetupLogging(verboseLevel int, logFilePath string) {
|
||||
switch verboseLevel {
|
||||
case 1:
|
||||
Log.SetLevel(logrus.DebugLevel)
|
||||
case 2:
|
||||
Log.SetLevel(logrus.TraceLevel)
|
||||
default:
|
||||
if verboseLevel >= 3 {
|
||||
Log.SetLevel(logrus.TraceLevel)
|
||||
}
|
||||
}
|
||||
|
||||
if logFilePath != "" {
|
||||
logFile, err := os.OpenFile(logFilePath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
|
||||
if err != nil {
|
||||
Log.Warnf("Failed to open log file %s: %v. Continuing without file logging.", logFilePath, err)
|
||||
return
|
||||
}
|
||||
|
||||
if verboseLevel > 0 {
|
||||
multiWriter := io.MultiWriter(os.Stdout, logFile)
|
||||
Log.SetOutput(multiWriter)
|
||||
Log.Debugf("Verbose logging enabled with file output (level: %d)", verboseLevel)
|
||||
} else {
|
||||
Log.SetOutput(logFile)
|
||||
}
|
||||
Log.Infof("Logging to file: %s", logFilePath)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user