Esempio n. 1
0
func init() {
	var handler log.Handler
	if term.IsTty(os.Stdout.Fd()) {
		handler = log.StreamHandler(os.Stdout, log.TerminalFormat())
	} else {
		handler = log.StreamHandler(os.Stdout, log.JsonFormat())
	}
	log.Root().SetHandler(handler)
	ncr.Log.SetHandler(handler)
}
Esempio n. 2
0
func (w *Logged) HandlerFor(target, level, format string) (log.Handler, error) {
	lvl, err := log.LvlFromString(level)
	if err != nil {
		return nil, fmt.Errorf("Invalid log level: %v", err)
	}

	var logformat log.Format
	switch format {
	case "json":
		logformat = log.JsonFormat()
	case "logfmt":
		logformat = log.LogfmtFormat()
	case "terminal", "term":
		switch {
		case target == "stdout" && term.IsTty(os.Stdout.Fd()):
			logformat = log.TerminalFormat()
		case target == "stderr" && term.IsTty(os.Stderr.Fd()):
			logformat = log.TerminalFormat()
		default:
			logformat = log.LogfmtFormat()
		}
	default:
		return nil, fmt.Errorf("Invalid log format: %v", format)
	}

	var handler log.Handler
	switch target {
	case "stdout":
		handler = log.StreamHandler(colorable.NewColorableStdout(), logformat)
	case "stderr":
		handler = log.StreamHandler(colorable.NewColorableStderr(), logformat)
	case "false":
		handler = log.DiscardHandler()
	default:
		handler, err = log.FileHandler(target, logformat)
		if err != nil {
			return nil, fmt.Errorf("Failed to open log file '%s': %v", target, err)
		}
	}

	return log.LvlFilterHandler(lvl, handler), nil
}
Esempio n. 3
0
func InitLogger(slvl string) {
	if slvl == "" {
		slvl = "debug"
	}
	lvl, err := log.LvlFromString(slvl)
	if err != nil {
		panic(err)
	}
	Log.SetHandler(log.LvlFilterHandler(lvl, log.StreamHandler(os.Stdout, log.TerminalFormat())))
	return
}
Esempio n. 4
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)
}
Esempio n. 5
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)
}
Esempio n. 6
0
func New() *Engine {
	// package instance of the helios type
	engine := &Engine{
		HTTPEngine: gin.Default(),
		Socket:     initSocket(),
		Logger:     log.New(),
	}

	fileHandler, _ := log.FileHandler("./log.debug", log.LogfmtFormat())
	engine.SetHandler(log.MultiHandler(log.LvlFilterHandler(log.LvlWarn, fileHandler), log.StreamHandler(os.Stdout, log.TerminalFormat())))

	return engine
}
Esempio n. 7
0
func New() *Engine {
	// package instance of the helios type
	engine := &Engine{
		HTTPEngine: gin.Default(),
		Logger:     log.New(),
	}

	fileHandler, _ := log.FileHandler("./error.log", log.LogfmtFormat())
	engine.SetHandler(log.MultiHandler(log.LvlFilterHandler(log.LvlWarn, fileHandler), log.StreamHandler(os.Stdout, log.TerminalFormat())))

	socket, err := initSocket()
	if err != nil {
		engine.Error("Failed to initialize socket server")
	}

	// Handle error cases
	socket.On("error", func(so socketio.Socket, err error) {
		engine.Error("Error on socket.io server", "error", err.Error())
	})

	engine.Socket = socket

	return engine
}