Skip to content

Commit 4327c9a

Browse files
committed
logging(to stdout) added
1 parent cdbebba commit 4327c9a

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

app.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Contact: mkoptur3@gmail.com
55
*
6-
* Last edit: 3/30/19 10:21 PM
6+
* Last edit: 4/1/19 12:23 PM
77
*
88
* This program is free software: you can redistribute it and/or modify
99
* it under the terms of the GNU General Public License as published by
@@ -25,15 +25,18 @@ import (
2525
"database/sql"
2626
"encoding/json"
2727
_ "github.com/go-sql-driver/mysql"
28+
"github.com/gorilla/handlers"
2829
"github.com/gorilla/mux"
2930
"github.com/spf13/viper"
3031
"log"
3132
"net/http"
33+
"os"
3234
"strconv"
3335
)
3436

3537
type App struct {
3638
Router *mux.Router
39+
Logger http.Handler
3740
DB *sql.DB
3841
}
3942

@@ -159,9 +162,10 @@ func (a *App) Initialize(username, password, server, port, dbName string) {
159162
}
160163

161164
a.Router = mux.NewRouter()
165+
a.Logger = handlers.CombinedLoggingHandler(os.Stdout, a.Router)
162166
a.InitializeRoutes()
163167
}
164168

165169
func (a *App) Run(addr string) {
166-
log.Fatal(http.ListenAndServe(":"+viper.GetString("Server.port"), a.Router))
170+
log.Fatal(http.ListenAndServe(":"+viper.GetString("Server.port"), a.Logger))
167171
}

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ go 1.12
55
require (
66
github.com/BurntSushi/toml v0.3.1 // indirect
77
github.com/go-sql-driver/mysql v1.4.1
8+
github.com/gorilla/handlers v1.4.0
89
github.com/gorilla/mux v1.7.0
910
github.com/magiconair/properties v1.8.0
1011
github.com/spf13/viper v1.3.2

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMo
1111
github.com/go-sql-driver/mysql v1.4.1 h1:g24URVg0OFbNUTx9qqY1IRZ9D9z3iPyi5zKhQZpNwpA=
1212
github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
1313
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
14+
github.com/gorilla/handlers v1.4.0 h1:XulKRWSQK5uChr4pEgSE4Tc/OcmnU9GJuSwdog/tZsA=
15+
github.com/gorilla/handlers v1.4.0/go.mod h1:Qkdc/uu4tH4g6mTK6auzZ766c4CA0Ng8+o/OAirnOIQ=
1416
github.com/gorilla/mux v1.7.0 h1:tOSd0UKHQd6urX6ApfOn4XdBMY6Sh1MfxV3kmaazO+U=
1517
github.com/gorilla/mux v1.7.0/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
1618
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=

0 commit comments

Comments
 (0)