mirror of
https://github.com/mpolden/echoip.git
synced 2024-11-10 07:27:22 +01:00
http: Log server errors
This commit is contained in:
parent
0d3594284e
commit
a4808f1fa4
@ -29,6 +29,11 @@ func (f *multiValueFlag) Set(v string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
log.SetPrefix("echoip: ")
|
||||
log.SetFlags(log.Lshortfile)
|
||||
}
|
||||
|
||||
func main() {
|
||||
countryFile := flag.String("f", "", "Path to GeoIP country database")
|
||||
cityFile := flag.String("c", "", "Path to GeoIP city database")
|
||||
@ -47,7 +52,6 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
log := log.New(os.Stderr, "echoip: ", 0)
|
||||
r, err := geo.Open(*countryFile, *cityFile, *asnFile)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"html/template"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
@ -383,6 +384,9 @@ func wrapHandlerFunc(f http.HandlerFunc) appHandler {
|
||||
func (fn appHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
if e := fn(w, r); e != nil { // e is *appError
|
||||
// When Content-Type for error is JSON, we need to marshal the response into JSON
|
||||
if e.Code/100 == 5 {
|
||||
log.Println(e.Error)
|
||||
}
|
||||
if e.IsJSON() {
|
||||
var data = struct {
|
||||
Error string `json:"error"`
|
||||
|
Loading…
Reference in New Issue
Block a user