0

got this in my rsysconf:

    $template TemplateLog,"%msg%\n"   
    $template DynamicLog,"%msg%\n"                                                                                                                            
    $template DynamicFile,"/var/log/%PROGRAMNAME%.log"    
    if ($programname == "test") then {local3.=debug    -/var/log/path.log;TemplateLog}                                                                  
    local3.=debug    -?DynamicFile;DynamicLog                                                                                                                 
    & stop   

If I put away the if statement, it works well. But I need to make the if statement working. What is wrong about it? Thank you for advice.

I tried to change the == to contains as suggested in one of answers, this does not help.

Is $programname containing same info as %PROGRAMNAME% ? This could cause the problem, maybe...

So acording to answer, I have made this:

$template TemplateLog,"%msg%\n"   
$template DynamicLog,"%msg%\n"                                                                                                                            
$template DynamicFile,"/var/log/%PROGRAMNAME%.log"           
template(name="pname" type="string" string="%PROGRAMNAME%")                                                                                               
set $!xyz = exec_template("pname");     
if ($!xyz contains'test') then {local3.=debug    -/var/log/path.log;TemplateLog}
local3.=debug    -?DynamicFile;DynamicLog                                                                                                                 
& stop   

But unfortunately, this code is not working either. If I delete the if statement, the second DynamicFile is saved into test.log, so the value is correct.

ragulin
  • 101
  • 2

1 Answers1

0

You can always print the variable to see the output. I think is something related to syntax, please try using contains instead of ==.

You can assign it to a var using templates:

    $template DynamicLog,"%msg%\n"                                                                                                                            
    $template DynamicFile,"/var/log/%PROGRAMNAME%.log"    
    template(name="pname" type="string" string="%PROGRAMNAME%")
    set $!xyz = exec_template("pname");
    if ($!xyz contains 'test') then {local3.=debug    -/var/log/path.log;TemplateLog}                                                                 
    local3.=debug    -?DynamicFile;DynamicLog                                                                                                                 
    & stop```