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