Esempio n. 1
0
// LoadOptions overwrites the existing server options
func LoadOptions(ops Options) {
	options = ops

	// Set verbosity
	glog.SetVerbosity(options.Verbosity)

	// Check option boundaries
	if options.ESStartupTimeout < minTimeout {
		glog.V(0).Infof("overriding elastic search startup timeout with minimum %d", minTimeout)
		options.ESStartupTimeout = minTimeout
	}
}
Esempio n. 2
0
func setLogging(ctx *cli.Context) error {

	if ctx.GlobalBool("master") || ctx.GlobalBool("agent") {
		hostname, err := os.Hostname()
		if err != nil {
			hostname = "unknown"
		}
		glog.SetLogstashType("serviced-" + hostname)
	}

	if ctx.IsSet("logtostderr") {
		glog.SetToStderr(ctx.GlobalBool("logtostderr"))
	}

	if ctx.IsSet("alsologtostderr") {
		glog.SetAlsoToStderr(ctx.GlobalBool("alsologtostderr"))
	}

	glog.SetLogstashURL(ctx.GlobalString("logstashurl"))

	if ctx.IsSet("v") {
		glog.SetVerbosity(ctx.GlobalInt("v"))
	}

	if ctx.IsSet("stderrthreshold") {
		if err := glog.SetStderrThreshold(ctx.GlobalString("stderrthreshold")); err != nil {
			return err
		}
	}

	if ctx.IsSet("vmodule") {
		if err := glog.SetVModule(ctx.GlobalString("vmodule")); err != nil {
			return err
		}
	}

	if ctx.IsSet("log_backtrace_at") {
		if err := glog.SetTraceLocation(ctx.GlobalString("log_backtrace_at")); err != nil {
			return err
		}
	}

	// Listen for SIGUSR1 and, when received, toggle the log level between
	// 0 and 2.  If the log level is anything but 0, we set it to 0, and on
	// subsequent signals, set it to 2.
	go func() {
		signalChan := make(chan os.Signal, 1)
		signal.Notify(signalChan, syscall.SIGUSR1)
		for {
			<-signalChan
			glog.Infof("Received signal SIGUSR1")
			if glog.GetVerbosity() == 0 {
				glog.SetVerbosity(2)
			} else {
				glog.SetVerbosity(0)
			}
			glog.Infof("Log level changed to %v", glog.GetVerbosity())
		}
	}()

	return nil
}