Printing to HABapp logs?

Hello all,

I’m using HABApp version 0.31.2 in my Habian installation. As I run into some issues I’d like some way of debugging my code.

From the documentation I gathered that this can be done through using a default logger or plain and simple print-statements from the code. My problem is that my rules are working (e.g. a switched is turned off in a rule), yet not a single line will be printed.

I’ve tried a number of things, such as:

  • Debug using print statements
  • Debug using log.* - statements
  • Upping the log level to DEBUG
  • Adding custom loggers / handlers

All to no avail. Am I missing something here? Any help is greatly appreciated!

You have to create the loggers you are using in the logging.yml file next to the HABApp config.
See the example in the docs and the comments there.

If that doesn’t work please provide a code snipped to reproduce the issue and the ```logging.yml``

Thanks for the prompt reply.

I’ve created this handler:

  AutoPresence:
    class: HABApp.core.lib.handler.MidnightRotatingFileHandler
    filename: '/var/log/openhab/habapp_autopresence.log'
    maxBytes: 1_048_567
    backupCount: 3
    formatter: HABApp_format
    level: DEBUG

And here is my rule:

import HABApp
import logging
import geopy.distance
from HABApp.core.items import *
from HABApp.core.events import ValueUpdateEvent, ValueChangeEvent

log = logging.getLogger('AutoPresence')

class AutoPresenceRule(HABApp.Rule):

    def __init__(self):
        super().__init__()

        self.switch_RobinIsHome = HABApp.openhab.items.switch_item.SwitchItem.get_item('RobinHome')
        self.location_RobinsPhone = HABApp.openhab.items.LocationItem.get_item('RobinsiPhone_Location')

        self.listen_event(self.location_RobinsPhone, self.robinMoved, ValueUpdateEvent)
        self.listen_event(self.location_RobinsPhone, self.robinMoved, ValueChangeEvent)

    def robinMoved(self, event):
        currLocation = self.location_RobinsPhone.get_value()
        refrLocation = (50, 6)
        distance = geopy.distance.distance(currLocation, refrLocation).m
        print (f"You're phone is {distance} meters from home!")

        log.debug('Debug Message test')
        log.info('Info Message test')
        log.warning('Warning Message test')
        log.error('Error Message test')

        if (distance > 100):
            self.switch_RobinIsHome.off()

AutoPresenceRule()

So there’s a number of lines that should print something. The habapp_autopresence.log-file is created on starting habapp, but it stays empty forever. Both the application log and the event log are appended with new info, just not the info I’m expecting…

The handler defines the available files, you also have to add a logger in the logging.yml.
In your case the logger name would be AutoPresence.
Please check the documentation how to create the logger.

Thanks, I’ve added this to my loggers and now it’s working:

  AutoPresence:
    level: DEBUG
    handlers:
      - AutoPresence
    propagate: False

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.