I am tearing my hair out.
I need a syslog handler.
I found this: at a StackOverflow page and found the approach works just fine standalone, communicates as it should with this system's syslog.
However, I can't figure out how to refer to it in my logging config file. I am using Python 2.6.6 so dict config is not available to me. I have to use file configuration. According to docs the class name has to be either relative to logging or a full specification from the python path.
Here is the section of my config file:
[handler_syslog]
class=logext.HDSysLogHandler
level=WARN
formatter=timestamp
args=(7, )
logext is a package located one level deeper than my main.
It contains 3 python files and compiled files:
[logext]$ ls -al
total 32
drwxr-x---. 2 sc1478 dev 4096 Apr 25 11:50 .
drwxr-x---. 3 sc1478 dev 4096 Apr 25 11:50 ..
-rw-r-----. 1 sc1478 dev 243 Apr 25 11:50 HDSysLogHandler.py
-rw-r-----. 1 sc1478 dev 630 Apr 25 11:50 HDSysLogHandler.pyc
-rw-r-----. 1 sc1478 dev 2 Apr 25 11:50 __init__.py
-rw-r-----. 1 sc1478 dev 132 Apr 25 11:50 __init__.pyc
-rw-r-----. 1 sc1478 dev 2426 Apr 25 11:50 syslog_bridge.py
-rw-r-----. 1 sc1478 dev 2386 Apr 25 11:50 syslog_bridge.pyc
init.py is blank, just to make a package.
syslog.bridge.py is basically the file referred to above, with a small change to the constructor to make it more flexible and work with Python 2.6
class SysLogLibHandler(logging.Handler):
...
def __init__(self, identifier, n):
try:
syslog.openlog(identifier, syslog.LOG_PID, self.FACILITY[n])
except Exception , err:
print err
raise
# We got it
logging.Handler.__init__(self)
finally HDSysLogHandler.py is as follows:
from syslog_bridge import SysLogLibHandler
class HDSysLogHandler(SysLogLibHandler):
def __init__(self, local_facility):
SysLogLibHandler.__init__(self, "hdaudio", local_facility)
The relevant section of the main module is:
import logging
import logging.config
import logext
...
logging.config.fileConfig('logging.conf')
When my main app is run, I get this:
Traceback (most recent call last):
File "Main.py", line 23, in <module>
logging.config.fileConfig('logging.conf')
File "/usr/lib64/python2.6/logging/config.py", line 84, in fileConfig
handlers = _install_handlers(cp, formatters)
File "/usr/lib64/python2.6/logging/config.py", line 162, in _install_handlers
h = klass(*args)
TypeError: 'module' object is not callable
What is this trying to tell me? WHAT module is not callable? Who's trying to "call it"?
What is the RIGHT way to locate a home-brewed logging handler and specify it in a logging configuration file?