Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adopt Weewx 4x new logging function - Enhancement #8

Open
HoracioDos opened this issue Dec 16, 2020 · 0 comments
Open

Adopt Weewx 4x new logging function - Enhancement #8

HoracioDos opened this issue Dec 16, 2020 · 0 comments
Labels
enhancement New feature or request

Comments

@HoracioDos
Copy link

Hello.
Logger function changed since Weewx 4.x,. You can make it backwards compatible and adopt the new one by changing from line 38 to 48

def logmsg(dst, msg):
    syslog.syslog(dst, 'zabbix: %s' % msg)

def logdbg(msg):
    logmsg(syslog.LOG_DEBUG, msg)

def loginf(msg):
    logmsg(syslog.LOG_INFO, msg)

def logerr(msg):
    logmsg(syslog.LOG_ERR, msg)

with this

# Test for new-style weewx v4 logging by trying to import weeutil.logger
import weeutil.logger
import logging

try:
    log = logging.getLogger(__name__)

    def logdbg(msg):
        log.debug(msg)

    def loginf(msg):
        log.info(msg)

    def logerr(msg):
        log.error(msg)

except ImportError:
    # Old-style weewx logging
    import syslog

    def logmsg(level, msg):
        syslog.syslog(level, 'Zabbix Extension: %s' % msg)

    def logdbg(msg):
        logmsg(syslog.LOG_DEBUG, msg)

    def loginf(msg):
        logmsg(syslog.LOG_INFO, msg)

    def logerr(msg):
        logmsg(syslog.LOG_ERR, msg)

Thanks

@RandomReaper RandomReaper added the enhancement New feature or request label Dec 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants