当连接到PostgreSQL数据库失败时,我编写了一小段代码,使用C API向syslog发送消息。
int main ( int argc, char **argv )
{
PGconn *psql;
PGresult *res;
int flag = 0;
openlog ( "postgres", LOG_NDELAY, LOG_SYSLOG );
psql = PQconnectdb("hostaddr = '127.0.0.0' port = '5432' dbname = 'RtpDb' user = 'rtp_user_99' password = 'rtp_user' connect_timeout = '10'");
if ( PQstatus(psql) != CONNECTION_OK )
{
//Send an event to syslog for DB Connection Failure
syslog (LOG_EMERG, "%s", PQerrorMessage(psql) )
}
closelog ();
PQclear(res);
PQfinish(psql);
}
当连接到postgres数据库失败时,即使在openlog中未启用LOG_CONS选项,消息仍会打印到控制台上。
Broadcast message from systemd-journald@blr09 (Tue 2017-01-03 05:24:46 EST):
postgres[40933]: could not connect to server: Network is unreachable
Is the server running on host "127.0.0.0" and accepting
TCP/IP connections on port 5432?
Message from syslogd@blr09 at Jan 3 05:24:46 ...
postgres:could not connect to server: Network is unreachable#012#011Is the server running on host "127.0.0.0" and accepting#012#011TCP/IP connections on port 5432?
请问如何避免信息在控制台上打印?