Ejemplo n.º 1
0
func main() {
	rl := capnslog.MustRepoLogger("github.com/coreos/pkg/capnslog/cmd")
	capnslog.SetFormatter(capnslog.NewStringFormatter(os.Stderr))

	// We can parse the log level configs from the command line
	flag.Parse()
	if flag.NArg() > 1 {
		cfg, err := rl.ParseLogLevelConfig(flag.Arg(1))
		if err != nil {
			log.Fatal(err)
		}
		rl.SetLogLevel(cfg)
		log.Infof("Setting output to %s", flag.Arg(1))
	}

	// Send some messages at different levels to the different packages
	dlog.Infof("Hello Dolly")
	dlog.Warningf("Well hello, Dolly")
	log.Errorf("It's so nice to have you back where you belong")
	dlog.Debugf("You're looking swell, Dolly")
	dlog.Tracef("I can tell, Dolly")

	// We also have control over the built-in "log" package.
	capnslog.SetGlobalLogLevel(logLevel)
	oldlog.Println("You're still glowin', you're still crowin', you're still lookin' strong")
	log.Fatalf("Dolly'll never go away again")
}
Ejemplo n.º 2
0
func startLogging(cmd *cobra.Command) {
	switch {
	case logDebug:
		logLevel = capnslog.DEBUG
	case logVerbose:
		logLevel = capnslog.INFO
	}

	capnslog.SetFormatter(capnslog.NewStringFormatter(cmd.Out()))
	capnslog.SetGlobalLogLevel(logLevel)
	plog.Infof("Started logging at level %s", logLevel)
}
Ejemplo n.º 3
0
func main() {
	flag.Parse()
	capnslog.SetFormatter(capnslog.NewStringFormatter(os.Stderr))
	capnslog.SetGlobalLogLevel(capnslog.INFO)

	var l, n time.Time
	var err error
	if *now != "" {
		n, err = time.Parse(time.UnixDate, *now)
		if err != nil {
			plog.Fatalf("Parsing --now failed: %v", err)
		}
	}
	if *leap != "" {
		l, err = time.Parse(time.UnixDate, *leap)
		if err != nil {
			plog.Fatalf("Parsing --leap failed: %v", err)
		}
		if (l.Truncate(24*time.Hour) != l) || (l.UTC().Day() != 1) {
			plog.Fatalf("Invalid --leap time: %s", l)
		}
	}

	s, err := ntp.NewServer(":123")
	if err != nil {
		plog.Fatalf("Listen failed: %v", err)
	}

	if !n.IsZero() {
		s.SetTime(n)
	}
	if !l.IsZero() {
		s.SetLeapSecond(l, ntp.LEAP_ADD)
	}

	s.Serve()
}