<commit_before>package tools

import (
	"log"
	"net/http"
)

type LogResponseWriter struct {
	ct     []byte
	status int
	w      http.ResponseWriter
}

type LogMux struct {
	mux    *http.ServeMux
	lw     *LogResponseWriter
	logger *log.Logger
}

func NewLogMux(fn, prefix string) *LogMux {
	lm := &LogMux{}
	lm.mux = http.NewServeMux()
	lm.lw = &LogResponseWriter{}
	lm.logger = InitLog(fn, prefix)
	return lm
}

// implement http.ResponseWriter

func (lw *LogResponseWriter) Header() http.Header {
	return lw.w.Header()
}

func (lw *LogResponseWriter) Write(bt []byte) (int, error) {
	lw.ct = bt
	return lw.w.Write(bt)
}

func (lw *LogResponseWriter) WriteHeader(statusCode int) {
	lw.status = statusCode
	lw.w.WriteHeader(statusCode)
}

// implement http.ResponseWriter end

func (l *LogMux) Handle(pattern string, handler func(http.ResponseWriter, *http.Request)) {
	l.mux.HandleFunc(pattern, handler)
}

func (l *LogMux) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	h, p := l.mux.Handler(r)
	l.lw.w = w
	h.ServeHTTP(l.lw, r)
	l.logger.Println(r.RequestURI, p, string(l.lw.ct))
}<commit_msg>add url instead of uri<commit_after>package tools

import (
	"log"
	"net/http"
)

type LogResponseWriter struct {
	ct     []byte
	status int
	w      http.ResponseWriter
}

type LogMux struct {
	mux    *http.ServeMux
	lw     *LogResponseWriter
	logger *log.Logger
}

func NewLogMux(fn, prefix string) *LogMux {
	lm := &LogMux{}
	lm.mux = http.NewServeMux()
	lm.lw = &LogResponseWriter{}
	lm.logger = InitLog(fn, prefix)
	return lm
}

// implement http.ResponseWriter

func (lw *LogResponseWriter) Header() http.Header {
	return lw.w.Header()
}

func (lw *LogResponseWriter) Write(bt []byte) (int, error) {
	lw.ct = bt
	return lw.w.Write(bt)
}

func (lw *LogResponseWriter) WriteHeader(statusCode int) {
	lw.status = statusCode
	lw.w.WriteHeader(statusCode)
}

// implement http.ResponseWriter end

func (l *LogMux) Handle(pattern string, handler func(http.ResponseWriter, *http.Request)) {
	l.mux.HandleFunc(pattern, handler)
}

func (l *LogMux) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	h, _ := l.mux.Handler(r)
	l.lw.w = w
	h.ServeHTTP(l.lw, r)
	if len(l.lw.ct) < 100 {
		l.logger.Println(r.URL.Path+r.URL.RawQuery, string(l.lw.ct))
	} else {
		l.logger.Println(r.URL.Path+r.URL.RawQuery, string(l.lw.ct[:100]))
	}
}
{'fraction_non_alphanumeric': 0.14383855732073852, 'fraction_numerical': 0.0025762129669386004, 'mean_word_length': 4.043290043290043, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '1123885', 'n_tokens_mistral': 948, 'n_tokens_neox': 937, 'n_words': 202}