Hi I according to your code on pastie, the logger is defined outside of the function set (think of it as a variable) therefore for you to use it within a function you have to pass it to the function i.e. the function your definition should be like this
def set(module, device, state, logger, attributes=None):
""" Set the state of the specified device"""
try:
acquire_lock(device)
except:
#state object doesn't exist yet
pass
try:
state_object = StateTable.select().where(StateTable.device == device).get()
except:
state_object = StateTable()
state_object.device = device
state_object.state = state
state_object.attributes = attributes
state_object.lastChange = datetime.datetime.now()
state_object.save()
logger.debug("Setting state for", device, "with state", state, "and attributes", attributes)
release_lock(device)
logger.debug("SETTING MQTT STATE")
attributes_mqtt = {"device" : device, "module" : module, "state" : state, "attributes" : json.loads(attributes)}
logger.debug("MQTT:", attributes_mqtt)
mqttc.publish("state", json.dumps(attributes_mqtt))
then when you call the set function pass the logger as a parameter.