forked from moredhel/env_logger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
no_pprof.go
36 lines (30 loc) · 869 Bytes
/
no_pprof.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//go:build !logpprof
// +build !logpprof
package env_logger
import (
"fmt"
"io/ioutil"
"net/http"
"strings"
)
func profileServer(port uint16) {
Warn("pprof server not included at compiletime")
// make dynamic config still work
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "")
})
http.HandleFunc("/logstring", func(w http.ResponseWriter, r *http.Request) {
// function to allow dynamicaly setting the logstring
body, err := ioutil.ReadAll(r.Body)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
fmt.Fprintf(w, "Error: "+err.Error())
return
}
debugConfig := strings.TrimSpace(string(body))
SetGlobalDebugConfig(debugConfig)
fmt.Fprintf(w, "New log config: %s", debugConfig)
})
Warnf("profileserver startet on port %d", port)
Error(http.ListenAndServe(fmt.Sprintf(":%d", port), nil))
}