Beispiel #1
0
func Run() {
	defer func() {
		anaLog.Close()
		idl.Panic("shutdown")
	}()

	if config.AppLog.SlackLogUrl != "" {

		prio := priority.Warning
		if config.AnaLog.DevelopmentEnv {
			prio = priority.Debugging
		}

		idl.AddHook(&iDslackLog.SlackLogHook{
			AcceptedPriorities: priority.Threshold(prio),
			HookURL:            config.AppLog.SlackLogUrl,
			IconURL:            "",
			Channel:            "",
			IconEmoji:          "",
			Username:           "******",
		})
	}

	idl.StandardLogger().Async = true
	idl.SetPrefix("anaLog")
	idl.SetErrCallback(func(err error) {
		idl.StandardLogger().Async = true
		idl.Log(&idl.Event{
			idl.StandardLogger(),
			map[string]interface{}{
				"error": err,
			},
			time.Now(),
			priority.Emergency,
			"AppLogger caught an internal error",
		})
		panic("AppLogger caught an internal error")
	})

	if config.AnaLog.DevelopmentEnv {
		go scheduler.StartIn(1 * time.Second)
	} else {
		go scheduler.StartIn(10 * time.Second)
	}

	server.Listen()
}
Beispiel #2
0
func New() *Logger {
	var sf *StdFormatter
	stdOut := new(StdHook)
	stdErr := new(StdHook)

	stdOut.SetFormatter(sf)
	stdErr.SetFormatter(sf)

	stdOut.SetWriter(os.Stdout)
	stdErr.SetWriter(os.Stderr)

	stdOut.SetPriorities([]priority.Priority{
		priority.Debugging,
		priority.Informational,
		priority.Notice,
	})

	stdErr.SetPriorities(priority.Threshold(priority.Warning))

	log := &Logger{
		false,
		sync.RWMutex{},
		sync.WaitGroup{},
		"",
		0,
		nil,
		map[priority.Priority][]Hook{
			priority.Emergency:     []Hook{},
			priority.Alert:         []Hook{},
			priority.Critical:      []Hook{},
			priority.Error:         []Hook{},
			priority.Warning:       []Hook{},
			priority.Notice:        []Hook{},
			priority.Informational: []Hook{},
			priority.Debugging:     []Hook{},
		},
	}

	log.AddHook(stdOut)
	log.AddHook(stdErr)

	return log
}
Beispiel #3
0
// Prioritys sets which Prioritys to sent to slack
func (sh *SlackLogHook) Priorities() []priority.Priority {
	if sh.AcceptedPriorities == nil {
		return priority.Threshold(priority.Debugging)
	}
	return sh.AcceptedPriorities
}