S
Sean DiZazzo
I'm finally getting around to trying out the python-daemon module and
have hit a wall. I'm trying to set up logging inside of the "with
daemon.DaemonContext" block. But when I try to use a logger inside
the block it throws an error:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
from __future__ import with_statement
import logging
import logging.handlers
import daemon
import daemon.pidlockfile
import sys
logger = logging.getLogger("DaemonLog")
logger.setLevel(logging.INFO)
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s
- %(message)s")
handler = logging.FileHandler("log.file")
logger.addHandler(handler)
pid = daemon.pidlockfile.TimeoutPIDLockFile("/var/run/daemontest.pid",
10)
with daemon.DaemonContext(pidfile=pid, gid=0, uid=0,
stdout=sys.stdout, stderr=sys.stderr):
logger.info("POO")
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I get the following traceback:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[seans_imac:~/Downloads] halfitalian% Traceback (most recent call
last):
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/logging/__init__.py", line 753, in emit
self.flush()
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/logging/__init__.py", line 731, in flush
self.stream.flush()
IOError: [Errno 9] Bad file descriptor
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/atexit.py", line 24, in _run_exitfuncs
func(*targs, **kargs)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/logging/__init__.py", line 1355, in shutdown
h.close()
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/logging/__init__.py", line 784, in close
self.stream.close()
IOError: [Errno 9] Bad file descriptor
Error in sys.exitfunc:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/atexit.py", line 24, in _run_exitfuncs
func(*targs, **kargs)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/logging/__init__.py", line 1355, in shutdown
h.close()
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/logging/__init__.py", line 784, in close
self.stream.close()
IOError: [Errno 9] Bad file descriptor
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Any advice? Also, I left in the call to TimeoutPIDLockfile() as well,
because the library's documentation is pretty sparse, and I want to
know if I'm using it properly.
Thanks in advance.
~Sean
have hit a wall. I'm trying to set up logging inside of the "with
daemon.DaemonContext" block. But when I try to use a logger inside
the block it throws an error:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
from __future__ import with_statement
import logging
import logging.handlers
import daemon
import daemon.pidlockfile
import sys
logger = logging.getLogger("DaemonLog")
logger.setLevel(logging.INFO)
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s
- %(message)s")
handler = logging.FileHandler("log.file")
logger.addHandler(handler)
pid = daemon.pidlockfile.TimeoutPIDLockFile("/var/run/daemontest.pid",
10)
with daemon.DaemonContext(pidfile=pid, gid=0, uid=0,
stdout=sys.stdout, stderr=sys.stderr):
logger.info("POO")
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I get the following traceback:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[seans_imac:~/Downloads] halfitalian% Traceback (most recent call
last):
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/logging/__init__.py", line 753, in emit
self.flush()
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/logging/__init__.py", line 731, in flush
self.stream.flush()
IOError: [Errno 9] Bad file descriptor
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/atexit.py", line 24, in _run_exitfuncs
func(*targs, **kargs)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/logging/__init__.py", line 1355, in shutdown
h.close()
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/logging/__init__.py", line 784, in close
self.stream.close()
IOError: [Errno 9] Bad file descriptor
Error in sys.exitfunc:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/atexit.py", line 24, in _run_exitfuncs
func(*targs, **kargs)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/logging/__init__.py", line 1355, in shutdown
h.close()
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/logging/__init__.py", line 784, in close
self.stream.close()
IOError: [Errno 9] Bad file descriptor
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Any advice? Also, I left in the call to TimeoutPIDLockfile() as well,
because the library's documentation is pretty sparse, and I want to
know if I'm using it properly.
Thanks in advance.
~Sean