mirror of
https://git.vectorsigma.ru/public/k3s.git
synced 2026-08-05 03:39:59 +00:00
Allow InitLogging to be called twice
This makes it a bit easier to embed k3s into another go program
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"io"
|
||||
"os"
|
||||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/pkg/reexec"
|
||||
@@ -43,19 +44,26 @@ var (
|
||||
Usage: "(logging) Log to standard error as well as file (if set)",
|
||||
Destination: &LogConfig.AlsoLogToStderr,
|
||||
}
|
||||
|
||||
logSetupOnce sync.Once
|
||||
)
|
||||
|
||||
func InitLogging() error {
|
||||
if LogConfig.LogFile != "" && os.Getenv("_K3S_LOG_REEXEC_") == "" {
|
||||
return runWithLogging()
|
||||
}
|
||||
var rErr error
|
||||
logSetupOnce.Do(func() {
|
||||
if LogConfig.LogFile != "" && os.Getenv("_K3S_LOG_REEXEC_") == "" {
|
||||
rErr = runWithLogging()
|
||||
return
|
||||
}
|
||||
|
||||
if err := checkUnixTimestamp(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := checkUnixTimestamp(); err != nil {
|
||||
rErr = err
|
||||
return
|
||||
}
|
||||
|
||||
setupLogging()
|
||||
return nil
|
||||
setupLogging()
|
||||
})
|
||||
return rErr
|
||||
}
|
||||
|
||||
func checkUnixTimestamp() error {
|
||||
|
||||
Reference in New Issue
Block a user