I have several Python rules that output various messages to the log. I’ve configured pax.logging.cfg with a few custom log files that I’ve been using successfully with DSL rules and I’d like to do the same with my Python rules. One of the custom log files is configured like this:
You could also change jsr223.jython.heating to jsr223.jython.the_name_of_my_rule, so that you don’t have to log to a separate logger in your rule and just use the log attribute of the rule function.
It’s so obvious now that you’ve pointed it out! Thanks!
I have a few different rules for various heating functions so I find it useful to create several different custom log files and use them in several rules rather than use a logger per rule.
Try naming your rules like “heating.This heating rule” and “heating.That heating rule”. I think this should work for you, so that you can use the rule log attribute and not having to create separate loggers.
Sorry, I think I’m being a bit dense but I don’t quite follow you. Here’s one of my rules that I’ve just reconfigured to use logging.getLogger:
@rule("Boiler central heating set point weather compensation rule", description="This rule calculates the central heating set point based on the outdoor temperature", tags=["Example"])
@when("Item SensorHygrometerOutdoor_Temperature received update")
def dev_boiler_heating_set_point_rule(event):
minOutdoorTemp = -5
maxOutdoorTemp = 20
maxFlowTemp = 70
minFlowTemp = 25
calculatedSetpoint = 0
log = logging.getLogger("org.eclipse.smarthome.model.script.heating")
outdoorTempRange = maxOutdoorTemp - minOutdoorTemp
deltaFlowTemp = maxFlowTemp - minFlowTemp
outdoorTemp = round(float(str(event.itemState)))
# clamp the outdoor temperature values to upper and lower limits
if outdoorTemp < minOutdoorTemp:
outdoorTemp = minOutdoorTemp
if outdoorTemp > maxOutdoorTemp:
outdoorTemp = maxOutdoorTemp
calculatedSetpoint = ((outdoorTempRange - (outdoorTemp - minOutdoorTemp)) / outdoorTempRange ) * deltaFlowTemp + minFlowTemp + items["BoilerHeatingWeatherCompSetPointBoost"].floatValue()
calculatedSetpoint = round(calculatedSetpoint)
if calculatedSetpoint < minFlowTemp:
calculatedSetpoint = minFlowTemp
if calculatedSetpoint > maxFlowTemp:
calculatedSetpoint = maxFlowTemp
events.sendCommand(ir.getItem("BoilerHeatingWeatherCompSetPoint"), calculatedSetpoint)
# dev_boiler_heating_set_point_rule.log.info("Heating: Calculated set point is ({}), outdoor temp is ({}).".format( calculatedSetpoint, outdoorTemp ))
log.info("Heating: Calculated set point is ({}), outdoor temp is ({}).".format( calculatedSetpoint, outdoorTemp ))
Do you mean I’d change the rule name to look like this:
@rule("heating.Boiler central heating set point weather compensation rule", description="This rule calculates the central heating set point based on the outdoor temperature", tags=["Example"])
@when("Item SensorHygrometerOutdoor_Temperature received update")
def dev_boiler_heating_set_point_rule(event):
or:
@rule("Boiler central heating set point weather compensation rule", description="This rule calculates the central heating set point based on the outdoor temperature", tags=["Example"])
@when("Item SensorHygrometerOutdoor_Temperature received update")
def heating.dev_boiler_heating_set_point_rule(event):
and then use this sort of code to write to the log:
dev_boiler_heating_set_point_rule.log.info("Heating: Calculated set point is ({}), outdoor temp is ({}).".format( calculatedSetpoint, outdoorTemp ))
… you can then simply change the name of your rule to have it picked up by the logger…
@rule("heating.Boiler central heating set point weather compensation rule", description="This rule calculates the central heating set point based on the outdoor temperature", tags=["Example"])
@when("Item SensorHygrometerOutdoor_Temperature received update")
def dev_boiler_heating_set_point_rule(event):