我有一個SaveRequest方法,它和http.Request
然後,據說,將其保存(現在只是路徑)的Postgres數據庫:轉到胡德保存到Postgres的,但不知道在哪裏
func (logger *PostgresLogger) SaveRequest(req *http.Request) {
os.Stdout.Write([]byte("Saving to PGDB\n"))
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\n", Id)))
transactionError := logger.dbConnection.Commit()
if transactionError != nil {
panic(transactionError)
}
}
這dbConnection
來自加載Hood配置文件:
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 }
}
很酷。所以,當我開始反向代理,並要求它保存傳入的請求,我看到這(樣品中,其中日誌由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
所以我們可以看到它遞增ID從保存返回,但我查看了logging_development數據庫,並沒有記錄。
停止並重新啓動服務器會繼續增加它停止的位置的ID,所以它看起來好像實際上正在保存,但在哪裏?
更新
這裏是開發配置:
{
"development": {
"driver": "postgres",
"source": "user=logging dbname=logging_development sslmode=disable"
}
}
有些什麼樣的pgAdmin顯示連接:
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
編輯:修正了檢查不正確的錯誤(不是問題的原因)
1)應該在哪裏數據根據config.json去? 2)可以使用pgadmin來檢查客戶端連接的數據庫以及他們實際執行的查詢。 – fvu 2013-05-11 23:52:04
我添加了配置文件。它應該去logging_development,並且服務器的統計數據似乎表明這是事實。 – Chris 2013-05-12 00:02:41
'os.Stdout.Write([] byte(「Saving to PGDB \ n」))''可以更好地用作'fmt.Println(「Saving to PGDB」)'btw – 2013-05-12 02:16:45