dovecot-2.0: mysql/pgsql: Log prefixes now contain also the host...
dovecot at dovecot.org
dovecot at dovecot.org
Wed Mar 2 14:58:01 EET 2011
details: http://hg.dovecot.org/dovecot-2.0/rev/965b9019ef2e
changeset: 12630:965b9019ef2e
user: Timo Sirainen <tss at iki.fi>
date: Wed Mar 02 14:57:58 2011 +0200
description:
mysql/pgsql: Log prefixes now contain also the hostname.
This is useful when there are multiple hosts in use.
diffstat:
src/lib-sql/driver-mysql.c | 18 +++++++++++-------
src/lib-sql/driver-pgsql.c | 33 ++++++++++++++++++++-------------
2 files changed, 31 insertions(+), 20 deletions(-)
diffs (141 lines):
diff -r b6f8d4bee20d -r 965b9019ef2e src/lib-sql/driver-mysql.c
--- a/src/lib-sql/driver-mysql.c Mon Feb 28 19:52:10 2011 +0200
+++ b/src/lib-sql/driver-mysql.c Wed Mar 02 14:57:58 2011 +0200
@@ -52,6 +52,11 @@
extern const struct sql_result driver_mysql_result;
extern const struct sql_result driver_mysql_error_result;
+static const char *mysql_prefix(struct mysql_db *db)
+{
+ return t_strdup_printf("mysql(%s)", db->host);
+}
+
static int driver_mysql_connect(struct sql_db *_db)
{
struct mysql_db *db = (struct mysql_db *)_db;
@@ -105,15 +110,14 @@
alarm(0);
if (failed) {
sql_db_set_state(&db->api, SQL_DB_STATE_DISCONNECTED);
- i_error("mysql: Connect failed to %s (%s): %s - "
+ i_error("%s: Connect failed to database (%s): %s - "
"waiting for %u seconds before retry",
- host != NULL ? host : unix_socket, db->dbname,
+ mysql_prefix(db), db->dbname,
mysql_error(db->mysql), db->api.connect_delay);
return -1;
} else {
- i_info("mysql: Connected to %s%s (%s)",
- host != NULL ? host : unix_socket,
- db->ssl_set ? " using SSL" : "", db->dbname);
+ i_info("%s: Connected to database %s%s", mysql_prefix(db),
+ db->dbname, db->ssl_set ? " using SSL" : "");
sql_db_set_state(&db->api, SQL_DB_STATE_IDLE);
return 1;
@@ -266,8 +270,8 @@
struct mysql_db *db = (struct mysql_db *)_db;
if (driver_mysql_do_query(db, query) < 0) {
- i_error("mysql: Query '%s' failed: %s",
- query, mysql_error(db->mysql));
+ i_error("%s: Query '%s' failed: %s",
+ mysql_prefix(db), query, mysql_error(db->mysql));
}
}
diff -r b6f8d4bee20d -r 965b9019ef2e src/lib-sql/driver-pgsql.c
--- a/src/lib-sql/driver-pgsql.c Mon Feb 28 19:52:10 2011 +0200
+++ b/src/lib-sql/driver-pgsql.c Wed Mar 02 14:57:58 2011 +0200
@@ -73,6 +73,11 @@
static void result_finish(struct pgsql_result *result);
+static const char *pgsql_prefix(struct pgsql_db *db)
+{
+ return t_strdup_printf("pgsql(%s)", db->host);
+}
+
static void driver_pgsql_set_state(struct pgsql_db *db, enum sql_db_state state)
{
i_assert(state == SQL_DB_STATE_BUSY || db->cur_result == NULL);
@@ -150,8 +155,8 @@
case PGRES_POLLING_OK:
break;
case PGRES_POLLING_FAILED:
- i_error("pgsql: Connect failed to %s: %s",
- PQdb(db->pg), last_error(db));
+ i_error("%s: Connect failed to database %s: %s",
+ pgsql_prefix(db), PQdb(db->pg), last_error(db));
driver_pgsql_close(db);
return;
}
@@ -162,7 +167,8 @@
}
if (io_dir == 0) {
- i_info("pgsql: Connected to %s", PQdb(db->pg));
+ i_info("%s: Connected to database %s",
+ pgsql_prefix(db), PQdb(db->pg));
if (db->to_connect != NULL)
timeout_remove(&db->to_connect);
driver_pgsql_set_state(db, SQL_DB_STATE_IDLE);
@@ -176,11 +182,10 @@
static void driver_pgsql_connect_timeout(struct pgsql_db *db)
{
- const char *dbname = PQdb(db->pg);
unsigned int secs = ioloop_time - db->api.last_connect_try;
- i_error("pgsql: Connect failed to %s: Timeout after %u seconds",
- dbname != NULL ? dbname : db->host, secs);
+ i_error("%s: Connect failed: Timeout after %u seconds",
+ pgsql_prefix(db), secs);
driver_pgsql_close(db);
}
@@ -191,19 +196,21 @@
i_assert(db->api.state == SQL_DB_STATE_DISCONNECTED);
db->pg = PQconnectStart(db->connect_string);
- if (db->pg == NULL)
- i_fatal("pgsql: PQconnectStart() failed (out of memory)");
+ if (db->pg == NULL) {
+ i_fatal("%s: PQconnectStart() failed (out of memory)",
+ pgsql_prefix(db));
+ }
if (PQstatus(db->pg) == CONNECTION_BAD) {
- i_error("pgsql: Connect failed to %s: %s",
- PQdb(db->pg), last_error(db));
+ i_error("%s: Connect failed to database %s: %s",
+ pgsql_prefix(db), PQdb(db->pg), last_error(db));
driver_pgsql_close(db);
return -1;
}
/* nonblocking connecting begins. */
if (PQsetnonblocking(db->pg, 1) < 0)
- i_error("pgsql: PQsetnonblocking() failed");
+ i_error("%s: PQsetnonblocking() failed", pgsql_prefix(db));
i_assert(db->to_connect == NULL);
db->to_connect = timeout_add(SQL_CONNECT_TIMEOUT_SECS * 1000,
driver_pgsql_connect_timeout, db);
@@ -428,7 +435,7 @@
driver_pgsql_stop_io(db);
- i_error("pgsql: Query timed out, aborting");
+ i_error("%s: Query timed out, aborting", pgsql_prefix(db));
result->timeout = TRUE;
result_finish(result);
}
@@ -494,7 +501,7 @@
{
struct pgsql_db *db = (struct pgsql_db *)_result->db;
- i_error("pgsql: sql_exec() failed: %s", last_error(db));
+ i_error("%s: sql_exec() failed: %s", pgsql_prefix(db), last_error(db));
}
static void driver_pgsql_exec(struct sql_db *db, const char *query)
More information about the dovecot-cvs
mailing list