logs

package
v1.2.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 25, 2022 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var LOGS = func(h http.Handler) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		if utils.StringContains(r.URL.Path, "metrics", "sw.js", "favicon", "/static/", "/sse/", "/ws/", "/wss/") {
			h.ServeHTTP(w, r)
			return
		}

		for _, header := range r.Header["Upgrade"] {
			if header == "websocket" {

				h.ServeHTTP(w, r)
				return
			}
		}
		recorder := &StatusRecorder{
			ResponseWriter: w,
			Status:         200,
		}
		t := time.Now()
		h.ServeHTTP(recorder, r)
		res := fmt.Sprintf("[%s] --> '%s' --> [%d]  from: %s ---------- Took: %v", r.Method, r.URL.Path, recorder.Status, r.RemoteAddr, time.Since(t))

		if recorder.Status >= 200 && recorder.Status < 400 {
			fmt.Printf(logger.Green, res)
		} else if recorder.Status >= 400 || recorder.Status < 200 {
			fmt.Printf(logger.Red, res)
		} else {
			fmt.Printf(logger.Yellow, res)
		}
		if settings.Config.Logs {
			logger.StreamLogs = append(logger.StreamLogs, res)
			eventbus.Publish("internal-logs", map[string]string{})
		}
	})
}

Functions

This section is empty.

Types

type StatusRecorder

type StatusRecorder struct {
	http.ResponseWriter
	Status int
}

func (*StatusRecorder) Flush added in v1.0.62

func (r *StatusRecorder) Flush()

func (*StatusRecorder) Hijack added in v1.0.62

func (r *StatusRecorder) Hijack() (net.Conn, *bufio.ReadWriter, error)

func (*StatusRecorder) WriteHeader

func (r *StatusRecorder) WriteHeader(status int)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL