Пример #1
0
func apiError(w rest.ResponseWriter, error string, code int) {
	w.WriteHeader(code)
	if lg.V(5) {
		lg.InfoDepth(1, fmt.Sprintf("%d: %s", code, error))
	}
	err := w.WriteJson(map[string]string{
		"Error": error,
		"Ok":    "false",
	})
	if err != nil {
		panic(err)
	}
}
Пример #2
0
// MiddlewareFunc makes AccessLogApacheMiddleware implement the Middleware interface.
func (mw *AccessLogApacheMiddleware) MiddlewareFunc(h rest.HandlerFunc) rest.HandlerFunc {

	// set default format
	if mw.Format == "" {
		mw.Format = DefaultLogFormat
	}

	mw.convertFormat()

	return func(w rest.ResponseWriter, r *rest.Request) {

		// call the handler
		h(w, r)

		util := &accessLogUtil{w, r}
		msg := mw.executeTextTemplate(util)
		lg.InfoDepth(0, msg)

	}
}
Пример #3
0
// Write delegates write to everything that is persisted below this level.
func Write() error {
	if lg.V(15) {
		lg.InfoDepth(1, "called config write")
	}

	currentConrfigMu.RLock()
	defer currentConrfigMu.RUnlock()

	filename := ConfigPath("settings.json")
	lg.V(5).Infoln("Saving settings file")
	data, err := json.MarshalIndent(&currentConfig.Settings, "", "  ")
	if err != nil {
		return err
	}
	err = ioutil.WriteFile(filename, data, 0644)
	if err != nil {
		return err
	}
	return nil

}
Пример #4
0
func logSQLErr(err error, query squirrel.Sqlizer) {
	if err != nil {
		if lg.V(10) {
			sql, args, qerr := query.ToSql()
			var msg string
			if qerr != nil {
				msg = fmt.Sprintf("sql error: %s", err)
			} else {
				msg = fmt.Sprintf("sql error: %s: %+v, %s", sql, args, err)
			}
			lg.ErrorDepth(1, msg)
		} else {
			lg.ErrorDepth(1, "sql error: %s", err.Error())
		}
	} else if lg.V(19) {
		sql, _, qerr := query.ToSql()
		if qerr != nil {
			lg.ErrorDepth(1, fmt.Sprintf("sql error: %s", err))

		}
		lg.InfoDepth(1, fmt.Sprintf("sql query: %s", sql))
	}
}