mirror of
https://github.com/simon987/task_tracker.git
synced 2025-04-16 08:56:45 +00:00
Logging config
This commit is contained in:
parent
ef333b6b25
commit
0346dd8b6b
@ -4,6 +4,7 @@ import (
|
||||
"errors"
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/valyala/fasthttp"
|
||||
"src/task_tracker/config"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -33,7 +34,7 @@ func LogRequest(h RequestHandler) fasthttp.RequestHandler {
|
||||
}
|
||||
|
||||
func SetupLogger() {
|
||||
logrus.SetLevel(logrus.TraceLevel) //todo: from conf
|
||||
logrus.SetLevel(config.Cfg.LogLevel)
|
||||
}
|
||||
|
||||
func parseLogEntry(r *Request) *LogEntry {
|
||||
@ -88,4 +89,3 @@ func LogError(r *Request) {
|
||||
"scope": entry.Scope,
|
||||
}).WithTime(entry.Time()).Error(entry.Message)
|
||||
}
|
||||
|
||||
|
@ -6,5 +6,11 @@ database:
|
||||
|
||||
git:
|
||||
webhook_secret: "very_secret_secret"
|
||||
# Github: sha1, Gogs: sha256
|
||||
webhook_hash: "sha1"
|
||||
# Github: 'X-Hub-Signature', Gogs: 'X-Gogs-Signature'
|
||||
webhook_sig_header: "X-Hub-Signature"
|
||||
|
||||
log:
|
||||
# panic, fatal, error, warn, info, debug, trace
|
||||
level: "trace"
|
||||
|
@ -1,6 +1,7 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
@ -10,6 +11,7 @@ var Cfg struct {
|
||||
WebHookSecret []byte
|
||||
WebHookHash string
|
||||
WebHookSigHeader string
|
||||
LogLevel logrus.Level
|
||||
}
|
||||
|
||||
func SetupConfig() {
|
||||
@ -27,4 +29,5 @@ func SetupConfig() {
|
||||
Cfg.WebHookSecret = []byte(viper.GetString("git.webhook_secret"))
|
||||
Cfg.WebHookHash = viper.GetString("git.webhook_hash")
|
||||
Cfg.WebHookSigHeader = viper.GetString("git.webhook_sig_header")
|
||||
Cfg.LogLevel, _ = logrus.ParseLevel(viper.GetString("log.level"))
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ import (
|
||||
"crypto"
|
||||
"crypto/hmac"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"src/task_tracker/api"
|
||||
"src/task_tracker/config"
|
||||
@ -16,8 +15,6 @@ func TestWebHookNoSignature(t *testing.T) {
|
||||
|
||||
r := Post("/git/receivehook", api.GitPayload{})
|
||||
|
||||
fmt.Println(r.StatusCode)
|
||||
|
||||
if r.StatusCode != 403 {
|
||||
t.Error()
|
||||
}
|
||||
@ -31,8 +28,6 @@ func TestWebHookInvalidSignature(t *testing.T) {
|
||||
client := http.Client{}
|
||||
r, _ := client.Do(req)
|
||||
|
||||
fmt.Println(r.StatusCode)
|
||||
|
||||
if r.StatusCode != 403 {
|
||||
t.Error()
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package test
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
@ -15,7 +14,7 @@ func Post(path string, x interface{}) *http.Response {
|
||||
body, err := json.Marshal(x)
|
||||
buf := bytes.NewBuffer(body)
|
||||
|
||||
r, err := http.Post("http://" + config.Cfg.ServerAddr + path, "application/json", buf)
|
||||
r, err := http.Post("http://"+config.Cfg.ServerAddr+path, "application/json", buf)
|
||||
handleErr(err)
|
||||
|
||||
return r
|
||||
@ -28,18 +27,12 @@ func Get(path string) *http.Response {
|
||||
return r
|
||||
}
|
||||
|
||||
|
||||
func handleErr(err error) {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func Print(body io.ReadCloser) {
|
||||
rawBody, _ := ioutil.ReadAll(body)
|
||||
fmt.Println(string(rawBody))
|
||||
}
|
||||
|
||||
func GenericJson(body io.ReadCloser) map[string]interface{} {
|
||||
|
||||
var obj map[string]interface{}
|
||||
@ -50,4 +43,4 @@ func GenericJson(body io.ReadCloser) map[string]interface{} {
|
||||
handleErr(err)
|
||||
|
||||
return obj
|
||||
}
|
||||
}
|
||||
|
@ -2,9 +2,12 @@ server:
|
||||
address: "127.0.0.1:5001"
|
||||
|
||||
database:
|
||||
conn_str : "user=task_tracker dbname=task_tracker_test sslmode=disable"
|
||||
conn_str: "user=task_tracker dbname=task_tracker_test sslmode=disable"
|
||||
|
||||
git:
|
||||
webhook_secret: "very_secret_secret"
|
||||
webhook_hash: "sha1"
|
||||
webhook_sig_header: "X-Hub-Signature"
|
||||
|
||||
log:
|
||||
level: "trace"
|
Loading…
x
Reference in New Issue
Block a user