这可能吗?据我所知,将选项添加到python类的唯一方法是在python目标的选项中对它们进行硬编码。我需要基于$ HOST之类的宏设置变量路径,但是python目标选项似乎没有被插值。我需要一种将$ HOST之类的宏值传递给init()方法的方法。
答案 0 :(得分:1)
每条消息的$ HOST值都会变化,因此实际上您需要在send()
中而不是在init()
中使用它。您可能真正想要的是这样的东西:
class MyDestination(object):
# ...
def send(self, msg):
host = msg["HOST"]
# ...
return True
或者您可以使用从v3.18开始的模板:
import syslogng
class MyDestination(object):
def init(self, options):
self.log_template = syslogng.LogTemplate("$HOST")
# ...
return True
def send(self, msg):
formatted_string = self.log_template.format(msg, self.template_options)
# ...
return True