2011-12-13 7 views
6
#include<syslog.h> 
syslog(LOG_INFO, "Start logging"); 

上記のsyslogコマンドは、syslogにログインしていません。Cコード内のsyslogコマンド

syslog: unknown facility/priority: 8049584 
+1

を参照してください。http://www.linuxselfhelp.com/gnu/glibc/html_chapter/libc_18.html –

答えて

7

あなたは本当にすべて有効に警告やデバッグ、すなわちgcc -Wall -gでコンパイルする必要があります。だから私は、これは何をログに失敗し、私は次のエラーを取得する、

openlog("Logs", "", LOG_USER); 
syslog(LOG_INFO, "Start logging"); 
closelog(); 

を試してみました。

openlog man pageを再度読みます。その2番目の引数が間違っているよう""を渡す(およびコンパイラがそのことについて警告しました)

void openlog(const char *ident, int option, int facility); 

:それは次のように宣言されています。例えば、 LOG_PERROR|LOG_PIDまたはその他のフラグ。

14

この行が間違っている:

openlog("vyatta-conntrack", "", LOG_USER); 

"" 整数されている必要があります:

void openlog(const char *ident, int option, int facility); 

整数が一緒にOR演算これらの定数のいずれかでなければなりません:

LOG_CONS  Write directly to system console if there is 
        an error while sending to system logger. 

    LOG_NDELAY  Open the connection immediately (normally, the 
        connection is opened when the first message is 
        logged). 

    LOG_NOWAIT  Don't wait for child processes that may have 
        been created while logging the message. (The 
        GNU C library does not create a child process, 
        so this option has no effect on Linux.) 

    LOG_ODELAY  The converse of LOG_NDELAY; opening of the 
        connection is delayed until syslog() is 
        called. (This is the default, and need not be 
        specified.) 

    LOG_PERROR  (Not in POSIX.1-2001.) Print to stderr as 
        well. 

    LOG_PID  Include PID with each message. 

次のようにもう一度お試しください:

openlog("vyatta-conntrack", LOG_PID, LOG_USER); 

syslogdの設定でログレベルがLOG_INFOのメッセージが保持されないことがあります。この問題をデバッグするためにLOG_ALERTなどを試してください。正常に機能している場合は、LOG_INFOに戻り、保存するログメッセージを保存するようにsyslogdを設定してください。

*.* /var/log/all_messages.log 

のような行を追加すると、​​のジョブが実行されます。システムで​​を使用している場合は、rsyslog.conf(5)のマンページを必ずお読みください。システムで異なるsyslogデーモンが使用されている場合は、システムのマンページで詳細を確認してください。