
\n
文字を含む文字列を書く\t
ことができるかどうかを知っている人はいますかsyslog
?
Cプログラムを使用しておよびを\n
含む文字列変数を作成しようとしました\t
。それからcat
ファイルを試しましたが、syslog
結果は私が望むものとは異なりました。システムログでは、これらの文字はと#012
で置き換えられます#011
。正規表現を使ってファイルを楽しい方法で読み取るいくつかのスクリプトを見つけましたが、それは私にとって必要なものではありません。私にとって必要なのは、システムログに指定されたIDを持つ文字列を作成することです。
私がしたいことの例は次のとおりです。
#include <syslog.h>
#include <stdio.h>
int main()
{
char *myMessage = "This is the first line\n This is the second line\n \tThis is the third line\n";
syslog(LOG_ERR, "My message is: %s", myMessage);
return 0;
}
これは私がcat
後で得たものですsyslog
:
test: My message is: This is the first line#012 This is the second line#012 #011This is the third line
これが私がcat
得たいものですsyslog
:
test: My message is: This is the first line
This is the second line
This is the third line
答え1
Syslog メッセージは暗黙的です。一行。複数行が必要な場合は、複数のsyslogメッセージを送信するか、メッセージを短くします。 syslog形式(日付と時刻の形式など)は設定可能なため、送信者のインデントを正しく設定できません。