<commit_before>// Note: inspiration for this from https://gist.github.com/cespare/3985516

package common

import (
    "os"
    "io"
    "time"
    "strings"
    "strconv"
    "net/http"
)

const (
    logFile = "access_log.txt"
)

type accessLog struct {
    ip                    string
    time                  time.Time
    method, uri, protocol string
    status                int
    responseBytes         int64
    elapsedTime           time.Duration
}

func LogAccess(w http.ResponseWriter, req *http.Request, duration time.Duration) {
    clientIP := req.RemoteAddr

    if colon := strings.LastIndex(clientIP, ":"); colon != -1 {
        clientIP = clientIP[:colon]
    }

    record := &accessLog{
        ip:             clientIP,
        time:           time.Time{},
        method:         req.Method,
        uri:            req.RequestURI,
        protocol:       req.Proto,
        status:         http.StatusOK,
        elapsedTime:    duration,
    }

    writeAccessLog(record)
}

func writeAccessLog(record *accessLog) {
    logRecord := "["+record.time.Format("02/Jan/2006 03:04:05")+"] "+record.ip+" "+record.protocol+" "+record.method+": "+record.uri+" (load time: "+strconv.FormatFloat(record.elapsedTime.Seconds(), 'f', 5, 64)+" seconds)\n"

    file, err := os.OpenFile(logFile, os.O_APPEND|os.O_RDWR|os.O_CREATE, 0666)
    CheckError(err)
    io.WriteString(file, logRecord)
    file.Close()
}<commit_msg>Switched logging to glog<commit_after>// Note: inspiration for this from https://gist.github.com/cespare/3985516

package common

import (
    "time"
    "strings"
    "strconv"
    "net/http"

    "github.com/golang/glog"
)

const (
    logFile = "access_log.txt"
)

type accessLog struct {
    ip                    string
    time                  time.Time
    method, uri, protocol string
    status                int
    responseBytes         int64
    elapsedTime           time.Duration
}

func LogAccess(w http.ResponseWriter, req *http.Request, duration time.Duration) {
    clientIP := req.RemoteAddr

    if colon := strings.LastIndex(clientIP, ":"); colon != -1 {
        clientIP = clientIP[:colon]
    }

    record := &accessLog{
        ip:             clientIP,
        time:           time.Time{},
        method:         req.Method,
        uri:            req.RequestURI,
        protocol:       req.Proto,
        status:         http.StatusOK,
        elapsedTime:    duration,
    }

    writeAccessLog(record)
}

func writeAccessLog(record *accessLog) {
    logRecord := "["+record.time.Format("02/Jan/2006 03:04:05")+"] "+record.ip+" "+record.protocol+" "+record.method+": "+record.uri+" (load time: "+strconv.FormatFloat(record.elapsedTime.Seconds(), 'f', 5, 64)+" seconds)"
    glog.Infoln(logRecord)
}
{'fraction_non_alphanumeric': 0.12902059992771955, 'fraction_numerical': 0.019515720997470183, 'mean_word_length': 2.1347678369195924, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '4519035', 'n_tokens_mistral': 903, 'n_tokens_neox': 850, 'n_words': 184}