2017-01-03 43 views
2

我有一個小型代碼寫入一個小的代碼發送消息到系統日誌使用C Api's,當無法連接到postgres數據庫。如何避免來自系統日誌廣播消息打印在控制檯上

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數據庫裏的信息被打印輸出上,即使選項LOG_CONS不openlog啓用控制檯。

Broadcast message from [email protected] (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 [email protected] 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? 

請問我可以幫助我如何避免在控制檯上打印的信息。

+2

相關:。http://serverfault.com/a/392333/143982 – alk

+0

那麼,竟敢顯示你的syslog-daemon的配置? – alk

回答

2

@alk提供的提示後,我做了一些更多的研究,並找到了如何避免在控制檯上打印的消息。

Broadcast message from [email protected] (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 [email protected] 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? 

上述消息具有兩個部分:

  1. 從systemd-journald =廣播消息>這些消息將通過journalctl在控制檯上被打印時的緊急消息發送。要禁用我們需要禁用ForwardToWall即這些消息。,ForwardToWall =在沒有 /etc/systemd/journald.conf

  2. 消息從syslogd的=>這些消息由rsyslog現在打印,因爲下面的配置線的在/etc/rsyslog.conf

.emerg:omusrmsg:

這種選擇行動往往規定「緊急消息去當前在線的所有用戶通知他們系統發生了一些奇怪的事情。要指定該壁(1)-FEATURE使用一個「:omusrmsg:*」「出評論此線

執行上述操作中的消息沒有打印在控制檯上後作爲這些操作是不允許因。安全威脅,我提出的事件與警報優先

syslog (LOG_ALERT, "%s", PQerrorMessage(psql)); 

由於@alk

+0

歡迎你。你會接受你自己的(好的)回答你自己的問題。 – alk

相關問題