3

私はこのrsyslog構成を持っています:

    $template f_x,"/path/%programname%.%$YEAR%%$MONTH%%$DAY%%$HOUR%.log"

    if $programname == 'xyz' and $msg contains 'Hello World' or $msg contains 'FATAL'         
    then $msg = 'Starting xyz' ?f_x
    & ~

この構成で receive $msg プロパティを 'Hello World' から $msg = 'BlaBlaBla' に変更し、ファイル (%programname%.%$YEAR%%$MONTH%%$DAY%%$HOUR%. log) 最後の $msg 値

前もって感謝します

4

1 に答える 1

4

msgプロパティをオーバーライドすることはできません。

rsyslog 7 以降では、カスタム テンプレートで CEE/lumberjack プロパティを使用することで、このトリックを実行できます。次に例を示します。

# Notice the use of $!msg in template string
template(name="logline" type="string"
         string="%TIMESTAMP:::date-rfc3339% %HOSTNAME% %syslogtag%%$!msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\n")

# If the message matches your conditions, set $!msg to your custom string
if ($programname == 'xyz' and $msg contains 'Hello World' or $msg contains 'FATAL') then set $!msg = "Starting xyz";
# Otherwise, use the msg property value
else set $!msg = $msg;

# Finally, use the custom template
action(type="omfile" file="/tmp/logfile" template="logline")

rsyslog の CEE/lumberjack プロパティの詳細については、http://www.rsyslog.com/how-to-set-variables-in-rsyslog-v7/ を参照してください

于 2013-03-15T20:09:08.070 に答える