package graylog
import (
	"encoding/json"
	"github.com/robertkowalski/graylog-golang"
)
var grayLog  *gelf.Gelf

func init() {
	grayLog = gelf.New(gelf.Config{
		GraylogPort:     62001,
		GraylogHostname: "172.18.138.7",
		Connection:      "wan",
		MaxChunkSizeWan: 42,
		MaxChunkSizeLan: 1337,
	})
}

func Log(log interface{}) {
	logStr, _ := json.Marshal(log)
	grayLog.Log(string(logStr))
}

func LogApi(shortMsg string, desc string, extraDesc string, reqSource string) {
	grayLogData := struct {
		ShortMessage string `json:"short_message"`
		ReqSource string `json:"req_source"`
		AdsDetail string `json:"ads_detail"`
		AdsExtraDetail string `json:"ads_extra_detail"`
	}{
		ShortMessage: shortMsg,
		ReqSource:    reqSource,
		AdsDetail: desc,
		AdsExtraDetail: extraDesc,
	}
	Log(grayLogData)
}
