summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorBen Morrison <ben@gbmor.dev>2019-05-31 04:29:11 -0400
committerBen Morrison <ben@gbmor.dev>2019-05-31 04:29:17 -0400
commit4fa97eec3910f22159e51c2742049a5769a8f0a0 (patch)
treee779be9d2ef3c71dbcbe00a24a7df9b9e7a50372
parentb961a7041ef6dbfd46371d0c626fd7d26b59c23d (diff)
downloadgetwtxt-4fa97eec3910f22159e51c2742049a5769a8f0a0.tar.gz
added user-agent to logging
-rw-r--r--http.go9
1 files changed, 6 insertions, 3 deletions
diff --git a/http.go b/http.go
index aaa3a2e..f4ba233 100644
--- a/http.go
+++ b/http.go
@@ -53,9 +53,10 @@ func ipMiddleware(hop http.Handler) http.Handler {
 }
 
 func log200(r *http.Request) {
+	useragent := r.Header["User-Agent"]
 
 	uip := getIPFromCtx(r.Context())
-	log.Printf("*** %v :: 200 :: %v %v\n", uip, r.Method, r.URL)
+	log.Printf("*** %v :: 200 :: %v %v :: %v\n", uip, r.Method, r.URL, useragent)
 }
 
 func log400(w http.ResponseWriter, r *http.Request, err string) {
@@ -65,15 +66,17 @@ func log400(w http.ResponseWriter, r *http.Request, err string) {
 }
 
 func log404(w http.ResponseWriter, r *http.Request, err error) {
+	useragent := r.Header["User-Agent"]
 
 	uip := getIPFromCtx(r.Context())
-	log.Printf("*** %v :: 404 :: %v %v :: %v\n", uip, r.Method, r.URL, err)
+	log.Printf("*** %v :: 404 :: %v %v :: %v :: %v\n", uip, r.Method, r.URL, useragent, err)
 	http.Error(w, err.Error(), http.StatusNotFound)
 }
 
 func log500(w http.ResponseWriter, r *http.Request, err error) {
+	useragent := r.Header["User-Agent"]
 
 	uip := getIPFromCtx(r.Context())
-	log.Printf("*** %v :: 500 :: %v %v :: %v\n", uip, r.Method, r.URL, err)
+	log.Printf("*** %v :: 500 :: %v %v :: %v :: %v\n", uip, r.Method, r.URL, useragent, err)
 	http.Error(w, err.Error(), http.StatusInternalServerError)
 }
d='n160' href='#n160'>160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271