Esempio n. 1
0
// SetLogLevel changes the log level of a specific subsystem
// name=="*" changes all subsystems
func SetLogLevel(name, level string) error {
	lvl, err := logrus.ParseLevel(level)
	if err != nil {
		return err
	}

	// wildcard, change all
	if name == "*" {
		SetAllLoggers(lvl)
		return nil
	}

	// Check if we have a logger by that name
	if _, ok := loggers[name]; !ok {
		return ErrNoSuchLogger
	}

	loggers[name].Level = lvl

	return nil
}
Esempio n. 2
0
// SetupLogging will initialize the logger backend and set the flags.
func SetupLogging() {

	format, ok := LogFormats[os.Getenv(envLoggingFmt)]
	if !ok {
		format = LogFormats[defaultLogFormat]
	}

	log.Out = os.Stderr
	log.Formatter = format

	lvl := logrus.ErrorLevel

	if logenv := os.Getenv(envLogging); logenv != "" {
		var err error
		lvl, err = logrus.ParseLevel(logenv)
		if err != nil {
			log.Debugf("logrus.ParseLevel() Error: %q", err)
			lvl = logrus.ErrorLevel // reset to ERROR, could be undefined now(?)
		}
	}

	SetAllLoggers(lvl)
}