Example #1
0
func ConfigureRootLogger() {
	sh := log.StreamHandler(colorable.NewColorableStdout(), log.TerminalFormat())

	logLevel := log.LvlInfo

	if showDebug == true {
		logLevel = log.LvlDebug
	} else {
		_, found := os.LookupEnv("DEBUG")
		if found == true {
			logLevel = log.LvlDebug
		}
	}

	fh := log.LvlFilterHandler(logLevel, sh)
	cfh := log.CallerFileHandler(fh)
	log.Root().SetHandler(cfh)
}
Example #2
0
func setSettings(level int, filename string) {
	logFilename = filename
	debug = level

	filehandler := log.Must.FileHandler(filename, log.LogfmtFormat())
	handler := log.MultiHandler(
		filehandler,
		log.StreamHandler(os.Stderr, log.TerminalFormat()))
	if debug > 1 {
		handler = log.CallerStackHandler("%+v", handler)
	} else {
		handler = log.CallerFileHandler(handler)
	}
	if debug < 1 {
		handler = log.LvlFilterHandler(log.LvlInfo, handler)
	}
	log.Root().SetHandler(handler)
	log.Info("Logging started", "level", debug, "log_file", logFilename)
}