예제 #1
0
파일: oldlog.go 프로젝트: tilgovi/go-libp2p
// SetLogLevel changes the log level of a specific subsystem
// name=="*" changes all subsystems
func SetLogLevel(name, level string) error {
	lvl, err := logging.LogLevel(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
	}

	logging.SetLevel(lvl, name)

	return nil
}
예제 #2
0
파일: oldlog.go 프로젝트: tilgovi/go-libp2p
// SetAllLoggers changes the logging.Level of all loggers to lvl
func SetAllLoggers(lvl logging.Level) {
	logging.SetLevel(lvl, "")
	for n := range loggers {
		logging.SetLevel(lvl, n)
	}
}
예제 #3
0
파일: option.go 프로젝트: tilgovi/go-libp2p
	logging.SetFormatter(&PoliteJSONFormatter{})
}

// TextFormatter Option formats the event log as human-readable plain-text
var TextFormatter = func() {
	logging.SetFormatter(logging.DefaultFormatter)
}

func Output(w io.Writer) Option {
	return func() {
		backend := logging.NewLogBackend(w, "", 0)
		logging.SetBackend(backend)
		// TODO return previous Output option
	}
}

// LevelDebug Option sets the log level to debug
var LevelDebug = func() {
	logging.SetLevel(logging.DEBUG, "")
}

// LevelError Option sets the log level to error
var LevelError = func() {
	logging.SetLevel(logging.ERROR, "")
}

// LevelInfo Option sets the log level to info
var LevelInfo = func() {
	logging.SetLevel(logging.INFO, "")
}