<commit_before>package main

import (
	"fmt"
	"io/ioutil"
	"net/http"
	"os"

	"github.com/Sirupsen/logrus"
	"github.com/jessevdk/go-flags"
	"github.com/justone/pmb/api"
)

var opts struct {
	Verbose bool    `short:"v" long:"verbose" description:"Show verbose debug information."`
	Primary string  `short:"m" long:"pmb-uri" description:"Primary PMB URI."`
	Level   float64 `short:"l" long:"level" description:"Level at which to send notifications." default:"4"`
	Host    string  `short:"h" long:"host" description:"Host to listen on." default:"0.0.0.0"`
	Port    string  `short:"p" long:"port" description:"Port to listen on." default:"3000"`
}

func main() {

	_, err := flags.Parse(&opts)
	if err != nil {
		os.Exit(1)
	}

	bus := pmb.GetPMB(opts.Primary)
	id := pmb.GenerateRandomID("github")

	if opts.Verbose {
		logrus.SetLevel(logrus.DebugLevel)
	} else {
		logrus.SetLevel(logrus.InfoLevel)
	}
	logrus.SetFormatter(&logrus.TextFormatter{FullTimestamp: true})

	conn, err := bus.ConnectClient(id, false)
	if err != nil {
		logrus.Warnf("Error connecting to PMB: %s", err)
		os.Exit(1)
	}

	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		body, err := ioutil.ReadAll(r.Body)
		if err != nil {
			http.Error(w, "Unable to read request body: "+err.Error(), http.StatusInternalServerError)
			return
		}
		var eventName string
		if eventHeaders, ok := r.Header["X-Github-Event"]; ok {
			eventName = eventHeaders[0]
		} else {
			logrus.Warnf("Github event name not found")
			return
		}

		eventJSON := string(body)

		notification, err := parseEvent(eventName, eventJSON)
		if err != nil {
			logrus.Warnf("Unable to parse event %s: %s, body: %s", eventName, err, eventJSON)
			return
		}

		notification.Level = opts.Level

		go func() {
			pmb.SendNotification(conn, *notification)
		}()<commit_msg>adding more logging for requests<commit_after>package main

import (
	"fmt"
	"io/ioutil"
	"net/http"
	"os"
	"strings"

	"github.com/Sirupsen/logrus"
	"github.com/jessevdk/go-flags"
	"github.com/justone/pmb/api"
)

var opts struct {
	Verbose bool    `short:"v" long:"verbose" description:"Show verbose debug information."`
	Primary string  `short:"m" long:"pmb-uri" description:"Primary PMB URI."`
	Level   float64 `short:"l" long:"level" description:"Level at which to send notifications." default:"4"`
	Host    string  `short:"h" long:"host" description:"Host to listen on." default:"0.0.0.0"`
	Port    string  `short:"p" long:"port" description:"Port to listen on." default:"3000"`
}

func main() {

	_, err := flags.Parse(&opts)
	if err != nil {
		os.Exit(1)
	}

	bus := pmb.GetPMB(opts.Primary)
	id := pmb.GenerateRandomID("github")

	if opts.Verbose {
		logrus.SetLevel(logrus.DebugLevel)
	} else {
		logrus.SetLevel(logrus.InfoLevel)
	}
	logrus.SetFormatter(&logrus.TextFormatter{FullTimestamp: true})

	conn, err := bus.ConnectClient(id, false)
	if err != nil {
		logrus.Warnf("Error connecting to PMB: %s", err)
		os.Exit(1)
	}

	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		var ip string
		if realIP, ok := r.Header["X-Real-Ip"]; ok {
			ip = realIP[0]
		} else {
			ip = r.RemoteAddr
		}
		logrus.Infof(strings.Join([]string{r.RequestURI, ip, r.Method, fmt.Sprintf("%s", r.Header)}, " "))

		body, err := ioutil.ReadAll(r.Body)
		if err != nil {
			http.Error(w, "Unable to read request body: "+err.Error(), http.StatusInternalServerError)
			return
		}
		var eventName string
		if eventHeaders, ok := r.Header["X-Github-Event"]; ok {
			eventName = eventHeaders[0]
		} else {
			logrus.Warnf("Github event name not found")
			return
		}

		eventJSON := string(body)

		notification, err := parseEvent(eventName, eventJSON)
		if err != nil {
			logrus.Warnf("Unable to parse event %s: %s, body: %s", eventName, err, eventJSON)
			return
		}

		notification.Level = opts.Level

		logrus.Infof("Sending notification: %s", notification)
		go func() {
			pmb.SendNotification(conn, *notification)
		}()
{'fraction_non_alphanumeric': 0.15656565656565657, 'fraction_numerical': 0.0073232323232323236, 'mean_word_length': 4.026649746192893, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5534730', 'n_tokens_mistral': 1532, 'n_tokens_neox': 1418, 'n_words': 335}