Search code examples
pythonloggingsyslog

TypeError: openlog() takes no keyword arguments


I am trying to write to syslog in one of my scripts. Here is the code for logger.py:

from __future__ import print_function
import os
import sys
import syslog
import urllib
import datetime

def log(msg, level="info"):
    msg = safe(msg)
    if os.environ.get('debug'):
        debugmsg = "{0} {1}".format(datetime.datetime.now(), msg)
        print(debugmsg, file=sys.stderr)
    syslog.openlog(ident=__file__,logoption=syslog.LOG_PID,facility=syslog.LOG_LOCAL0)
    syslog.syslog(level, msg)

def safe(str):
    return urllib.unquote_plus(str)

When I go to test the log function via logger.log("Hello world!"), the interpreter throws TypeError: openlog() takes no keyword arguments.

Any insight?


Solution

  • This could be a problem with an older version of python. See this and that