I have a SaveRequest method that takes and http.Request
and then, supposedly, saves it (right now just the path) to a postgres database:
func (logger *PostgresLogger) SaveRequest(req *http.Request) {
os.Stdout.Write([]byte("Saving to PGDB
"))
request := db.Requests { Path: req.URL.Path }
transaction := logger.dbConnection.Begin()
Id, saveError := transaction.Save(&request)
if saveError != nil {
panic(saveError)
}
os.Stdout.Write([]byte(fmt.Sprintf("%v
", Id)))
transactionError := logger.dbConnection.Commit()
if transactionError != nil {
panic(transactionError)
}
}
That dbConnection
comes from loading a Hood config file:
func New(prefix string) (PostgresLogger) {
dbConnection, err := hood.Load("/Users/ls/Dropbox/programming/go/src/postgres_logger/db/config.json", "development")
if err != nil {
panic(err)
}
return PostgresLogger{ prefix: prefix, dbConnection: dbConnection }
}
Cool. So when I start the reverse proxy and ask it to save incoming requests, I see this (sample, where logs are prefixed by RVSPRXY):
Saving to PGDB
56
RVSPRXY (1368315177148901322):
[::1]:51142 GET /css/editor.css
Saving to PGDB
RVSPRXY (1368315177149851787):
[::1]:51143 GET /js/handlebars.min.js
Saving to PGDB
RVSPRXY (1368315177150164615):
[::1]:51140 GET /css/mercury.bundle.css
Saving to PGDB
RVSPRXY (1368315177150358938):
[::1]:51141 GET /css/mercury_regions.bundle.css
Saving to PGDB
RVSPRXY (1368315177150776986):
[::1]:51144 GET /js/jquery-2.0.0.min.js
Saving to PGDB
57
58
59
60
So we can see it incrementing the id being returned from Save, but I look in the logging_development database and there are no records.
Stopping and restarting the server continues to increment the ids from where it left off, so it seems like it is actually saving, but where?
Update
Here is the development config:
{
"development": {
"driver": "postgres",
"source": "user=logging dbname=logging_development sslmode=disable"
}
}
And some of what PGAdmin shows for connections:
5289 logging logging_development 2013-05-11 17:54:48.700467-06 127.0.0.1:51403 INSERT INTO "requests" ("path", "created_at", "updated_at") VALUES ($1, $2, $3) RETURNING "id"
5290 logging logging_development 2013-05-11 17:54:48.746065-06 127.0.0.1:51414 INSERT INTO "requests" ("path", "created_at", "updated_at") VALUES ($1, $2, $3) RETURNING "id"
5291 logging logging_development 2013-05-11 17:54:48.747876-06 127.0.0.1:51415 INSERT INTO "requests" ("path", "created_at", "updated_at") VALUES ($1, $2, $3) RETURNING "id"
5292 logging logging_development 2013-05-11 17:54:48.748086-06 127.0.0.1:51416 INSERT INTO "requests" ("path", "created_at", "updated_at") VALUES ($1, $2, $3) RETURNING "id"
5293 logging logging_development 2013-05-11 17:54:48.74866-06
Edit: fixed a bug checking the wrong error (not the cause of the issue)