mirror of https://github.com/k3s-io/k3s
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
1.5 KiB
78 lines
1.5 KiB
package cmds
|
|
|
|
import (
|
|
"fmt"
|
|
"sync"
|
|
"time"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
"github.com/urfave/cli"
|
|
)
|
|
|
|
type Log struct {
|
|
VLevel int
|
|
VModule string
|
|
LogFile string
|
|
AlsoLogToStderr bool
|
|
}
|
|
|
|
var (
|
|
LogConfig Log
|
|
|
|
VLevel = &cli.IntFlag{
|
|
Name: "v",
|
|
Usage: "(logging) Number for the log level verbosity",
|
|
Destination: &LogConfig.VLevel,
|
|
}
|
|
VModule = &cli.StringFlag{
|
|
Name: "vmodule",
|
|
Usage: "(logging) Comma-separated list of FILE_PATTERN=LOG_LEVEL settings for file-filtered logging",
|
|
Destination: &LogConfig.VModule,
|
|
}
|
|
LogFile = &cli.StringFlag{
|
|
Name: "log,l",
|
|
Usage: "(logging) Log to file",
|
|
Destination: &LogConfig.LogFile,
|
|
}
|
|
AlsoLogToStderr = &cli.BoolFlag{
|
|
Name: "alsologtostderr",
|
|
Usage: "(logging) Log to standard error as well as file (if set)",
|
|
Destination: &LogConfig.AlsoLogToStderr,
|
|
}
|
|
|
|
logSetupOnce sync.Once
|
|
)
|
|
|
|
func InitLogging() error {
|
|
var rErr error
|
|
logSetupOnce.Do(func() {
|
|
if err := forkIfLoggingOrReaping(); err != nil {
|
|
rErr = err
|
|
return
|
|
}
|
|
|
|
if err := checkUnixTimestamp(); err != nil {
|
|
rErr = err
|
|
return
|
|
}
|
|
|
|
setupLogging()
|
|
})
|
|
return rErr
|
|
}
|
|
|
|
func checkUnixTimestamp() error {
|
|
timeNow := time.Now()
|
|
// check if time before 01/01/1980
|
|
if timeNow.Before(time.Unix(315532800, 0)) {
|
|
return fmt.Errorf("server time isn't set properly: %v", timeNow)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func setupLogging() {
|
|
if Debug {
|
|
logrus.SetLevel(logrus.DebugLevel)
|
|
}
|
|
}
|