mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-04 20:49:06 +02:00
Refactor log disable check
This commit is contained in:
+13
-15
@@ -60,15 +60,7 @@ func InitLogger(logger *log.Logger, logLevel string, logs ...string) error {
|
|||||||
case "":
|
case "":
|
||||||
logger.Warnf("empty log path received: %#v", logPath)
|
logger.Warnf("empty log path received: %#v", logPath)
|
||||||
default:
|
default:
|
||||||
conflict, configPath := FindFirstLogrotateConflict()
|
writer, err := setupLogFile(logPath, isRotationDisabled(logger))
|
||||||
if conflict {
|
|
||||||
logger.Warnf("log rotation conflict detected in: %#v, rotation is disabled", configPath)
|
|
||||||
}
|
|
||||||
rotationDisabled := isRotationDisabled()
|
|
||||||
if rotationDisabled {
|
|
||||||
logger.Warn("log rotation is disabled by env flag")
|
|
||||||
}
|
|
||||||
writer, err := setupLogFile(logPath, conflict || rotationDisabled)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Errorf("failed setting up log file: %s, %s", logPath, err)
|
logger.Errorf("failed setting up log file: %s, %s", logPath, err)
|
||||||
return err
|
return err
|
||||||
@@ -108,13 +100,19 @@ func FindFirstLogPath(logs []string) string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func isRotationDisabled() bool {
|
func isRotationDisabled(logger *log.Logger) bool {
|
||||||
v, ok := os.LookupEnv("NB_LOG_DISABLE_ROTATION")
|
v, _ := os.LookupEnv("NB_LOG_DISABLE_ROTATION")
|
||||||
if !ok {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
disabled, _ := strconv.ParseBool(v)
|
disabled, _ := strconv.ParseBool(v)
|
||||||
return disabled
|
if disabled {
|
||||||
|
logger.Warnf("log rotation is disabled by env flag")
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
conflict, configPath := FindFirstLogrotateConflict()
|
||||||
|
if conflict {
|
||||||
|
logger.Warnf("log rotation conflict detected in: %#v, rotation is disabled", configPath)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupLogFile(logPath string, disableRotation bool) (io.Writer, error) {
|
func setupLogFile(logPath string, disableRotation bool) (io.Writer, error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user