mirror of
https://github.com/k3s-io/k3s.git
synced 2024-06-07 19:41:36 +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:
parent
0efe2af1a7
commit
8cc9efdf7c
@ -6,6 +6,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/docker/docker/pkg/reexec"
|
"github.com/docker/docker/pkg/reexec"
|
||||||
@ -43,19 +44,26 @@ var (
|
|||||||
Usage: "(logging) Log to standard error as well as file (if set)",
|
Usage: "(logging) Log to standard error as well as file (if set)",
|
||||||
Destination: &LogConfig.AlsoLogToStderr,
|
Destination: &LogConfig.AlsoLogToStderr,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logSetupOnce sync.Once
|
||||||
)
|
)
|
||||||
|
|
||||||
func InitLogging() error {
|
func InitLogging() error {
|
||||||
if LogConfig.LogFile != "" && os.Getenv("_K3S_LOG_REEXEC_") == "" {
|
var rErr error
|
||||||
return runWithLogging()
|
logSetupOnce.Do(func() {
|
||||||
}
|
if LogConfig.LogFile != "" && os.Getenv("_K3S_LOG_REEXEC_") == "" {
|
||||||
|
rErr = runWithLogging()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if err := checkUnixTimestamp(); err != nil {
|
if err := checkUnixTimestamp(); err != nil {
|
||||||
return err
|
rErr = err
|
||||||
}
|
return
|
||||||
|
}
|
||||||
|
|
||||||
setupLogging()
|
setupLogging()
|
||||||
return nil
|
})
|
||||||
|
return rErr
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkUnixTimestamp() error {
|
func checkUnixTimestamp() error {
|
||||||
|
Loading…
Reference in New Issue
Block a user