k3s/pkg/cli/cmds/log.go

78 lines
1.5 KiB
Go
Raw Normal View History

2019-08-08 05:45:54 +00:00
package cmds
import (
"fmt"
"sync"
2019-08-08 05:45:54 +00:00
"time"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
2019-08-08 05:45:54 +00:00
)
type Log struct {
VLevel int
VModule string
LogFile string
AlsoLogToStderr bool
}
var (
LogConfig Log
VLevel = &cli.IntFlag{
2019-08-08 05:45:54 +00:00
Name: "v",
Usage: "(logging) Number for the log level verbosity",
2019-08-08 05:45:54 +00:00
Destination: &LogConfig.VLevel,
}
VModule = &cli.StringFlag{
2019-08-08 05:45:54 +00:00
Name: "vmodule",
Usage: "(logging) Comma-separated list of FILE_PATTERN=LOG_LEVEL settings for file-filtered logging",
2019-08-08 05:45:54 +00:00
Destination: &LogConfig.VModule,
}
LogFile = &cli.StringFlag{
2019-08-08 05:45:54 +00:00
Name: "log,l",
Usage: "(logging) Log to file",
2019-08-08 05:45:54 +00:00
Destination: &LogConfig.LogFile,
}
AlsoLogToStderr = &cli.BoolFlag{
2019-08-08 05:45:54 +00:00
Name: "alsologtostderr",
Usage: "(logging) Log to standard error as well as file (if set)",
2019-08-08 05:45:54 +00:00
Destination: &LogConfig.AlsoLogToStderr,
}
logSetupOnce sync.Once
2019-08-08 05:45:54 +00:00
)
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
2019-08-08 05:45:54 +00:00
}
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)
}
2019-08-08 05:45:54 +00:00
}