mueslo / openwrt_hass_devicetracker

Simple OpenWRT package which forwards device connection changes to a HomeAssistant instance
GNU General Public License v3.0
92 stars 31 forks source link

Could logging loglevel be configurable? #9

Open zxdavb opened 6 years ago

zxdavb commented 6 years ago

There is a lot of DEBUG log message via logger -p debug... It woudl be great if this was configurable via (say):

uci set hass.global.loglevel=6

...where 6 is equal to INFO, etc. as per the 'standard' logger priorities.

I am unable to submit a PR at the moment (house renovations), but this chunk of code may be a start:

function log_msg {
    local _LEVEL _LEVEL_TEXT=$1
    shift   # remove loglevel param

    config_get hass_loglevel global loglevel 5  # default is NOTICE

    [ "$_LEVEL_TEXT" == "error" ]   && _LEVEL=3
    [ "$_LEVEL_TEXT" == "warning" ] && _LEVEL=4
    [ "$_LEVEL_TEXT" == "notice" ]  && _LEVEL=5
    [ "$_LEVEL_TEXT" == "info" ]    && _LEVEL=6
    [ "$_LEVEL_TEXT" == "debug" ]   && _LEVEL=7

    if [ $_LEVEL -le $hass_loglevel ]; then
        logger -p $_LEVEL -t $0 $@
    fi
}

Then, through the code, you could have, for example:

log_msg error "register_hook() missing interface"